DEV Community

abhishekjaindba
abhishekjaindba

Posted on

Take MySQL Database Backup From Jenkins

In this post, we will explain and practically show how you can configure MySQL database backup using Jenkins jobs. in easy words, you will automate the MySQL database backup process from Jenkins GUI.

  1. Log to Jenkins default URL and port: http://192.168.56.21:8080/

If you want to install and setup Jenkins see this article

  1. Go to New items

  2. Give some Name and select FreeStyle project

  3. In the build section click on Add build step radio button and select Execute shell.

  4. Select boolean parameter for MySQL database host and database superuser password which is root password in MySQL database case.

  5. In this build part give the shell script name with full path and parameters like $HOST_IP & $Password

Shell Script

[root@master01 ~]# cat /opt/jenkins_scripts/mysql_full_db_backup.sh

!/bin/bash

HOST_IP=$1

PASSWORD=$2

echo "starting mysql database full backup"

mysqldump -h $HOST_IP --all-databases --single-transaction --quick --lock-tables=false > /opt/jenkins_scripts/mysql_backup/full_backup_$(date +%F_%N).sql -u root -p$PASSWORD

echo "Backup has been done"

https://thedbadmin.com/take-mysql-backup-from-jenkins-job

Oldest comments (0)