BackupPC

Introduction
You may have been looking for a nice way to backup your files, and of those computers and devices you have in your network.

BackupPC is a program written mostly on perl and cgi-scripts which is run under an Apache server. BackupPC is capable of making backups of Linux machines, Windows and Mac and support secure remote connections, data encryption, compression and a lot of other features. It is fairly simple to configure and it has all the robust features you may be looking for.

Pre-requisites and assumptions
It's desirable that the user already have some knowledge about the following topics:
 * Backup strategy
 * Apache server configuration and apache server files hierarchy
 * Setup SSH Keys
 * Rsync and rsyncd
 * Setup and using Samba

Some of those pre-requisites will be covered during this tutorial, but it is better if the user already has some experience with those topics.

Also, during this article some commands from the ebuild will be used. They are very usefull for any Gentoo installation, so you may want to have this particular package installed before continuing.

If you are not too familiar with the Gentoo "ways of life", then you better read the article USE Flags where you will find a lot of information regarding best pratices to use Gentoo.

It is good to remember that all commands that are shown here to be run as root may be run with the command.

Also, when mentioned in this article, PC means any desktop, workstation or server. Portable devices are laptops, Mobile Internet Devices (MID) and all the other sort of things mobile.

USE flags required
Make sure Apache you enable/disable the following USE flags:

Modules
You may want to use the following modules in your Apache installation. Specifically, those in bold are the ones that BackupPC really requires for a successfull installation.

Some of those modules may already be installed as part of Apache. To check which Apache modules and USE flags your installation is using already, please run the following command

If you don't have Apache installed yet, then you will need to configure your system before emerging. To do that, add the required modules to your /etc/make.conf file and configure the flags correctly by editing your /etc/portage/package.use file.

SSH
You should have the newest version of SSH and use SSH-2 as the specified protocol. Also, root must be able to login to SSH without using a password. This requirement is due to the fact that when BackupPC is running the backup task and using the rsync mode, it must be able to read all the files related to the backup and set the backup bit on them. If you are only doing backups of files that a simple user can ready, then there is no need to setup root's SSH access without a password

Check if you already have installed

If it isn't installed, then you should install it. Some of the USE flags you should set, but are not strictly necessary, are

After taking care of which USE flags you want to use, you should emerge the package

Configure SSH keys so the ssh command does not ask for a password. Make sure you have followed the Setup SSH Keys article to understand how to setup SSH keys for accessing without a password.

It is a good idea to try and SSH from the server to the client nodes to make sure everything is working. Try that with root, if the client is Linux or Mac

If everything has been set up correctly, you should see the output of the command uptime in your display. If you had a 'Permission Denied!' or some other error, please check your log files and correct that error before continuing.

It is a good idea to add the BackupPC's public keys to root's authorized_keys file too. That will make BackupPC user to be able to run something like

and the output will be root.

Installing BackupPC
BackupPC requires Apache, Perl modules and CGI. Some of those components will be installed during the installation of BackupPC. Others may be installed after, as they are not pre-requisites for the installation but are required for it to run smoothly.

To install BackupPC you have to emerge the ebuild. You should customize it to have the USE flags you prefer. In this article, the following USE flags were used:

You may add those USE flags to your /etc/portage/package.use by running the following command

So, finally, you emerge the ebuild

Configuring the server
BackupPC supports different ways for configuring which servers are going to be backed up. If you only have one kind of operating system in the network you want to backup, or if you just want to use a single protocol/daemon to do this backup, then you should use just the global file.

But, even though your case may be the one cited above, perhaps you want to backup different directories from different machines. If that's the case, then I advice you to use per-server configuration files. Below you will find an example from each type of configuration:

