Backing up and restoring Linux MySQL with LiveVault

This article provides guidance for LiveVault users wishing to backup and restore Linux MySQL databases.

To accurately back up Linux MySQL data, you must stop MySQL before the backup job starts, then start MySQL after backup completes. This is also true for restoring MySQL data.

How MySQL is installed on a Linux computer determines where its databases and programs are. The sections included in this article cover three common MySQL installations:

You may wish to run a script before, or after, a MySQL backup. An additional section entitled Running scripts before and after backup is included at the end of the article to provide advice.

Note
MySQL version V3.23.52 was used to develop these procedures; they might not apply to other versions.

For all installations, log in as root to perform the following steps.

 

MySQL installation using Red Hat binary or source packages (rpm)

In this variation, the databases are in /var/lib/mysql by default.

To back up MySQL using Red Hat, proceed as follows.

  1. Configure a separate backup policy for MySQL, backing up all of MySQL on it.

Important:
If you do not back up all of MySQL, Then LiveVault cannot guarantee the integrity and recoverability of your MySQL databases.

  1. Stop MySQL. Include the following command in the pre-backup script: /etc/rc.d/init.d/mysql stop.

LiveVault backs up MySQL according to the schedule specified for your MySQL backup policy.

  1. When the backup is complete, start MySQL. Include the following command in the post-backup script: /etc/rc.d/init.d/mysql start.

 

MySQL installation using binary packages (tar.gz)

In this variation, the databases are in /usr/local/mysql/data by default.

Note:
If MySQL is configured to start and stop as suggested in the mysql.server script, then follow the steps in MySQL installation using Red Hat binary or source packages (rpm) above.

To back up MySQL using binary packages (tar.gz), proceed as follows.

  1. Configure a separate backup policy for MySQL, backing up all of MySQL on it.

Important:
If you do not back up all of MySQL, LiveVault cannot guarantee the integrity and recoverability of your MySQL databases.

  1. Open the mysql.server script, and replace @HOSTNAME@ with /bin/hostname, for example: vi /usr/local/mysql/support-files/mysql.server

This step only needs to be done once.

  1. Stop MySQL. Include the following command in the pre-backup script: /usr/local/mysql/support-files/mysql.server stop. (If you are running a restore, enter the following command: sh /usr/local/mysql/support-files/mysql.server stop).

 LiveVault backs up MySQL according to the schedule specified for your MySQL backup policy.

  1. When the backup is complete, start MySQL. (Include the following command in the post-backup script: /usr/local/mysql/support-files/mysql.server start. (If you are running a restore, enter the following command: sh /usr/local/mysql/support-files/mysql.server start).

 

MySQL installation using source packages

In this variation, the databases are in /usr/local/mysql/var by default.

This variation assumes the default directory, /usr/local/mysql, is used to install MySQL.

If MySQL is configured to start and stop as suggested in the mysql.server script, then follow the steps in MySQL installation using Red Hat binary or source packages (rpm) above.

To back up MySQL using source packages, proceed as follows.

  1. Configure a separate backup policy for MySQL, backing up all of MySQL on it.

Important
If you do not back up all of MySQL, then LiveVault cannot guarantee the integrity and recoverability of your MySQL databases.

  1. Stop MySQL. Include the following command in the pre-backup script: /usr/local/mysql/share/mysql/mysql.server stop.

 LiveVault backs up MySQL according to the schedule specified for your MySQL backup policy.

  1. When the backup is complete, start MySQL. Include the following command in the post-backup script: /usr/local/mysql/share/mysql/mysql.server start.

 

Running scripts before and after backup

The LiveVault software lets you run a script before and after a backup job when using LiveVault in Linux. For example, you might want to export data before a backup runs.

To specify backup scripts, proceed as follows.

  1. On the Computer Backup tab, select Edit.
  2. Select the Options tab.
  3. Select the backup policy you want from the list.
  4. Enter the full path and program name in the Program to Run Before Each Backup and Program to Run After Each Backup fields. The file must be a Bourne shell script (/bin/sh).
  5. Click Next.

The Backup Configuration Confirmation page opens.

  1. In the Backup Configuration Confirmation page, verify your pathnames. Make any necessary changes.
  2. Click Done.