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. AutoMySQLBackup des not work on Shared and Reseller servers or on Dedicated servers with CloudLinux installed.
- 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:
- Use your web browser to go to http://sourceforge.net/projects/automysqlbackup, and then click . Save the .tar.gz file on your computer.
- 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).
- Log in to your account using SSH.
- At the command prompt, change to the directory where you uploaded the .tar.gz file in step 2.
- 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.
To install AutoMySQLBackup, type the following command:
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.
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.
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.
If you receive this message, type n and then press Enter to complete the installation.
After you download and install AutoMySQLBackup, you can configure the settings for your own environment. To do this, follow these steps:
- Log in to your account using SSH.
- 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.
- 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:
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.
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:
By default, AutoMySQLBackup backs up all MySQL databases. You only need to change this setting if you want to back up specific databases.
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:
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:
- 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.
- 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:
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:
For more information about how to use cPanel to create a cron job, please see this article.
- Connecting to MySQL from the command line
Learn how to connect to MySQL from the command line using the mysql program with this guide including detailed instructions, code snippets and links to related articles.
- MySQL database backups using cron jobs
Learn how to set up a cron job that automatically backs up a MySQL database at defined intervals.
- Importing and exporting a MySQL database
Learn how to how to import MySQL databases and export MySQL databases. If you already have a database that you want to install on an A2 Hosting server, or you want to back up your database, this article shows you how.