Guides

Acronis Backup: backing up MySQL database

How to backup all MySQL database dump

In order to use Acronis Backup to back up all the MySQL databases on a server, it is necessary to make a script that creates and saves a dump file (SQL export) for each database.

A functional example of the script to dump each database is as follows:

#! /bin/bash

BACKUP_DIR="/root/mysql-dumps/"
MYSQL_USER="root"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="mysql-root-password"
MYSQLDUMP=/usr/bin/mysqldump

databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`

for db in $databases; do
	$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db.gz"
done

Subsequently, it is advisable to schedule the execution of the script before each backup so that the backup procedure also saves the dump files created by the script.

The steps are as follows:

  • Connect to the Acronis platform, click on the 'Devices/All Devices' item in the menu on the left;
  • select the server on which the script is located;
  • click on the 'Backup' section on the right; then, click on the gear icon that appears on the right;
  • select 'Backup Options' from the menu;
  • Acronis MySQL
  • go to the 'Backup options' menu under 'Pre-post commands';
  • in the window shown at right, set the 'Run a command before backup' choice to Yes;
  • enter the path to the script file in the text box labelled 'Command or Batch File Path on Agent Machine';
  • Acronis pre-post command
  • Finally, save the changes for the backup plan by clicking first on the 'END' button and then on the 'SAVE CHANGES' button in the next screen.