Backup MySQL Databases with AutoMySQLBackup on Ubuntu

AutoMySQLBackup is a free opensource tool that automatically backs-up all the databases hosted on a MySQL server at varying intervals. It’s a great tool that may come in handy in a time of trouble. Not only can it backup MySQL databases automatically, it also comes with many features like email notifications, incremental backups, back up compression and encryption.

If you’re looking for a simple yet powerful tool to automatically backup MySQL databases, you may want to try this. You probably won’t regret it.

This brief tutorial is going to show you how to install and configure in on Ubuntu servers.

To get it installed and configured, follow the steps below

Step 1: Install AutoMySQLBackup

This post assumes you already have MySQL server installed and have few databases to backup. If you haven’t done that, please search on this blog to find easy tutorials on installing MySQL or MariaDB servers.

When you have MySQL server installed and few databases created, continue below to install AutoMySQLBackup.

Run the commands below to install the tool.

sudo apt-get update
sudo apt-get install automysqlbackup

During the installation, you’ll be prompted to choose a mail configuration as shown below. Select Internet Site if you’re going to be setting up email notification. If not, then just select No configuration.

Please select the mail server configuration type that best meets your needs.
No configuration:
Should be chosen to leave the current configuration unchanged.
Internet site:
Mail is sent and received directly using SMTP.
Internet with smarthost:
Mail is received directly using SMTP or by running a utility such
as fetchmail. Outgoing mail is sent using a smarthost.
Satellite system:
All mail is sent to another machine, called a 'smarthost', for delivery.
Local only:
The only delivered mail is the mail for local users. There is no network.
General type of mail configuration:

                    No configuration
                    Internet Site
                    Internet with smarthost
                    Satellite system
                     Local only
         <Ok>                                       <Cancel> 

 

After selecting your options, select Ok to continue with the installation.

Step 2: Configure AutoMySQLBackup

Now that the tool is installed, go and configure it. I couldn’t find any configuration file crated, so I had to create one myself. The default configuration directory for AutoMySQLBack is at:

/etc/automysqlbackup/

Create a new configuration file with the parameters as shown below. Run the commands below to create a new configuration file.

sudo nano /etc/automysqlbackup/automysqlbackup.conf

Then add the content below into the file and save.

CONFIG_mysql_dump_username="root"
CONFIG_mysql_dump_password='root_password'
CONFIG_mysql_dump_host="localhost"
CONFIG_backup_dir="/var/backup/db"
CONFIG_do_monthly="01"
CONFIG_do_weekly="5"
CONFIG_rotation_daily=6
CONFIG_rotation_weekly=35
CONFIG_rotation_monthly=150
CONFIG_mysql_dump_port=3306
CONFIG_mysql_dump_compression='gzip'

Save the file

Now to run the backup manually, just type the commands below.

sudo automysqlbackup

To automatically run the backup daily, run the commands below.

sudo ln -s /usr/sbin/automysqlbackup /etc/cron.daily/

That’s it!

Also look in the folder below for back up jobs that were run manually.

/var/lib/automysqlbackup

Summary:

This post shows students and new users an easy want to automatic MySQL backup on Ubuntu. With AuthMySQLBackup tool, one can set a backup job to run daily, weekly or monthly.

The job will then backup all MySQL databases and store them in the location specify.

Enoy!

You may also like the post below