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:

You can specify the scripts to run on the MySQL Database nodes in Pre/Post Scripts Settings of the Backup Wizard.

Follow these steps:

  1. Log into the Backup Server as a root user.
  2. 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.

  1. 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.*

  1. Provide the execution permission to both the scripts.
  2. Place both the scripts in the following location:

    /opt/Arcserve/d2dserver/usr/prepost/

  1. Log into the Arcserve UDP Agent (Linux) web interface.
  2. Open the Backup Wizard and navigate to the Advanced tab.
  3. In the Pre/Post Scripts Settings option, select the pre-db-backup-mode.sh script file from the "Before snapshot is taken" dropdown list.
  4. In the Pre/Post Scripts Settings option, select the post-db-backup-mode.sh script file from the "After snapshot is taken" dropdown list.
  5. Submit the backup job.

    The backup job is submitted.

The scripts are created to back up MySQL Database.

Note: Arcserve UDP Agent (Linux) supports the volume level snapshot. To ensure the data consistency, all data files of the database must be on one volume.