Monday, May 3, 2010

Backuppc Basic Setup and Configuration on Debian Lenny for Windows and Linux Hosts

Backuppc is an extremely robust and flexible backup solution for your entire network.  Unfortunately, the very complex and flexible nature of Backuppc makes it a very complicated solution to setup and get working correctly.  However, as usual, installing the application on debian is very easy:
sudo aptitude install backuppc
Unfortunately that is only the first step... once it is done installing, it will have you answer some setup questions about setting up the web interface.  It will also generate a password for the web interface that you will need to use to log on.
Once the setup is complete, you can visit the backuppc web interface through http://localhost/backuppc.  One of the errors you may be greeted with is "Error: Unable to connect to BackupPC server".  If that happens, it may be because backuppc is not running, or is attempting to run under the wrong user.  To fix this (in almost every case), you need to change your use to backuppc, and start backuppc again.
su backuppc
/usr/share/backuppc/bin/BackupPC -d
This should start backuppc as a daemon, solving your problem, and allowing you to once again revisit the web interface.
The web interface is laid out (in my opinion) in a slightly confusing way.
The view you will see when you first log on is an overall server status page.  Once you have hosts with backups, there will be some very useful graphs displaying pool storage size.  Good, you have the basic program up and running... now for a little bit of customization.

Changing the Backuppc Pool Directory
By default, all your backups are stored at /var/lib/backuppc.  However, I wish to store my backups on another disk drive that has a lot more storage than my system disk.  To do this we need to create a soft link from the default backup directory to whatever directory you wish to store the backups.  You will notice that we create two directories called "pc" and "cpool". "pc" is where all the files are stored, and those two directories were originally causing permission issues.
Changing the Pool directory:
cd /var/lib/backuppc
sudo rm -r *ln -s /var/lib/backuppc /new_drive/backuppc
sudo mkdir pc cpool
cd ..
sudo chown -R backuppc *
If you have problems, it may be a permissions issue:
sudo chmod -R 777 backuppc
I would recommend not leaving the permissions wide open... just make sure it is a permission error and slowly restrict the permissions until everything works correctly.  Now the backups should redirect directly to your new drive.

Adding Hosts
Now we need to add some hosts for backup.  Select "Edit Config" from the left menu.  Click on the "Hosts" tab.  Here we can add hosts for backup.  I personally have DNS reservations for all of my hosts, so I can add by IP, however if your hosts will have different IP's I would highly recommend checking the DHCP option.  As long as your hosts are registered in DNS backuppc can track them and back them up no matter where they are.  Add the hosts you will be backing up, hit save, and then click on the "Xfer" tab.

Setting Default Xfer Options (for Windows)
Next, we need to set the default transfer settings.  This is mostly a setting for large networks of pc's that are set up the same way, which makes it unnecessary for the admin to configure each pc individually. Click on "Edit Config" on the menu on the left, and select "Xfer" from the top menu.  How you set this up depends entirely on your network setup.  I have two Windows 7 PC's, so I will be setting the default settings for a SMB share.

The above screen shot shows the settings I set for the default.  I chose SMB for the transfer method.  The advantage of using SMB is that it is already built into Windows... which is good from an ease of use scenario, but is not as good from a security standpoint.  For the SMB share name, I added the administrative C$ share, which is the entire C$.  In this instance I also should have set default "Include/Exclude" settings.  This part is not extremely intuitive, and it took me a little while to figure that out.  Shown below is one of my host machines.

To ensure that only the right files are backed up, we need to add first the "SmbShareName" to the "New Key" field, and click "Add".  Once we have added the base share name, we can add the individual paths that we wish to backup.  You will notice above that I told backuppc to backup only the "Users" directory under the C$ share.  So now, instead of backing up the entire OS, backuppc will only backup "C:\Users", which is a much better option. You can obviously add more than one folder.  You can also add folders to exclude, which is a nice option as well. Notice that the "Override" box is checked... that just means that this host differs from the default configuration in this area.

Backing up the Localhost
Backing up the localhost is the easiest of all the pc's to backup (in my opinion).  The easiest way to backup your linux localhost is through "tar".  In the top host drop-drop menu, select "localhost".  Click on "Edit Config" which will enter the host-specific configuration.  Select "tar" and from the "XferMethod" drop-down menu.  Next, we need to select the tar share names that we wish to back up.  Since the localhost is not running a whole lot of services, and is not mission critical, I am only backing up the /var and /etc directories.  Go ahead and save the config and you should be ready to backup your localhost!

Backing up Linux Hosts with Rsyncd
I prefer the rsyncd method for backing up linux hosts.  It does involve installing rsyncd on the linux hosts in question, but it is a rather quick install.
sudo aptitude install rsync
Once that is done installing, we need to setup the configuration file.  On linux, the config file is called rsyncd.conf and is located at /etc/rsyncd.conf.. so
sudo nano /etc/rsyncd.conf
Now we copy the config in:
Now we need one more file to complete the configuration. The file is called rsyncd.secrets, and is stored in whatever place you specified in rsyncd.conf. The file only contains one line
backuppc:Yourpassword
The format of the file is simple: username:Password. Make sure the username matches exactly what you specified in rsyncd under "auth users", otherwise you will have difficulties.
Next we need to secure the secrets file:
sudo chown root /etc/rsyncd.secrets
sudo chmod 600 /etc/rsyncd.secrets

Next, lets setup the backuppc side... shown below is a screenshot of the configuration.
The "RsyncShareName" is the share name that you specified in the rsyncd.conf file.  The username and password should match exactly what is in the rsyncd.secrets file, and make sure the "RsyncdAuthRequired" is checked.  You will notice in the config I posted above, I was very aggressive and made the share root be root.  That being the case, there are many folders I should exclude from backing up, since they are either temporary folders/files or files/folders I really don't want backed up (i.e. floppy).  As well, be very careful about hard/soft links as those can cause issues.
If you experience problems, there is one configuration issue that you can check on the backuppc server.
When using rsyncd for backuppc you will need the File::RsyncP perl module installed.  It may be installed already, but if not perldoc File::RsyncP, to make sure RsyncP is installed.
As well, the log file on the client machine is a great help as well, located at /var/log/rsyncd.log.


Restoring Files, Logging and Information
Well, you now have a local backup solution for all your PC's.  Now you can use backuppc's powerful logging and reporting functions to view the status of all your backups.  As well, you can easily browse your backups and restore files if needed.  To browse backups, just select your host, and in the left menu will be an option to  "Browse Backups".  Select this to browse and restore backups.
Congratulations on completing the basic Backuppc setup.  Hopefully in a later post more advanced topics can be covered.