Create the Scripts to Back Up MySQL Database
You can create scripts that you use to back up MySQL Database. You do not have to stop your database to perform a backup. You create the following two scripts to back up MySQL Database:
- pre-db-backup-mode.sh - This script closes all open tables, and it locks all the tables for all the databases with a global read lock.
- post-db-backup-mode.sh - This script releases all the locks.
You can specify the scripts to run on the MySQL Database nodes in Pre/Post Scripts Settings of the Backup Wizard.
Follow these steps:
- Log into the Backup Server as a root user.
- Create the pre-db-backup-mode.sh script using to the following code:
#!/bin/bash#
dbuser=root
dbpwd=rootpwd
lock_mysqldb(){
(
echo "flush tables with read lock;"
sleep 5
) | mysql -u$dbuser -p$dbpwd ${ARGUMENTS} }
}
lock_mysqldb &
PID="/tmp/mysql-plock.$!"
touch ${PID}
Note: Specify the value for dbuser and dbpwd variables as defined in your MySQL Database.
- Create the post-db-backup-mode.sh script using the following code:
#!/bin/bash
killcids(){
pid="$1"
cids=`ps -ef|grep ${pid}|awk '{if('$pid'==$3){print $2}}'`
for cid in ${cids}
do
echo ${cid}
kill -TERM ${cid}
done
echo -e "\n"
}
mysql_lock_pid=`ls /tmp/mysql-plock.* | awk -F . '{print $2}'`
[ "$mysql_lock_pid" != "" ] && killcids ${mysql_lock_pid}
rm -fr /tmp/mysql-plock.*
- Provide the execution permission to both the scripts.
- Place both the scripts in the following location:
/opt/Arcserve/d2dserver/usr/prepost/
- Log into the Arcserve Unified Data Protection Agent for Linux web interface.
- Open the Backup Wizard and navigate to the Advanced tab.
- In the Pre/Post Scripts Settings option, select the pre-db-backup-mode.sh script file from the "Before snapshot is taken" dropdown list.
- In the Pre/Post Scripts Settings option, select the post-db-backup-mode.sh script file from the "After snapshot is taken" dropdown list.
- Submit the backup job.
The backup job is submitted.
The scripts are created to back up MySQL Database.
Note: Arcserve Unified Data Protection Agent for Linux supports the volume level snapshot. To ensure the data consistency, all data files of the database must be on one volume.
This section contains the following topics: