Previous Topic: Create the Scripts to Back Up Oracle DatabaseNext Topic: Customize the Job Schedule


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.

  3. 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.*
    
  4. Provide the execution permission to both the scripts.
  5. Place both the scripts in the following location:
    /opt/CA/d2dserver/usr/prepost/
    
  6. Log into the Arcserve UDP Agent (Linux) web interface.
  7. Open the Backup Wizard and navigate to the Advanced tab.
  8. In the Pre/Post Scripts Settings option, select the pre-db-backup-mode.sh script file from the "Before snapshot is taken" dropdown list.
  9. In the Pre/Post Scripts Settings option, select the post-db-backup-mode.sh script file from the "After snapshot is taken" dropdown list.
  10. 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.