Knowledge Base

How to back up MySQL databases using AutoMySQLBackup

This article describes how to use the AutoMySQLBackup tool to back up MySQL databases.

AutoMySQLBackup is a flexible script that enables you to create backups at varying intervals, such as daily, weekly, and monthly. By rotating your backups, you can preserve storage space on your account. You can even send backup files to external e-mail accounts for off-site backup redundancy.

  • Server Rewind on managed VPS accounts does not include database backups and restores, so you should follow the procedures below to set up your own database backups on a managed VPS.
  • Although A2 Hosting servers are compatible with a wide variety of software applications, we cannot provide troubleshooting assistance for application-specific issues. The procedures below are for demonstration purposes only.

Downloading and installing AutoMySQLBackup

To download and install AutoMySQLBackup on your account, follow these steps:

  1. Use your web browser to go to http://sourceforge.net/projects/automysqlbackup, and then click Download. Save the .tar.gz file on your computer.
  2. Upload the .tar.gz file to your A2 Hosting account. To do this, you can use FTP, SFTP, or the cPanel File Manager (if your account includes cPanel access).
  3. Log in to your account using SSH.
  4. At the command prompt, change to the directory where you uploaded the .tar.gz file in step 2.
  5. To extract the application files from the .tar.gz file, type the following command:
    tar xvzf automysqlbackup-v3.0_rc6.tar.gz
    The exact filename may differ slightly, depending on the version you downloaded.
  6. To install AutoMySQLBackup, type the following command:

    ./install.sh
  7. At the Select the global configuration directory prompt, type the path where the configuration files will be stored.

    If you have a shared hosting account, make sure the path begins with /home/username, where username represents your A2 Hosting account username.
  8. At the Select directory for the executable prompt, type the path where the program file will be stored.

    If you have a shared hosting account, make sure the path begins with /home/username, where username represents your A2 Hosting account username. Additionally, you may have to modify the PATH setting in your .bash_profile file to include the directory where the AutoMySQLBackup script file is located.
  9. If you are installing AutoMySQLBackup on a shared hosting account, you may receive the following message:

    exists already ... searching for config files:
    Found config file /home/username/*.conf. head: cannot open `/home/username/*.conf' for reading: No such file or directory
    No version information on first line of config file. Assuming the version is <3.
    Convert? [Y/n]

    If you receive this message, type n and then press Enter to complete the installation.

Configuring AutoMySQLBackup

After you download and install AutoMySQLBackup, you can configure the settings for your own environment. To do this, follow these steps:

  1. Log in to your account using SSH.
  2. Use a text editor to edit the myserver.conf file. The myserver.conf file is located in the configuration directory that you specified in the previous procedure.
  3. To configure basic backup settings, remove the pound sign (#) from the start of the following lines in the myserver.conf file, and then change the values to match your own installation:
    CONFIG_mysql_dump_username='username'
    CONFIG_mysql_dump_password='password'
    CONFIG_backup_dir='/home/username/mysqlbackups'
    Make sure you use a MySQL username and password, and not the username and password you use to log in to SSH. Addtionally, make sure that the path you specify for the backup directory exists. AutoMySQLBackup does not automatically create the directory.
  4. To specify specific databases to back up, remove the pound sign (#) from the start of the following line, and change the value to the databases you want to back up:

    CONFIG_db_names=()
    By default, AutoMySQLBackup backs up all MySQL databases. You only need to change this setting if you want to back up specific databases.
  5. To specify rotation settings for the different backup intervals, remove the pound sign (#) from the start of the following lines, and then change the values to the rotation settings that you want:

    CONFIG_rotation_daily=6
    CONFIG_rotation_weekly=35
    CONFIG_rotation_monthly=150
  6. To send backup files to an e-mail account, remove the pound sign (#) from the start of the following lines, and then modify them as shown. Replace [email protected] with the e-mail address where you want to send the backup files:

    CONFIG_mailcontent='files'
    CONFIG_mail_use_uuencoded_attachments='yes'
    CONFIG_mail_address='[email protected]'
    • A2 Hosting strongly recommends that you periodically store database backup files at a location separate from the web server. The e-mail feature in AutoMySQLBackup is one way to easily accomplish this.
    • AutoMySQLBackup uses the mail program to send backup files to an e-mail account. By default, the mail program is disabled on shared hosting accounts. If you want to send backup files on a shared hosting account to an e-mail address, please open a support ticket at https://my.a2hosting.com and request access to the mail program.
  7. Save the changes to the myserver.conf file and exit the text editor.

Running a backup

After you configure AutoMySQLBackup for your environment, you can run backups. To run a backup manually using AutoMySQLBackup, type the following command. Replace path with the path to the myserver.conf file:

automysqlbackup "path/myserver.conf"

However, you will most likely want to automate the process and create backups automatically. To do this, you can set up a cron job that runs the following command. Replace the username and path values as required by your own configuration:

/home/username/path/automysqlbackup "path/myserver.conf"

For more information about how to use cPanel to create a cron job, please see this article.