BackupPC
Introduction
Quote from the BackupPC website;
“BackupPC is a high-performance, enterprise-grade system for backing up Linux and WinXX PCs and laptops to a server’s disk. BackupPC is highly configurable and easy to install and maintain.”
This document contains notes on installing BackupPC to run on a Synology DiskStation, specifically the install was carried out on the DS212j model. This builds on other excellent documentation, referenced at the end of this document.
The document also describes installing lighttpd as the web-server to provide BackupPC’s admin interface. This seems a small over-head to increase security by running both BackupPC and lighttpd under the same system user. It also allows you to separately choose whether to expose your BackupPC admin panel to the Internet or not.
Please also note Synology‘s disclaimer in the ’Introduction’ section of SynologyDiskStation.
It is advisable to backup all your data on the device before attempting to modify it’s installed software.
In command-line examples, where the line starts with a $
sign, this indicates the command is run as a normal user, whilst
# indicates the command is run as the root user.
Installing BackupPC on Synology DiskStation
Preparation
- Install ipkg as described in SynologyDiskStation. It is also recommended that you install Screen and a lightweight editor you are familiar with. E.g. Vi, Mg or Nano. If you are unfamiliar with any of these editors, Nano is the quickest to get up-to-speed with.
Whenever you create a new shell, make sure `/opt/bin` is on the path. If it
is a root shell, you may need `/opt/sbin` on the path too. See
[SynologyDiskStation](SynologyDiskStation.html) for more information. If you
set the path before running [Screen][]
Check that
/opt/binin on the path for the backuppc user’s shell. If not, add it.$ whoami $ echo $PATH $ export PATH=/opt/bin:$PATHOptionally, install nano
# ipkg install nano
Create a backuppc user
Create a backuppc user using the DSM web interface. Add the backuppc user to the ‘users’ group. There is no need to give the backkuppc user any other privileges
T.B.D. - Home directories.
Open a shell as the backuppc user and create a directory for the backuppc database denying access to others
# su -s /bin/sh backuppc # mkdir -p /volume1/private/backuppc # chmod 700 /volume1/private/backuppc # chown backuppc.nobody /volume1/private/backuppc
Install lighttpd
Note that referenced line numbers are a guide and will vary as the file is edited.
Install lighttpd
# ipkg install lighttpdEdit
/opt/etc/lighttpd/lighttpd.conf
Enable the following modules by uncommenting the lines they are on:
- mod_access
- mod_accesslog
- mod_auth
- mod_cgi
Change the `server.document-root` to `/opt/local/www` on line 40
Change the `server.username` to `backuppc` on line 187
Remove the `lighttpd/index.html` element from the `index-file.names` array
and add `index.cgi` on line 48
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
"index.cgi" )
Locate the `CGI module` configuration section and uncomment the
`cgi.assign` lines (lines 222-224)
#### CGI module
cgi.assign = ( ".pl" => "/opt/bin/perl",
".cgi" => "/opt/bin/perl" )
Note that the port number is specified by the `server.port` setting on line
139. 8081 should be fine.
Locate the `auth module` configuration section (line 240) and uncomment
the following lines. Change the auth.backend to `htpasswd`. Make sure
you set the `auth.backend.htpasswd.userfile` option and not another, such
as `auth.backend.plain.userfile`
#### auth module
## read authentication.txt for more info
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/opt/etc/lighttpd/lighttpd-htpasswd.user"
## debugging
# 0 for off, 1 for 'auth-ok' messages, 2 for verbose debugging
auth.debug = 0
Add an `auth.require` section as follows:
auth.require = ( "/cgi-bin" =>
(
"method" => "basic",
"realm" => "BackupPC",
"require" => "valid-user"
)
)
Change the ownership of the log directory
# chown -R backuppc.nobody /opt/var/log/lighttpdCreate directory for the web server root
# mkdir /volume1/private/www # chown backuppc.nobody /volume1/private/wwwRestart lighttpd
# /opt/etc/init.d/S80lighttpd restart
Note. The Media Server package also uses lighttpd. It’s
start and stop script kills all instances of lighttpd, which will
include this one we are installing. Therefore, you will need to restart
this instance after Media Server stops it. Examine
/volume1/@appstore/MediaServer/scripts/S86synodms.sh for
the cause.
One workaround is to use a different name for this instance as follows:
# ln -s /opt/sbin/lighttpd /opt/sbin/backuppchttpd
Edit /opt/etc/init.d/S80lighttpd and change the
NAME of the executable on line 3 from lighttpd
to backuppchttpd.
Install BackupPC
Download BackupPC from http://sourceforge.net/projects/backuppc/files/backuppc/
Install perl and other required packages
# ipkg install perl optware-devel
You may need to uninstall the wget package as wget-ssl is installed with
optware-devel and conflicts with the wget package
# ipkg install wget-ssl
# ipkg remove wget
You may get errors, but hopefully, wget-ssl was downloaded. If not,
download it manually, then you can install the `.ipk` file directly. E.g.
# ipkg install wget-ssl_1.12-2_arm.ipk
# ipkg install libidn_1.25-1_arm.ipk
- Download
File::RsyncPsource from http://perlrsync.sourceforge.net/
There is already an older version of [Perl][] included with the
DiskStation. The OS is based on [Debian][] which uses Perl for important
operations which we do not want to interfere with. For that reason, it is
probably better to manually download and compile the few Perl packages we
require, rather than use [CPAN][]. See the
[Debian PerlFAQ][Debian_PerlFAQ] for more information.
Create a working directory and compile the source code
$ cd ~ $ tar -xf File-RsyncP-0.68.tar.gz $ cd File-RsyncP-0.68 $ perl Makefile.PL $ make LD=ld LINKTYPE=dynamic LDDFLAGS="-shared -O2" $ make LD=ld LINKTYPE=dynamic LDDFLAGS="-shared -O2" test
**Note:** the `-O2` switch contains the capital letter `O` and not a zero
Then install as root:
# cd ~backuppc/File-RsyncP-0.68/ # make LD=ld LINKTYPE=dynamic LDDFLAGS="-shared -O2" installDownload the perl File::Listing module from http://search.cpan.org/~gaas/File-Listing-6.04/lib/File/Listing.pm and install it in the same way as described above for the
File::RsyncPmodule
If you get a warning that the `HTTP::Date` module isn't installed,
similarly download, build and install it first from
<http://search.cpan.org/~gaas/HTTP-Date-6.02/lib/HTTP/Date.pm>
Install other BackupPC required packages:
# ipkg install perl-compress-zlib # ipkg install perl-archive-zipExtract the BackupPC archive file
T.B.D. User /volume1/homes/backuppc/src instead of /volume1/root
# cd /volume1/root # tar -xf BackupPC-3.2.1.tar.gz # cd BackupPC-3.2.1Configure BackupPC
# perl configure.pl --config-dir=/opt/etc/backuppc --log-dir=/opt/var/log/backuppc
Accept the default values for each item, except as noted below:
- Install directory: /opt/local/backuppc
- Data directory: /volume1/private/backuppc
- CGI bin directory: /opt/local/www/cgi-bin
- Apache image directory: /opt/local/www/BackupPC
- URL for image directory: /BackupPC
Enable the backuppc user to run the
pingcommand by installing and configuringsudo. If you wish to use an editor other than Vi, change theEDITORenvironment variable to path of your preferred editor. The example is for Mg# ipkg install sudo # export EDITOR=/opt/bin/mg # visudoModify the
User privilege specificationsection (line 72) by adding a line for backuppc as follows:## ## User privilege specification ## root ALL=(ALL) ALL backuppc ALL=(root) NOPASSWD: /bin/pingEdit
/opt/etc/backuppc/config.pl
Modify the `PingCmd` entry (line 1655) as follows:
$Conf{PingCmd} = '/opt/bin/sudo -u root $pingPath -c 1 -w 3 $host';
Run BackupPC and check the log for errors
# su -s /bin/sh backuppc $ /opt/local/backuppc/bin/BackupPC -d $ tail /opt/var/log/backuppc/LOG $ /opt/local/backuppc/bin/BackupPC_serverMesg status info $ /opt/local/backuppc/bin/BackupPC_serverMesg status jobs $ /opt/local/backuppc/bin/BackupPC_serverMesg status hostsCreate a symbolic link so that the
BackupPC_Adminscript is seen by lighttpd as having a.plextension. Also create an index.cgi version.# ln -s /opt/local/www/cgi-bin/BackupPC_Admin /opt/local/www/cgi-bin/BackupPC_Admin.pl # ln -s /opt/local/www/cgi-bin/BackupPC_Admin /opt/local/www/cgi-bin/index.cgiModify
/opt/etc/backuppc/config.pl- line 2019$Conf{CgiAdminUsers} = '*';Create a password file
# /usr/syno/apache/bin/htpasswd -c -m /opt/etc/lighttpd/lightttpd-htpasswd.user USERNAME
To add more users, use the same command, but without the `-c` (create
file) option.
BackupPC Startup Script
The initial folder that the BackupPC source was extracted too to
contains a sub-directory named init.d which contains
various versions of startup scripts for different operating systems. The
paths in these scripts have been set appropriately by the BackupPC
installation process. The original versions are stored in the
src sub-directory. Alternatively, you could use one of the
scripts published in some of the documents referenced at the end of this
document.
The instructions here modify the Debian version to suit our requirements. Copy the BackupPC modified version to the Synology DiskStation startup folder.
# cp /volume1/root/BackupPC-3.2.1/init.d/debian-backuppc /opt/etc/init.d/S82backuppc
# chmod 755 /opt/etc/init.d/S82backuppc
Then make the changes indicated by the following unified diff:
--- /volume1/root/BackupPC-3.2.1/init.d/debian-backuppc 2013-02-09 19:31:35.000000001 +0000
+++ /opt/etc/init.d/S82backuppc 2013-02-10 14:21:34.000000001 +0000
@@ -7,6 +7,8 @@
# Distributed with BackupPC version 3.2.1, released 24 Apr 2011.
#
+# Modified to run on Synlogoy DiskStation - Frank Dean - 10-Feb-2013
+
set -e
#
@@ -23,31 +25,38 @@
case "$1" in
start)
echo -n "Starting $NAME: "
- start-stop-daemon --start --pidfile $LOGDIR/BackupPC.pid \
- -c $USER --exec $BINDIR/$DAEMON -- -d
+ /opt/bin/su $USER -s /bin/sh -c "$BINDIR/$DAEMON -d"
echo "ok."
;;
stop)
echo -n "Stopping $NAME: "
- start-stop-daemon --stop --pidfile $LOGDIR/BackupPC.pid -u $USER \
- --oknodo --retry 30 -x /usr/bin/perl
+ /opt/bin/killall $DAEMON
echo "ok."
;;
restart)
echo -n "Restarting $NAME: "
- start-stop-daemon --stop --pidfile $LOGDIR/BackupPC.pid -u $USER \
- --oknodo --retry 30 -x /usr/bin/perl
- start-stop-daemon --start --pidfile $LOGDIR/BackupPC.pid \
- -c $USER --exec $BINDIR/$DAEMON -- -d
+ $0 stop
+ sleep 1
+ $0 start
echo "ok."
;;
+ status)
+ PID=`ps | /bin/grep "BackupPC -d" | /bin/grep /opt/bin/perl | /opt/bin/perl -lane 'print $F[0]'`
+ if [ -n "$PID" ]; then
+ echo "$NAME is running with PID $PID"
+ else
+ echo "$NAME is not running"
+ fi
+ ;;
reload|force-reload)
echo "Reloading $NAME configuration files"
- start-stop-daemon --stop --pidfile $LOGDIR/BackupPC.pid \
- --signal 1 -x /usr/bin/perl
+ PID=`ps | /bin/grep "BackupPC -d" | /bin/grep /opt/bin/perl | /opt/bin/perl -lane 'print $F[0]'`
+ if [ -n "$PID" ]; then
+ /opt/bin/kill -s 1 $PID
+ fi
;;
*)
- echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
+ echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac
After restarting the server, BackupPC should have been
restarted too. Navigate to the BackupPC URL which should be of the form
http://DISKSTATION_IP:8081/cgi-bin/BackupPC_Admin.pl or
simply http://DISKSTATION_IP:8081/cgi-bin/ should work
too.
DSM 5.1 Upgrade
This upgrade appears to have changed the location of some binaries. Attempting to start the BackupPC server, fails as follows:
# /opt/etc/init.d/S82backuppc start
Starting backuppc: 2014-11-15 11:31:40 $Conf{SmbClientPath} =
'/usr/syno/bin/smbclient' is not a valid executable program
Search for the new file locations:
# find /usr -name smbclient
/usr/bin/smbclient
# find /usr -name nmblookup
/usr/bin/nmblookup
The following changes are needed.
# vi /opt/etc/backuppc/config.pl
# : Amend $Conf{SmbClientPath} to /usr/bin/smbclient
# : Amend $Conf{NmbLookupPath} to /usr/bin/nmblookup
# : Amend $Conf{SshPath} to /usr/bin/ssh
Statistics
The Debian release of BackupPC maintains statistics relating to the pool size, displaying this information in a graph on the main page of the CGI application.
To see the graphs, you need to be logged in as a CGI admin user {CgiAdminUsers}
If you would like to capture statistics which are displayed in graphs on the status page of the cgi interface:
The section describes patching the upstream (BackupPC) release to apply the changes to include the graphs from the Debian release
Download BackupPC.patch and save it as
/opt/local/backuppc/BackupPC.patchDownload GeneralInfo.patch and save it as
/opt/local/backuppc/GeneralInfo.patchInstall the rrdtool package
# ipkg install rrdtoolMake the files that are to be patched writable
# cd /opt/local/backuppc # chmod u+w bin/BackupPC lib/BackupPC/CGI/GeneralInfo.pmApply the patches
# patch -b -p0 < BackupPC.patch # patch -b -p0 < GeneralInfo.pm.patch # chown backuppc.users bin/BackupPC lib/BackupPC/CGI/GeneralInfo.pm # chmod 444 bin/BackupPC.orig lib/BackupPC/CGI/GeneralInfo.pm.orig
Troubleshooting
To debug any issues in the backup process, run the BackupPC_dump program interactively from the command line (whilst the BackupPC server process is running). E.g.
#
See also the Troubleshooting document in the BackupPC wiki.
References
- http://backuppc.sourceforge.net/
- Running BackupPC server on DiskStation
- How to install the BackupPC application
- Install Backuppc with Lighttpd
- BackupPC with Lighttpd in DD-WRT
- CPAN Module-Build-0.4003
- http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModAuth
- http://wiki.centos.org/HowTos/BackupPC
– Frank Dean - 9 Feb 2013
– Frank Dean - 16 Oct 2005
Related Topics: DebianTips, LinuxHintsAndTips, SynologyDiskStation