Automatic MySQL Backups

MySQL
This feature goes perfectly with my previous article on Google Drive Syncing. If you pair it with these automatic backups you can have your mysql backups automatically sync to your google drive account. I recommend checking that article out first then returning here and completing this guide as well.

Install

Ubuntu has a package in it’s repos called “automysqlbackup” that is dirt simple to get running out of the box.

sudo apt-get install automysqlbackup

Now here is where you can customize it. The configuration file has a setting that tells it where to create the backup files.

sudo nano /etc/default/automysqlbackup

Look for the line that reads

BACKUPDIR="/var/lib/automysqlbackup"

Change it to where you want the backups stored. If you followed my previous Google Drive guide that would be something similar to this

BACKUPDIR="/home//gdrive/mysql_backups"

If you are using Google Drive to back these up you will have one more step. This is due to the fact that the backup files are created as root and grive will run into permission issues trying to sync.

To fix this we will be modifying the grive bash script to change the permissions on the folder (and it’s contents) and then execute grive.

nano ~/scripts/grive.sh

Modify it to look similar to this

#!/bin/bash

chmod 755 /home//gdrive/ -R
chown : /home//gdrive/ -R

cd /home//gdrive
./grive

Save the file and you are done.

You can kick it off manually or wait for the cron to execute on it’s own.

sudo automysqlbackup

Posted in Server Admin Tagged with: , , , , , ,

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *

*