Backing up MySQL in B3 Server to

2011/11/06 by Paulo Pereira

~/categories/Linux #Linux #B3 Server #MySQL

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

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


Be sure duplicity is installed:

apt-get install duplicity

Generate an ssh key to connect to

ssh-keygen -t rsa
scp ~/.ssh/
cat ~/.ssh/ | ssh '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) <>
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://
duplicity --encrypt-key="1AAB123A" scp:// ~/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!