Skip to main content
How to back up MySQL database on VMware

Instructions to back up MySQL database on VMware

Updated over a week ago

This document guides you on how to back up a MySQL clustered and standalone databases hosted on VMware using the Enterprise Workloads data protection solution. You can leverage VMware Tools utility to run custom pre-post backup scripts, ensuring database consistent snapshots.

📝 Note

Ensure VMware Tools are installed on the MySQL Server VM.


  1. Create the backupScripts.d folder under the /etc/vmware-tools on the MySQL Server VM. For more information, refer to the VMware KB article.

    1. SSH into the MySQL Server VM as a non-root sudo user.

    2. Run the following command:

      sudo mkdir /etc/vmware-tools/backupScripts.d​

  2. Create pre and post script files in the /etc/vmware-tools/backupScripts.d folder and you must name them starting with a number to ensure sequential execution of IO freeze and IO thaw tasks by VMware tools, where lower number has higher priority during script execution. In our example, the script will be executed prior to the script.

    1. Pre-backup script:

    2. Post-backup script:

  3. Ensure scripts are executable with appropriate privileges.

    1. SSH into the MySQL Server VM.

    2. Run the following commands:

      sudo chmod +x /etc/vmware-tools/backupScripts.d/
      sudo chmod +x /etc/vmware-tools/backupScripts.d/
      sudo chown root:root /etc/vmware-tools/backupScripts.d/
      sudo chown root:root /etc/vmware-tools/backupScripts.d/​

  4. Deploy a backup proxy to back up your VM.

    1. Download the VMware Proxy Deployer on your local system and deploy the backup proxy using steps listed in Deploy VMware proxy using VMware Proxy Deployer.

    2. Configure VM for backup by creating a backup policy on the Enterprise Workloads Management Console.

    3. Enable Changed Block Tracking (CBT) and VMware tools quiescing in the backup policy configuration.

  5. Perform a manual VM backup on the Enterprise Workloads Management Console for a quick validation.

Sample Pre-script:



rm -f $lock_file
echo "FLUSH TABLES WITH READ LOCK" | logger -t $(basename $0)
mysql -uroot -p'my_password' -e "FLUSH TABLES WITH READ LOCK; system touch $lock_file; system nohup sleep $sleep_time; system echo \"Lock released\"|logger -t $(basename $0); " > /dev/null &

echo "child pid $mysql_freeze_pid" | logger -t $(basename $0)

while [ ! -f $lock_file ]
if ! ps -p $mysql_freeze_pid 1>/dev/null ; then
echo "Mysql command has failed (bad credentials?)" | logger -t $(basename $0)
exit 1
sleep 1
if [ $c -gt $timeout ]; then
echo "Timed out waiting for lock" | logger -t $(basename $0)
touch $lock_file
kill $mysql_freeze_pid
echo $mysql_freeze_pid > $lock_file
exit 0

Sample Post-script:


mysql_freeze_pid=$(cat $lock_file)

echo "Sending sigterm to $mysql_freeze_pid" | logger -t $(basename $0)
pkill -9 -P $mysql_freeze_pid
rm -f $lock_file

exit 0
Did this answer your question?