Backing up MySQL in B3 Server to rsync.net

2011/11/06 by Paulo Pereira

~/categories/Linux #Linux #B3 Server #MySQL #rsync.net

In a previous post I talked about how to backup to rsync.net using duplicity.

I will now show how to backup your B3 Server Mysql databases using the same method.

Installation

Be sure duplicity is installed:

su
apt-get install duplicity

Generate an ssh key to connect to rsync.net

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub user@server.rsync.net:.ssh/authorized_keys
cat ~/.ssh/id_rsa.pub | ssh user@server.rsync.net 'dd of=.ssh/authorized_keys oflag=append conv=notrunc'

Generate a gpg public and private key to encrypt your backups

gpg --gen-key
gpg --list-keys
pub 1239A/**1AAB123A** 2011-10-09 [expires: 2012-10-08]
uid Your Name (name) <mail@mail.com>
sub 54321/1234BBCC 2011-10-09 [expires: 2012-10-08]

Backup/restore your databases

I have MyISAM tables, so I will be using the mysqlhotcopy command. You can also use mysqldump.

mysqlhotcopy -u *backupuser* -p *userpassword* *database1* ~/backup --allowold --keepold
mysqlhotcopy -u *backupuser* -p *userpassword* *database2* ~/backup --allowold --keepold
tar -cvf ~/backup/backup.tar ~/backup/* --exclude='*_old'
duplicity full --encrypt-key="1AAB123A" ~/backup/backup.tar scp://user@server.rsync.net/backups
duplicity --encrypt-key="1AAB123A" scp://user@server.rsync.net/backups ~/backup/backup_restore.tar
/etc/init.d/mysql stop
tar -xvf ~/backup/backup_restore.tar /var/lib/mysql/
/etc/init.d/mysql start

I’m backing up and restoring all my databases at once. You could create a different archive for database or extract the restore file to a different location and the copy the database you want to restore.

Check out my duplicity post to see what more can you do with duplicity.

Feedback and suggestions appreciated!