Anyway, both cases do use the global configuration file for other settings which are "global". Below you will find a list of variable you should setup correctly to best fit your needs: $Conf{WakeupSchedule} = [5]; $Conf{MaxBackups} = 4; $Conf{MaxUserBackups} = 4; $Conf{MaxBackupPCNightlyJobs} = 4; The global configuration file is well documented and you can read what those variables are on it. The example above sets the following environment:
 * It will wake-up at 5AM to start the jobs
 * It will run a maximum of 4 backup jobs simultaneously
 * It will let the user start a maximum of 4 jobs simultaneously
 * It will run 4 jobs in parallel, during night time backup

You also have to tell BackupPC which hosts you want to backup. You should edit the /etc/backuppc/hosts file and make the appropriate changes. name      dhcp  user      moreUsers server     0    backuppc  regUser,otherUser,admin desktop    0    regUser   backuppc,otherUser laptop     1    regUser   otherUser

Explaining the colums:
 * name => you should use the hostname of the machine you want to backup. It could also be the FQDN of the machine. This parameter is used by nslookup and DNS queires, so if you want to check you have set this correctly you can either check your /etc/hosts file and see if this host is define there (you got also to make sure your /etc/nsswitch.conf file is setup to query the hosts file first before the DNS) or you can run the command below:


 * dhcp => for all the PC/Portable Devices with static IP, this field should be set to 0. If your PC/Portable Device gets its settings from a DHCP server, then you need to set this to 1.
 * user => this is the user that will be authorized to run the backup job. Also this has to be the same as the user that authenticates in Apache, otherwise you won't be able to run backup jobs from the web interface. Also, this is the user that will receive emails concerning the backup jobs for this host.
 * moreUsers => this is where you put information about other users which are allowed to run the backup job. This must be the same user as the one that authenticates in Apache.

Using only the Global configuration file
If you are planning on having only the global configuration file to specify which PC or Portables Devices and what files/directories each will backup, then you can edit the rest of the global configuration file as described in it.

An example using rsync to backup more than one PC/Portable Device. Those PC/Portable Devices could be running any flavor of Unix (with support for SSH connections and the basic Unix commands like df, cat, gzip, bzip2, tar, and others) or any flavor of Windows (with support for the Rsync daemon).

Using one configuration file per-PC
If you planning on using one configuration file per PC/Portable Devices, then you need to copy the /etc/backuppc/config.pl file to the directory of your PC/Portable Device.

First create a directory for your PC/Portable Device

where $hostname is the name of the PC/Portable Device you have defined in the /etc/backupp/hosts file

Configuring the clients
Unfortunately, by the time I wrote this article I had no access to a Mac machine. But, Macs are essentially similar to Linux since they are *NIX. Ok Mac-users, don't chastize me if you don't agree with the last statement :-)

BackupPC essentially have a commom configuration file, where it gets all the "global" variables and per-PC configurations files. Those individuals per-PC configuration files are the ones that BackupPC will use to know how to connect to that specific machine and what to backup from them. Of course you could have just the commom configuration file, but then all the machines you want to backup would to accept the same type of remote connection and use the same user/pass combination, not to mention that they would need to have the same directories you have set up.

Linux
Linux machines can choose from different type of remote connections, but rsync is the one used in this article and it is by far the most flexible and reliable for this type of machine.

Windows
Windows machine should be configured to use rsync, if you have a rsync daemon running on your Windows, or use SMB/CIFS protocol. Rsync is more flexible but SMB/CIFS is easier to set up and don't require much tweaking on the Windows machine.

Part-time connected devices
If you have a laptop or a netbook, you may want to backup those devices as well. For each device that is not connected all the time to the network, you need to follow the basic steps for the Operating System it runs, as described above, and change slightly the per-PC configuration file for them.

Windows
Some versions Windows have the Windows Firewall activated at the initial installation (ex: XP and Vista) and some are very restrictive about the rules set on the firewall (ex: Vista). You should check the Windows Firewall to see if it is activated and if the rules set are not restricting access to this machine.

Also, you may have problems doing backups of sub-directories of an exported directory. A workaround for this is to define one share per directory you want to backup. Then, on the per-PC configuration file you have for this machine, you should configure to have each share backuping one directory.