BackupPC is an awesome program for backing up your data in an efficient manner. It provides you with an easy to use web interface and some very complete documentation. Read more about it at the BackupPC SourceForge page.
For some reason, the FreeBSD ports tree still does not contain BackupPC! This guide details the configuration steps to get BackupPC running with an Apache (lighttpd also supported, though) web interface on a FreeBSD host.
Dependencies
Sadly, there is not a BackupPC port for FreeBSD so the dependencies will not be precalculated and installed automatically. To satisfy BackupPC dependencies, make sure a few ports are already installed.
Perl
For this installation, Perl and the BackupPC cgi script are set up with SUID privileges. If you would like to avoid this scenario, run the Apache webserver as the backuppc user instead of the default www user. You can edit this in /usr/local/etc/apache22/httpd.conf.
First, check to see if you have Perl installed. If you do, take note of which version it is so that you can rebuild the correction version.
- pkg_info | grep ^perl
Change Perl version as necessary.
- # cd /usr/ports/lang/perl5.10
- # make config

- # make install -DFORCE_PKG_REGISTER clean
Other Packages
- p5-Compress-Zlib
- p5-Archive-Zip
- p5-XML-RSS
- p5-File-RsyncP
- p5-libwww
- rsync
- samba-smbclient (for Windows backups)
- samba-nmblookup (for Windows backups)
- apache22
You can use the following as a template to figure out if you have a port currently installed:
- $ pkg_info | grep package_name
Install the package if it is not found.
whereis package_name is another way to find the location of a port.
- $ cd /usr/ports/*/package_name
- # make install clean
User and Group
We do not want to run BackupPC as a privileged user, so we will create its own user (backuppc) and group (backuppc), which can be individually locked down later.
Your user and group name can be different, but please note what it is and change the rest of the guide accordingly!
- # pw group add backuppc
- # pw user add backuppc -g backuppc -m
- # passwd backuppc
If you decide to remove this account for any reason, just use the rmuser <user> command.
Obtaining and Installing BackupPC
Now obtain the latest BackupPC archive, do a little prep work, and then install it.
- # mkdir ~/backuppc_tmp
Download the latest BackupPC tar.gz archive from here. Place this file in the ~/backuppc_tmp directory that was just created.
- # cd ~/backuppc_tmp
- # tar xvzf BackupPC-3.2.0.tar.gz
- # cd BackupPC-3.2.0
Now, we have everything in place and we can start configuring BackupPC.
I have provided everything you should need to keep a localized installation, but feel free to change these variables or even take a look at the full list by viewing perl configure.pl -help
- # perl configure.pl \
--batch \
--backuppc-user=backuppc \
--compress-level=5 \
--install-dir /home/backuppc \
--config-dir /home/backuppc/etc \
--log-dir /home/backuppc/log \
--data-dir /home/backuppc/data \
--hostname host.domain.tld \
--cgi-dir /home/backuppc/cgi-bin \
--html-dir /home/backuppc/htdocs \
--html-dir-url /bupc/htdocs - # chown -R backuppc:backuppc /home/backuppc
- # chmod u=wrxs,go=rx /home/backuppc/cgi-bin/BackupPC_Admin
- # chgrp www /home/backuppc/cgi-bin/BackupPC_Admin
- # chgrp www /home/backuppc/etc
- # chgrp www /home/backuppc/etc/config.pl
Starting / Stopping / Restarting BackupPC Daemon
Like any other server/daemon on FreeBSD, the easier way to facilitate start/stop/rrestarting services is via a script in /usr/local/etc/rc.d. I previously wrote one for this guide, but the newer versions of the BackupPC archives actually contain a valid script we can drop in.
Since we (most likely) want the BackupPC service to start when the machine boots, we need to add it to /etc/rc.conf.
- # cd ~/backuppc_tmp/BackupPC-3.2.0/init.d
- # cp freebsd-backuppc /usr/local/etc/rc.d/backuppc
- # chmod +x /usr/local/etc/rc.d/backuppc
- # echo 'backuppc_enable="YES"' >> /etc/rc.conf
- # /usr/local/etc/rc.d/backuppc start
- backuppc started
Setup BackupPC Web Interface
We need to create a htaccess password that Apache will use to authenticate users to the BackupPC web interface.
Be sure to use backuppc as the user when creating the htpasswd file. If you want to change it, use the name you would like but you must edit config.pl to reflect the change. Modify the $Conf{BackupPCUser} variable.
- # htpasswd -c /usr/local/etc/apache22/.htpasswd-backuppc backuppc
Now we need to configure Apache to publish the BackupPC web interface with the URL of http://<your hostname or IP>/bupc
- # cd /usr/ports/www/apache22
- # make install clean
- # kldload accf_http
- # echo 'accf_http_load="YES"' >> /etc/rc.conf
- # echo 'apache22_enable="YES"' >> /etc/rc.conf
- # vi /usr/local/etc/apache22/Includes/backuppc.conf
- Alias /bupc/htdocs /home/backuppc/htdocs
- ScriptAlias /bupc /home/backuppc/cgi-bin/BackupPC_Admin
- <Directory "/home/backuppc/cgi-bin">
- #SSLRequireSSL
- Options +ExecCGI
- AllowOverride AuthConfig
- Order allow,deny
- #Allow from 192.168.0 192.168.5.44
- Allow from all
- AuthName "BackupPC Admin"
- AuthType Basic
- AuthUserFile /usr/local/etc/apache22/.htpasswd-backuppc
- Require valid-user
- </Directory>
- <Directory "/home/backuppc/htdocs">
- Order allow,deny
- Allow from all
- </Directory>
- # apachectl restart
We also have to set which user(s) (from the password dialog) have access to the functions provided by the web interface. Without setting this in config.pl, we would be provided with a minimal set of administrative links upon logging in to the web interface.
- # su backuppc
- $ vim ~/etc/config.pl
- ... ... snip ... snip ... ...
- $Conf{CgiAdminUsers} = 'backuppc';
- ... ... snip ... snip ... ...
Now open up your web browser and go to http://<local ip or hostname>/bupc and you should see the htaccess password dialog box. Enter the authentication you configured earlier. You should eventually be greeted with a page similar to the following:
Edit config.pl
I, personally, like to run the BackupPC client process (on the client!) as the user bupc and I lock it down so it can execute rsync with root privileges. Since I do this, I usually change the default arguments for the command that gets piped to the client to initiate the backup.
- # su backuppc
- $ vi /home/backuppc/etc/config.pl
- ... ... snip ... snip ... ...
- $Conf{RsyncClientCmd} = '$sshPath -q -x -l bupc $host sudo $rsyncPath $argList+'
- ... ... snip ... snip ... ...
- $Conf{RsyncClientRestoreCmd} = '$sshPath -q -x -l bupc $host sudo $rsyncPath $argList+';
- ... ... snip ... snip ... ...
As I plan to mostly backup Linux/BSD boxes, I want to make rsync the default backup choice when I go to setup a new host.
- # su backuppc
- $ vi /home/backuppc/etc/config.pl
- ... ... snip ... snip ... ...
- $Conf{XferMethod} = 'rsync';
- ... ... snip ... snip ... ...
Changes to config.pl are instantaneous, as it is loaded on every page hit.
BackupPC Client Config
As mentioned earlier, I use a SSH authorized key authentication and sudo combination. I also have setup BackupPC to run rsync by default, as most of my hosts I plan to setup are *nix boxes. Now we just have to do a little prep work on our client.
We use SSH key authentication because BackupPC is unable to "login" traditionally by manually supplying a username and password. Instead, it will use the keys we will set up and only allow a specific username/host combination have direct access
Create bupc User
First, we need to create the user that BackupPC logs into the clients with. I plan to create the bupc user on the system we plan to backup.
I prefer to assign the /bin/sh shell until I get done with configuring the user...then I change it to a shell with no environment (/usr/sbin/nologin).
The following is for creating users on another FreeBSD box. You can use utilities such as adduser and useradd on Linux.
- # pw user add bupc -s /bin/sh -m
- # passwd bupc
Install sudo and Enable SSH
sudo is needed to run rsync with temporary root privileges
FreeBSD Example
- # cd /usr/ports/security/sudo
- # make install clean
- # rehash
- # echo 'sshd_enable="YES"' >> /etc/rc.conf
- # /etc/rc.d/sshd start
apt-get based system (Debian, Ubuntu, etc) Example
- # apt-get install ssh sudo
yum based system (RedHat, CentOS, Fedora, etc) Example
- # yum install ssh sudo
Now, all we have left is to edit the sudoers file so the bupc user can access rsync with root privileges (it will have Permission Denied errors for many file, otherwise).
- # visudo
- ... ... snip ... snip ... ...
- bupc ALL=(ALL) NOPASSWD: /usr/local/bin/rsync
Now a quick test to make sure that we can execute rsync with root privileges.
- # su bupc
- $ sudo rsync
- <some rsync output>
If you get prompted for a password, check your steps because something is wrong.
Setup Authorized Keys on Client
Now we need to do a few things to enable the BackupPC server to talk to clients without dealing with login prompts (when issuing commands on remote boxes via ssh). SSH Key-Authentication works perfectly for this. The server and client know are set up in such a way that they establish a connection based on an encrypted key file swapped between the two.
Client
- # su bupc
- $ ssh-keygen -t rsa
Server
- # su backuppc
- $ ssh-keygen -t rsa
- $ scp ~/.ssh/id_rsa.pub bupc@CLIENT_HOST:~/.ssh/BackupPC.pub
Client
In my case, my authorized keyfile is ~/.ssh/authorized_keys but yours could be different! Check out your sshd_config file. You can find it by running find / -name sshd_config
- # su bupc
- $ cd ~/.ssh
- $ ls
- id_rsa
- id_rsa.pub
- BackupPC.pub
- $ cat BackupPC.pub >> authorized_keys
Server
Now test that we can login to our client using authorized keys from the backuppc user on the BackupPC server.
- # su backuppc
- $ ssh bupc@CLIENT_HOST
... and we should be in with no password!
Finally, just test a remote sudo execution of rsync to make sure everything is working correctly.
- # su backuppc
- $ ssh bupc@CLIENT_HOST sudo rsync
Again, you should get get some generic rsync usage information and not be prompted for a password.
If all is well, you are ready to configure clients to be backed up. Visit the web interface we previously setup and start adding hosts!
Adding Clients
- Tags
- AI (1)
- ALIX (1)
- digitalfoo.net (2)
- embedded (6)
- FreeBSD (30)
- Java (1)
- Linux (26)
- misc (7)
- my projects (1)
- MySQL (2)
- NanoBSD (3)
- opensource (7)
- perl (1)
- PHP (3)
- programming (11)
- Python (1)
- security (4)
- Archives
- 2011
- February (1)
- March (1)
- June (1)
- July (1)
- August (1)
- 2010
- June (5)
- July (2)
- December (4)
- April (6)
- March (2)
- May (1)
- August (2)
- October (1)
- November (1)
- 2009
- August (7)
- July (8)
- April (4)
- May (4)
- December (2)
- June (1)
- September (1)
- November (4)
- October (1)
- Web Tools
- Index
- dig-shovel Live
- SQL Injection Encoder
- Links
-

