BackupPC on Ubuntu 10.10 Maverick

Update: The instructions below will also work for newer versions of Ubuntu, e.g. Ubuntu 12.04 LTS.

There are a lot of server backup solutions out there and if you only manage a few servers chances are high that you are using your own scripts based on rsync and mysqldump to backup your machines. Well, you could have it so much easier. BackupPC is easy to install and configure and probably your only question will soon be “Why didn’t I use it earlier?”.

Install BackupPC

Install is as simple as it gets, just run

sudo apt-get install backuppc rrdtool

rrdtool is needed to show the pool size graphics at the status page, but Backuppc will also work if you decide not to install it. During installation Backuppc will create a default user ‘backuppc’ and give you a password, write it down as you will need it later. If you forget your password you can change it later by running htpasswd /etc/backuppc/htpasswd backuppc.

When installation is complete create a new ssh key so that you can use key based authentication.

sudo su -l backuppc
sudo ssh-keygen -t rsa -C "backuppc"```

You might want to specify some directories that should not be backuped, e.g. temporary files and log files. To do so edit */etc/backuppc/config.pl* and change *$Conf{BackupFilesExclude}*.

`$Conf{BackupFilesExclude} = ['/dev', '/proc', '/media', '/mnt', '/var/lib/backuppc', '/lost+found', '/tmp', '/var/tmp', '/var/run', '/var/log'];`

If you backup clients over the Internet you should also set *$Conf{PingMaxMsec}*, otherwise BackupPC won’t backup clients that have a ping over 20 milliseconds; I set it to 200.

`$Conf{PingMaxMsec} = '200';`

BackupPC is installed now and you can login at http://yourdomain/backuppc with the user name backuppc and the password given during installation.

**Set up the client which should be backuped**

Login to the client you want to backup and make sure sudo and rsync are installed

`sudo apt-get install sudo rsync`

``Add a user account to run the backups, e.g backuppc:

sudo adduser backuppc
sudo echo "backuppc ALL=NOPASSWD: /usr/bin/rsync" >> /etc/sudoers```

Copy the ssh key that you created on the server onto your client. To do so login to your backuppc server and as backuppc user copy the key with ssh-copy-id.

sudo su -l backuppc
ssh-copy-id backuppc@clienthostname```

Try if it works by connecting to the client, you should be able to login without password. To increase security you can edit .ssh/authorized_keys and add *from=”your server ip address”* before ssh-rsa so that login is only possible from your backup server.

Login to backuppc at http://yourdomain/backuppc with the user name backuppc and the password given during installation. Go to ‘Edit Hosts’ and add the client host name and backup user, e.g. backuppc.  
 Find the settings RsyncClientCmd and RsyncClientRestoreCmd and change root to backuppc and add sudo in front of $rsyncPath so that  
*RsyncClientCmd* is  
`$sshPath -q -x -l backuppc $host sudo $rsyncPath $argList+`  
 and *RsyncClientRestoreCmd* is  
`$sshPath -q -x -l backuppc $host sudo $rsyncPath $argList+`  
 Click the save button to apply the change.

The client is set up now. You can manually start the backup by going to ‘Host Summary’, clicking the host name and then the button ‘Start Full Backup’. If you are running a MySQL server on the client please also follow the next step.

  
**Configure MySQL backup**

BackupPC allows you to execute a script before starting the backup. You could just write your own simple mysqldump script but I’d recommend to use Mark Grennan’s excellent AutoMySQLBackup script. By default it will create a separate file for each database which makes it very easy to recover a single database. It will also make a daily, weekly and monthly backup.

Create a new MySQL user, e.g. backuppc, with only SELECT, SHOW VIEW, LOCK, SHOW DATABASES and RELOAD privileges.

Download the latest version of AutoMySQLBackup at [http://sourceforge.net/projects/automysqlbackup/](http://sourceforge.net/projects/automysqlbackup/ "AutoMySQLBackup") (click on ‘Browse all files’ to see the downloads) to your backuppc user folder, probably /home/backuppc/. Open the script in an editor and set the user name, password and email address.

The standard location of the backups is /srv/backup/db. If you want to keep this create the folder and set the necessary write permissions.

sudo mkdir -p /srv/backup/db sudo chown backuppc /srv/backup/db

Set the owner and file permissions of the script to your backup user.

sudo chown backuppc automysqlbackup.sh sudo chmod 700 automysqlbackup.sh

Now login to the BackupPC webinterface, select your client from the pull down menu on the top left side and click ‘Edit Config’ (don’t use the ‘Edit Config’ link in the ‘Server’ section, these are the global settings) and set *DumpPreUserCmd *under Backup Settings to

sshPath -q -x -l backuppc $host /home/backuppc/automysqlbackup.sh

Remember to click the ‘Save’ button to apply the change.

**Useful links**  
[ Debian Administration BackupPC Introduction](http://www.debian-administration.org/articles/588 "Debian BackupPC")  
[CentOS BackupPC Guide](http://wiki.centos.org/HowTos/BackupPC "CentOS BackupPC Guide")


BackupPC on Ubuntu 10.10 Maverick
Share this