I was asked today how to perform an application consistent backup of MySQL in a Linux Virtual Machine on VMware for a customer evaluating Veeam Backup.
On Windows, Veeam can do application consistent backups through the Veeam Microsoft Volume Shadow Copy Services (VSS) integration for VSS aware applications. Unfortunately Linux does not have a system like Microsoft Volume Shadow Copy Services (VSS) that allows applications to be made application consistent by backup applications like VMware vDR or Veeam Backup.
A simple workaround is to leverage VMware tools ability to call custom freeze/thaw scripts during a quiesced snapshot to enable customers to do the required application quiescence.
The example below is for MySQL, for other applications you need to know the application specific command to quiesce the application and modify the scripts below appropriately.
Step 1. Make sure VMware Tools are installed in the Linux VM
VMware Tools MUST be installed and should be up to date in your Linux Virtual Machine.
Step 2. Determine how to quiesce the application
To quiesce MySQL we will do a mysqldump to create a transactionally consistent backup of mysql without downtime.
Note the disadvantage of this method is that it takes more space since it creates a copy of the database. Alternatively, If you can stop/start mysql during an off hour backup that is a simple way to quiesce ( no transactions can occur if the database is stopped ) as well. You would stop mysql in the pre-freeze, and start mysql in the post-thaw in that case.
Step 3. Create /usr/sbin/pre-freeze-script
Below are the commands to type at the Linux command shell to create the pre-freeze script which will create a transactionally consistent backup of MYSQL and store the resulting statements in /var/mysqlbackup.todaysdate.sql
The resulting .sql file produced by mysqldump contains a set of SQL INSERT statements that can be used to reload the dumped tables at a later time
cat <<EOF > /usr/sbin/pre-freeze-script
mysqldump --single-transaction --all-databases > /var/mysqlbackup.\`date +"%m%d%y"\`.sql
Check the above command worked properly by examining the created script.
The result of the cat command above should look like below
mysqldump --single-transaction --all-databases > /var/mysqlbackup.`date +"%m%d%y"`.sql
Make the script executable
chmod 755 /usr/sbin/pre-freeze-script
Step 4. Create the /usr/sbin/post-thaw-script
In this case we don’t have to call anything in the post-thaw so create an empty script :
chmod 755 /usr/sbin/post-thaw-script
Step 5. Enable VMware Tools Quiescence
Now check “Use VMware Tools Quiescence” in Veeam Backup, and Veeam will ask VMware tools to quiesce the VM, and VMware Tools will call /usr/sbin/pre-freeze-script and /usr/sbin/post-thaw-script to create the application consistent snapshot.
After the Veeam backup, login to the VM and validate the backup file with the date of the backup exists:
root@vCentos ~# ls -la /var/mysqlbackup.032411.sql
-rw-r--r-- 1 root root 422120 Mar 24 11:59 /var/mysqlbackup.032411.sql
You can customize the above procedure for any Linux application that provides a method to quiesce itself.