I recently came across a nifty little tool called Tarsnap.
From the Tarsnap home page:
Tarsnap is a secure online backup service for BSD, Linux, OS X, Solaris, Cygwin, and can probably be compiled on many other UNIX-like operating systems. The Tarsnap client code provides a flexible and powerful command-line interface which can be used directly or via shell scripts.
Here’s a quick and easy guide to get you up and running backup up all of your MySQL databases.
Automate the MySQL Backup
In your home directory:
mkdir backups && cd backups
Download: http://sourceforge.net/projects/automysqlbackup/ to the backups directory you just created.
Rename it:
mv automysqlbackup.sh.2.5 automysqlbackup.sh
Make it executable:
chmod u+rwx automysqlbackup.sh
Edit it:
nano automysqlbackup.sh
Fill out your database name, password, and the names of the databases you want to backup.
Look for the commented POSTBACKUP line. Add these two lines right below it (replace username with your username).
1 2 |
|
Install and Setup Tarsnap.
Follow the instructions on the Tarsnap getting started page: http://www.tarsnap.com/gettingstarted.html
You should have donwloaded, paid for, and installed Tarsnap before continuing.
We’re going to use the tarsnap sample config (cache dir and key location).
cd /usr/local/etc cp tarsnap.conf.sample tarsnap.conf
Now run your backup script:
sudo ./automysqlbackup.sh
Check to see if you’re backup was created and stored remotely:
sudo tarsnap --list-archives
Now we’re going to create a cronjob to run the script on a daily basis (or you could move it to your /etc/cron.daily).
1 2 3 |
|
Now you’re databases are being backed up daily on a rotation keeping weekly and monthly dumps and storing them both on and off-site (encrypted).