paapereira.xyz

Backing up MySQL in B3 Server to 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:

1su
2apt-get install duplicity

Generate an ssh key to connect to rsync.net

1ssh-keygen -t rsa
1scp ~/.ssh/id_rsa.pub user@server.rsync.net:.ssh/authorized_keys
1cat ~/.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

1gpg --gen-key
1gpg --list-keys
1pub 1239A/**1AAB123A** 2011-10-09 [expires: 2012-10-08]
2uid Your Name (name) <mail@mail.com>
3sub 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.

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

#Linux #B3 Server #MySQL #Rsync.net