How to install the BackupPC application

From QNAPedia
Revision as of 21:49, 31 October 2013 by Cvidal (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

BackupPC on QNAP

This page describes how to install BackupPC on a QNAP NAS (Originally targeted for a QNAP TS-439 Pro NAS, but with some modifications it should not be difficult to adapt it for other models). This article initially started to document a solution to create automatic backups (full/incremental) for an office with 4 windows PC clients.

It is known that BackupPC has been installed successfully at least on following QNAP models.

  • QNAP TS-210
  • QNAP TS-219P
  • QNAP TS-269 Pro
  • QNAP TS-412U
  • QNAP TS-419P+
  • QNAP TS-419P II
  • QNAP TS-439 Pro
  • QNAP TS-459 Pro
  • QNAP TS-459 Pro+
  • QNAP TS-659
  • QNAP TS-659 Pro II
  • QNAP TS 859 Pro  (Configuration: 12TB-Raid6)
  • QNAP TS 809 Pro  (Configuration: 12TB-Raid6)

Please add your model to the list above if it is running BackupPC and not listed over here.


Exemplary device QNAP TS-439 Pro NAS

The QNAP TS-439 Pro, an exemplary device from the list from above, inhibited for example the following features:

  • It had a relatively fast i386 compatible processor and in a test (in ct' magazine) it proved to have very fast cifs file sharing transfer speeds.
  • With a system booting and running from the internal disk-on-chip, the system would not be dependent on any of it's hot swappable and easy to remove/insert hard disks.
  • Four hot swappable bays would give enough future expansion possibilities.
  • With file compression set to zero the performance for backing up a windows machine with the rsync protocol is about 25 MB/s. The single core processor at the QNAP (An Intel Atom N270 processor, with hyperthreading) is running then at 100% load. When 3 computers, running a mixture of windows xp and 7, are backed up simultaneously the speed divides over the 3 computers, each transfering about 8 MB/s.

Webserver lighttpd with BackupPC

BackupPC was installed with webserver lighttpd. Although it has apache already installed, I considered that with a secondary installed webserver, it would not interfere with apache and apache would then be still 'free' to experiment with without interfering with BackupPC's webinterface.

Further system specifications

  • QNAP system software v3.4.2 Build0331
  • Storage: 3×2TB Hard Disk Western Digital RE4 WDC WD2003FYYS ( 2.0 TB 64MB 3.5IN S-ATA II 7200RPM), configured in Raid 5, giving a total of 3.6 TB of storage.

Please note that some hard disk models, like the Western Digital WD20EARS are not suitable for raid configuration. Read more about this: here

Installation tips

  • When copy/pasting commands from below into a shell into an editor like nano, make sure that single lines remain on one line. Nano may not recognize text wrap correctly. When your nano window is too narrow, commands which were originally on a single line, become fragmented which caused some unexpected behavior. Certainly not something what you want and easy to overlook with large blocks of text. Another fix is using the editor joe, especially with the file /share/MD0_DATA/custom/autorunmaster.sh, containing long lines
  • Although not relevant for this installation manual because the webserver lighttpd is being used rather than apache, at the QNAP TS-439 PRO the apache configuration settings are in: /etc/config/apache/apache.conf
  • When following this guide, installing of BackupPC should be finished in about 40 minutes.

Basic configuration

Enter at least following information on the QNAP web-based interface:

  • Factory default username and password is: admin
  • Server Name: BACKUPNAS (In my situation identical to IP-address 192.168.2.115)
  • User: admin
  • Password: (figure out yourself)
  • Network Services
    • Enable file service for Microsoft networking
    • Server Description: NAS Backup Server
    • Workgroup: (figure out yourself)
  • Raid 5 configuration with 3 x 2.0 TB hard disk WD2003FYYS

Presuming that your computer has ssh installed and configured and you have some affinity with what ssh is and how to use it, append your public key on your computer, which probably is in ~/.ssh/id_dsa.pub to the .ssh/authorized_keys file at the NAS. If the file authorized_keys is not present at the NAS, just copy:

scp ~/.ssh/id_dsa.pub admin@192.168.2.115:.ssh/authorized_keys

Otherwise do (See also: How_To_Set_Up_Authorized_Keys):

scp ~/.ssh/id_dsa.pub admin@192.168.2.115:.ssh/keytemp
ssh admin@192.168.2.115
cd .ssh
cat keytemp >> authorized_keys  
rm keytemp

Now you should be able to connect safely to the NAS. For a more convenient ssh connection, add a file with the filename "config" in your local .ssh directory and add the following lines:

Host nas
  HostName 192.168.2.115
  User admin

Now you should be able to connect with ssh with the following command:

ssh nas

The nas server can ask for a passphrase if you had one. In Ubuntu 9.04 there is an issue with the ssh-agent (or maybe it is the gnome-keyring), which should be able to store your passphrase, preventing the need to retype it each time it is being requested. The issue concerns that the passphrase is not being stored properly.

Step 1. Installation part from within the webbrowser

  • Use IP address in web browser or just type: http://BACKUPNAS
  • Download Optware QPKG (Applications->QPKG Plugins->Get QPKG->Optware IPKG (Itsy Package Management System) (Version 0.99.163)
  • Extract Optware_0.99.163_X86.qpkg in this zip archive
  • Install Optware QPKG by clicking on tab Installation->Browse to Optware_0.99.163_X86.qpkg -> Install
  • Enable Optware QPKG in tab QPKG Installer->Icon Optware->Enable->Close

Step 2. Installation part from within a terminal

Since we have setup ssh access properly, we can go on now from within a terminal. Log in with ssh to the TS-439Pro

ssh nas

Then check free memory space with

free

Check mounted partitions with

mount

Check free disk size with command:

df -h

(Notice the /dev/md0, which is in my case the mirrored raid device.) Since /opt is an symlink to /share/MD0_DATA/.qpkg/Optware/ the size of the /opt directory will be large enough for BackupPC (Here 1GB is advised: backuppc-lighttpd-dd-wrt)

Update ipkg and install the editor nano:

ipkg update
ipkg install nano

BackupPC dependencies

The documentation for BackupPC is available at http://backuppc.sourceforge.net/faq/BackupPC.html . We need to install BackupPC dependencies as mentioned on that page. Although most dependencies are installed while setting up Optware as explained above, we still need to Install following packages on which BackupPC further relies:

ipkg install perl samba2 tar rsync par2cmdline

Intermezzo - openssh

The default SSH client provided by QNAP (at /usr/bin/ssh) might not be very useful to use with BackupPC because of its limited set of options and security issues. Therefore we install the openssh package which should install the OpenSSH client at /opt/bin/ssh.

ipkg-opt install openssh

But it should be noted that this package will also install the OpenSSH server. This has to be disabled so that it does not conflict with the default SSH server provided. Therefore in /opt/etc/default/openssh, change

SSHD_ENABLE=yes

to

 SSHD_ENABLE=no

This should prevent OpenSSH server from starting at boot time.

Perl modules

Apart from the above utilities, BackupPC has the following perl modules as dependencies - Compress::Zlib, Archive::Zip, File::RsyncP and XML::RSS .

Compress::Zlib can be installed directly from the optware repository.

ipkg install perl-compress-zlib

Similarly, Archive::Zip can be installed directly from the optware repository.

ipkg install perl-archive-zip

Making Perl-File-RsyncP

  • TIP: On the TS-412U there is not enough space for the step as described. I had to move the /root/.cpan directory to /share/MD0_DATA/root/ and then link to that. After that all went smoothly.

Since the ipkg package perl-file-rsyncp is not available, we have to build this manually instead. Do the following:

ipkg install optware-devel

For CPAN module File::RsyncP, first we set up the build environment. This build environment will also be useful for installing other perl modules. Then we download the source from Perl CPAN and install it. Move to a directory with enough space. I cd'ed to /share/MD0_DATA/, created a directory installtemp there and worked from there:

mkdir /share/MD0_DATA/installtemp
cd /share/MD0_DATA/installtemp
wget http://search.cpan.org/CPAN/authors/id/C/CB/CBARRATT/File-RsyncP-0.70.tar.gz
tar zxvf File-RsyncP-0.70.tar.gz
cd File-RsyncP-0.70
perl Makefile.PL
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2"
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" test
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" install

Continue with installing other perl modules. Start the CPAN and when it asks, set all space directories to begin with: /share/MD0_DATA/installtemp.

perl -MCPAN -e shell
cpan>

Upgrade the CPAN module and restart it:

cpan> install Bundle::CPAN
cpan> reload cpan

CPAN configuration can be checked with the following command:

cpan> o conf

CPAN configuration can be modified with the following command:

cpan> o conf init

This will guide you through all settings and offer default settings which are fine. Again, make sure all space taking directories are set to begin with: /share/MD0_DATA/installtemp

Install the CPAN module File::Listing:

cpan> install File::Listing
cpan> exit

Our last CPAN module, XML::RSS, has a lot of dependencies (this can be seen clearly in here). Therefore, following the steps similar to those mentioned in http://www.livejournal.com/doc/server/lj.install.perl_setup.modules.html. In theory is is possible to install from CPAN directly. Please note that the XML::RSS module is necessary only if you plan to use BackupPC RSS feed. As I was not planning to use the RSS feed and the installation with the method below failed, I chose to ignore this dependency. The error it threw was: "no space left on device". If the memory problem is solved, the command to install the XML::RSS CPAN module is:

cpan> install XML::RSS
cpan> exit

Installing BackupPC

To run BackupPC, it is recommended that there is a user specifically for this program. We create the user backuppc for this:

/usr/local/bin/useradd -m -d /share/MD0_DATA/backuppc backuppc

This will create a home profile in a 'safe' area, a user backuppc. cd to the home folder from backuppc

cd /share/MD0_DATA/backuppc

Download from this directory the sources of BackupPC:

wget http://sourceforge.net/projects/backuppc/files/backuppc/3.2.1/BackupPC-3.2.1.tar.gz/download

Extract the archive, cd into it:

tar zxvf BackupPC-3.2.1.tar.gz
cd BackupPC-3.2.1

In this directory, execute the perl configure script and enter custom data as written down here (scroll down!):

perl configure.pl --config-dir=/opt/etc/backuppc --log-dir=/opt/var/log/backuppc

Is this a new installation or upgrade for BackupPC?  If this is
an upgrade please tell me the full path of the existing BackupPC
configuration file (eg: /etc/BackupPC/config.pl).  Otherwise, just
hit return.

--> Full path to existing main config.pl []? 

I found the following locations for these programs:

    bzip2        => /bin/bzip2
    cat          => /bin/cat
    df           => /bin/df
    gtar/tar     => /bin/tar
    gzip         => /bin/gzip
    hostname     => /bin/hostname
    nmblookup    => /opt/bin/nmblookup
    par2         => /opt/bin/par2
    perl         => /opt/bin/perl
    ping         => /bin/ping
    rsync        => /usr/bin/rsync
    sendmail     => /usr/sbin/sendmail
    smbclient    => /opt/bin/smbclient
    split        => /usr/bin/split
    ssh/ssh2     => /usr/bin/ssh

--> Are these paths correct? [y]? 

Please tell me the hostname of the machine that BackupPC will run on.

--> BackupPC will run on host [BACKUPNAS]? 

BackupPC should run as a dedicated user with limited privileges.  You
need to create a user.  This user will need read/write permission on
the main data directory and read/execute permission on the install
directory (these directories will be setup shortly).

The primary group for this user should also be chosen carefully.
The data directories and files will have group read permission,
so group members can access backup files.

--> BackupPC should run as user [backuppc]? 

Please specify an install directory for BackupPC.  This is where the
BackupPC scripts, library and documentation will be installed.

--> Install directory (full path) [/usr/local/BackupPC]? /opt/local/backuppc

Please specify a data directory for BackupPC.  This is where all the
PC backup data is stored.  This file system needs to be big enough to
accommodate all the PCs you expect to backup (eg: at least several GB
per machine).

--> Data directory (full path) [/data/BackupPC]? /share/MD0_DATA/BackupPC 

BackupPC can compress pool files, providing around a 40% reduction in pool
size (your mileage may vary). Specify the compression level (0 turns
off compression, and 1 to 9 represent good/fastest to best/slowest).
The recommended values are 0 (off) or 3 (reasonable compression and speed).
Increasing the compression level to 5 will use around 20% more cpu time
and give perhaps 2-3% more compression.

--> Compression level [3]? 

BackupPC has a powerful CGI perl interface that runs under Apache.
A single executable needs to be installed in a cgi-bin directory.
This executable needs to run as set-uid backuppc, or
it can be run under mod_perl with Apache running as user backuppc.

Leave this path empty if you don't want to install the CGI interface.

--> CGI bin directory (full path) []? /share/MD0_DATA/www/cgi-bin

BackupPC's CGI script needs to display various PNG/GIF images that
should be stored where Apache can serve them.  They should be placed
somewhere under Apache's DocumentRoot.  BackupPC also needs to know
the URL to access these images.  Example:

    Apache image directory:  /var/www/htdocs/BackupPC
    URL for image directory: /BackupPC

The URL for the image directory should start with a slash.

--> Apache image directory (full path) []? /share/MD0_DATA/www/BackupPC
--> URL for image directory (omit http://host; starts with '/') []? /BackupPC

Ok, we're about to:

  - install the binaries, lib and docs in /opt/local/backuppc,
  - create the data directory /share/MD0_DATA/BackupPC,
  - create/update the config.pl file /opt/etc/backuppc/config.pl,
  - optionally install the cgi-bin interface.

--> Do you want to continue? [y]? 
Created /opt/local/backuppc/bin
Created /opt/local/backuppc/doc
Created /opt/local/backuppc/lib/BackupPC/CGI
Created /opt/local/backuppc/lib/BackupPC/Config
Created /opt/local/backuppc/lib/BackupPC/Lang
Created /opt/local/backuppc/lib/BackupPC/Storage
Created /opt/local/backuppc/lib/BackupPC/Xfer
Created /opt/local/backuppc/lib/BackupPC/Zip
Created /opt/local/backuppc/lib/Net/FTP
Created /share/MD0_DATA/www/BackupPC
Created /share/MD0_DATA/BackupPC
Created /share/MD0_DATA/BackupPC/pool
Created /share/MD0_DATA/BackupPC/cpool
Created /share/MD0_DATA/BackupPC/pc
Created /share/MD0_DATA/BackupPC/trash
Created /opt/etc/backuppc
Created /opt/var/log/backuppc
Installing binaries in /opt/local/backuppc/bin
Installing library in /opt/local/backuppc/lib
Installing images in /share/MD0_DATA/www/BackupPC
Making init.d scripts
Making Apache configuration file for suid-perl
Installing docs in /opt/local/backuppc/doc
Installing config.pl and hosts in /opt/etc/backuppc
BusyBox v1.01 (2010.03.14-18:22+0000) multi-call binary

Usage: ping [OPTION]... host

Send ICMP ECHO_REQUEST packets to network hosts.

Options:
	-c COUNT	Send only COUNT pings.
	-s SIZE		Send SIZE data bytes in packets (default=56).
	-q		Quiet mode, only displays output at start
			and when finished.

Installing cgi script BackupPC_Admin in /share/MD0_DATA/www/cgi-bin

Ok, it looks like we are finished.  There are several more things you
will need to do:

  - Browse through the config file, /opt/etc/backuppc/config.pl,
    and make sure all the settings are correct.  In particular,
    you will need to set $Conf{CgiAdminUsers} so you have
    administration privileges in the CGI interface.

  - Edit the list of hosts to backup in /opt/etc/backuppc/hosts.

  - Read the documentation in /opt/local/backuppc/doc/BackupPC.html.
    Please pay special attention to the security section.

  - Verify that the CGI script BackupPC_Admin runs correctly.  You might
    need to change the permissions or group ownership of BackupPC_Admin.
    If this is an upgrade and you are using mod_perl, you will need
    to restart Apache.  Otherwise it will have stale code.

  - BackupPC should be ready to start.  Don't forget to run it
    as user backuppc!  The installation also contains an
    init.d/backuppc script that can be copied to /etc/init.d
    so that BackupPC can auto-start on boot.  This will also enable
    administrative users to start the server from the CGI interface.
    See init.d/README.

Enjoy!

Ping command

Without setting proper rights to the ping command, BackupPC will not be able to issue a ping and check whether a client is alive. To set the proper rights do:

ipkg install sudo

Instead of directly editing /opt/etc/sudoers, use the command visudo to edit this file in a safe manner:

visudo

You should add the /bin/ping command to the admin user. Search for following text:

##                                                                                               
## User privilege specification                                                         
##                                                                                               
root ALL=(ALL) ALL

Add below the line beginning with root ALL= the following:

backuppc ALL=(admin) NOPASSWD: /bin/ping

Then change the line in the "/opt/etc/backuppc/config.pl" file to

$Conf{PingCmd} = '/opt/bin/sudo -u admin $pingPath -c 1 -w 3 $host';

With these arguments it should send one ping with a maximum waiting time of 3 seconds before deciding whether a host did not reply. Depnding on which ping version is being used, the arguments may differ slightly. Some computers use -t or -W as argument for timeout. So when in doubt check the arguments.

Intermezzo - Managing Users

To find out the currently logged on user:

whoami

Initial BackupPC test

On the TS-412U you will need to add the user backuppc to the group administrators and change the permissions in /opt/var/log as below:

administrators:x:0:admin,backuppc
chmod 775 /opt/var/log/backuppc


You should now be able to test the installation of BackupPC. Start BackupPC manually with:

su backuppc
/opt/local/backuppc/bin/BackupPC -d

Then test status:

ps ax | grep "BackupPC -d" | grep perl

If BackupPC is running, you should see some output. In case of the following error message

No language setting
BackupPC::Lib->new failed

a possible cause is that the previously existing /opt/etc/backuppc/config.pl specified in the course of the installation process is not loaded. If the access rights to the file are okay, check whether the variable $useFHS is set to 1 at:

/opt/local/backuppc/lib/BackupPC/Lib.pm:87:   my $useFHS = 1;

It not, the config.pl is assumed to be located relative to $topDir.

backuppc {start|restart|stop|status}script

If you are not working as admin, return to user admin:

su admin

Copy the following lines to the file /opt/sbin/backuppc (user rights should be admin):

#!/bin/sh

# PROVIDE: backuppc
# REQUIRE: DAEMON
# BEFORE:  LOGIN

name="backuppc"
USER="backuppc"
MYSELF=$0

case "$1" in
start)
    /opt/bin/su backuppc -s /bin/sh -c '/opt/local/backuppc/bin/BackupPC -d'
    echo "${name} started"
    ;;
restart)
    if [ "`ps ax | grep "BackupPC -d" | grep perl`" != "" ] ; then
        "$MYSELF" stop
        sleep 1
    fi
    "$MYSELF" start
    ;;
stop)
    killall BackupPC
    echo "${name} stopped"
    ;;
status)
    if [ "`ps ax | grep "BackupPC -d" | grep perl`" = "" ] ; then
        echo "${name} not running"
    else
        echo "${name} running"
    fi
    ;;
*)
    printf "Usage: %q {start|stop|restart|status}\n" "$0" >&2
    exit 1
    ;;
esac

exit 0

Then make backuppc executable:

chmod u+x /opt/sbin/backuppc

Now you can find running status with:

/opt/sbin/backuppc status

Start backuppc with

/opt/sbin/backuppc start

Stop backuppc with

/opt/sbin/backuppc stop

Restart backuppc with

/opt/sbin/backuppc restart

Intermezzo - autorun.sh

IMPORTANT: If your device is on firmware 3.8.3 or higher you will want to follow this tutorial here that utilizes QPKG to run autorun.sh as mounting ramblock method below is no longer the best way to do it. After your done with the steps you may pick up below where it says "Restart your NAS and check if BackupPC is running" and after it has restarted you may proceed with installing light web server.

autorun.sh contents should look like this when done installing backuppc server and light web server. autorun.sh should be located in /share/MD0_DATA/.qpkg/autorun/ . You will need to create the autorun directory and make sure autorun.sh is executible.

#!/bin/sh
"/opt/sbin/backuppc" start
/opt/etc/init.d/S80lighttpd
exit 0

Depending on where you write files on the NAS, please note that configuration settings, files and directories may be installed on a RAM-disk. Anything added there will disappear at reboot. A simple way to check a directory you are unsure about is to run df <DIR> . That command returns information about what file system the given directory is located on. (If the output is empty then it is on the RAM-disk). The pwd command gives you your current directory. Because default config files are reset after each startup (see here:), QNAP supplies a method to execute a bash script at each startup to perform specific initialization tasks. The file autorun.sh, which should be stored on the internal disk-on-chip, is executed at each startup. Editing this file can be done with mounting the config ramblock first, create/editing its contents, (make sure it is executable) and unmounting the device when finished. This ramblock is device/model dependent. You can use the following command to find your model:

/sbin/getcfg System "Internal Model"

This will give for example a string like: TS-459. If anyone wants to make a universal script in order to retrieve the correct ramblock, I think getcfg in combination with using a table to find it will be the preferred method:

QNAP Model ramblock Mount command . . . . . . . . . . . . . . . . . . . . . Comment

TS-210
TS-412U

/dev/mtdblock5
mount -t ext2 /dev/mtdblock5 /tmp/config

TS-439Pro /dev/sdx6
mount -t ext2 /dev/sdx6 /tmp/config
Inside is a 128 MB Apacer ATA Disk Module
44 pin, prod. nr. t9aj01, accessible and
replaceable via the front, without voiding your warranty.
TS-459Pro
TS-459Pro+
/dev/sdx6
mount -t ext2 /dev/sdx6 /tmp/config
Inside is a 512 MB Apacer USB Disk Module
8 pin header, prod. nr. 79700-m512-028-RS(MF34011),
resembles the Apacer AP-UM512MC10CG,
accessible and replaceable via the front, without
voiding your warranty.


Create/Edit /tmp/config/autorun.sh

nano /tmp/config/autorun.sh

From here you could add code which will be executed during the boot process. See below for an implementation of this.

When finished, ensure that /tmp/config/autorun.sh is executable:

chmod 755 /tmp/config/autorun.sh

IMPORTANT: Unmount the mounted flash partition:

umount /tmp/config

Alternatively to find the unmounted ramblock (including all other devices):

/sbin/fdisk -l

On a QNAP TS-439Pro and 459 Pro, this results for example in six devices: /dev/sdx1 .. /dev/sdx6 This will not exactly reveal which of the six devices should be used.

Add startup script to /opt/etc/init.d

For more standardized behaviour, we create a startup (Do not try to start BackupPC from /tmp/config/autorun.sh, because Optware is not correctly setup yet at that moment) script /opt/etc/init.d/S81backuppc :

nano /opt/etc/init.d/S81backuppc

Copy/paste the code below:

#!/bin/sh
"/opt/sbin/backuppc" start
exit 0

Then make it executable:

chmod u+x /opt/etc/init.d/S81backuppc

Automatic startup of BackupPC when system boots

To start BackupPC automatically each time the system boots, basically create or modify the file autorun.sh . However, simply adding the command /opt/etc/init.d/S81backuppc does not work well, because autorun.sh is started early in the bootprocess and Optware is not properly configured yet at that moment. A working two-stage-solution is to first configure Optware and then start S81backuppc . This is done with the autorun.sh which starts another script, autorunmaster.sh which resides in /share/MD0_DATA/custom/ :

Stage 1 - Mount the internal disk-on-chip

QNAP Model Command . . . . . . . . . . . . . . . . . . . . . . . . . . .

TS-210
TS-212
TS-412U

mount -t ext2 /dev/mtdblock5 /tmp/config
TS-439Pro
TS-459Pro
TS-459Pro+
mount -t ext2 /dev/sdx6 /tmp/config


Stage 1 - Create or modify /tmp/config/autorun.sh

nano /tmp/config/autorun.sh

Stage 1 - Add the following code:

#!/bin/sh
# To solve a problem with scripts which depend on Optware and
# therefore cannot be executed because autorun.sh is executed
# early in the bootprocess and Optware is still uninitialized
# we follow the ideas of http://forum.qnap.com/viewtopic.php?f=85&t=18977&start=0

# start a single script
/share/MD0_DATA/custom/autorunmaster.sh
# finish

Stage 1 - Ensure that /tmp/config/autorun.sh is executable by root:

chmod +x /tmp/config/autorun.sh

Stage 1 - IMPORTANT: Unmount the mounted flash partition:

umount /tmp/config

Stage 2 - Create the directory /share/MD0_DATA/custom/

mkdir /share/MD0_DATA/custom/

Stage 2 - create the file autorunmaster.sh

nano /share/MD0_DATA/custom/autorunmaster.sh

Stage 2 - Copy/paste following text into it.

#!/bin/sh
# Scriptname autorunmaster.sh
# This script is called by autorun.sh which is executed at every startup of the system
# (See: http://forum.qnap.com/phpbb2/viewtopic.php?t=1168)
# You will find the reboot log at: /share/..._DATA/custom/log/autorun.log
# Define Target HDA_DATA or MD0_DATA

export TARG=MD0_DATA
# FIRST start Optware and delete the /etc/rcS.d/QS100...sh
# echo `date` >> /share/$TARG/custom/log/autorun.log

echo "start autorunmaster to begin with Optware" >> /share/$TARG/custom/log/autorun.log
/etc/init.d/Optware.sh start
rm -f /etc/rcS.d/QS100Optware
# echo "Optware started" >> /share/$TARG/custom/log/autorun.log

# echo "Now launching custom scripts which need Optware initialization first" >> /share/$TARG/custom/log/autorun.log
#
#echo "starting BackupPC script " >> /share/$TARG/custom/log/autorun.log
/opt/etc/init.d/S81backuppc

Stage 2 - Ensure that /share/MD0_DATA/custom/autorunmaster.sh is executable by root:

chmod +x /share/MD0_DATA/custom/autorunmaster.sh

Stage 2 - create a log directory in which autorunmaster.sh can add information:

mkdir /share/MD0_DATA/custom/log

Restart your NAS and check if BackupPC is running:

/opt/sbin/backuppc restart
/opt/sbin/backuppc status

It should say: backuppc running

lighttpd installation and configuration

Install lighttpd from the Optware package:

ipkg update
ipkg install lighttpd

The configuration file lighttpd.conf is at /opt/etc/lighttpd/lighttpd.conf (Symbolic linked to /share/MD0_DATA/.qpkg/Optware/etc/lighttpd) . (For more easy setup, maybe one could write a specific file in the directory /opt/etc/lighttpd/conf.d/backuppc.conf which holds all custom settings for backuppc) For now edit backuppc.conf:

nano /opt/etc/lighttpd/lighttpd.conf

In the ”## modules to load” section uncomment the following lines:

## modules to load
server.modules              = (
            "mod_access",
            "mod_cgi",
            "mod_acesslog" )

Then change:

server.document-root        = "/share/MD0_DATA/www/"

BackupPC is installed as user backuppc. The easiest way for the webserver to being able to execute the BackupPC webinterface is to start lighttpd as well as user backuppc. Since lighttpd is exclusively used for BackupPC this seems reasonable:

## change uid to <uid> (default: don't care)
#server.username            = "nobody"
server.username            = "backuppc"

## change uid to <uid> (default: don't care)
#server.groupname           = "nobody"
server.groupname           = "backuppc"

Under $HTTP["url"] =~ "\.pdf$" { ... } add the following:

## >>>>>>>>>>>> ADDED FOR BACKUPPC
$HTTP["url"] =~ "/cgi-bin/" {
    cgi.assign = ( ".pl" => "/opt/bin/perl" )
}

Remove the "lighttpd/index.html" from the following:

# files to check for if .../ is requested
index-file.names            = ( "index.php", "index.html",
                                "index.htm", "default.htm"
                              )

Give ownership of lighttpd log dir to user backuppc so it can read and write to it:

chown -R backuppc:backuppc /opt/var/log/lighttpd

You can now save your lighttpd configuration file. Restart lighttpd web server:

/opt/etc/init.d/S80lighttpd restart

Check if lighttpd is running:

ps ax | grep lighttpd | grep conf

You should see some output if it is running.

To start lighttpd automatically when the system boots, add the following lines to the file /share/MD0_DATA/custom/autorunmaster.sh just below the entry for BackupPC

#echo "starting lighttpd" >> /share/$TARG/custom/log/autorun.log
/opt/etc/init.d/S80lighttpd

Restart your NAS and check whether lighttpd is running.

BackupPC webinterface

Enable administrative rights in the webinterface for every user:

nano /opt/etc/backuppc/config.pl

Change

$Conf{CgiAdminUsers}     = '';

into

$Conf{CgiAdminUsers}     = '*';

When lighttpd is configured as written above, it expects a perl script to have a .pl extension. Therefore create a symbolic link to the BackupPC perl script with that extension:

ln -s /share/MD0_DATA/www/cgi-bin/BackupPC_Admin /share/MD0_DATA/www/cgi-bin/BackupPC_Admin.pl

The BackupPC webinterface is now ready. A webpage should appear if you browse to: http://192.168.2.115:8081/cgi-bin/BackupPC_Admin.pl

NOTE: If you have broken images (e.g. logo.gif) you will need to copy the images directory or create symbolic links to the /images directory. Substitute BackupPC-3.2.1 for your correct directory.

ln -s /share/MD0_DATA/backuppc/BackupPC-3.2.1/images /share/MD0_DATA/www/images

You also need to edit config.pl typically located in /share/MD0_DATA/.qpkg/Optware/etc/backuppc/. Search for $Conf{CgiImageDirURL} = '/BackupPC' and change it to $Conf{CgiImageDirURL} = '/images';

NOTE: If css seems to be broke you will need to create a file in the images directory called BackupPC_stnd.css and add the following code to the css file then save it. Restart light web server and backup pc admin page should look great now.

body {
    background-color: #FFFFFF;
    font-family: tahoma,arial,sans-serif,helvetica;
    font-size: 10pt;
    height: 100%;
    margin: 2px 5px 0 2px;
}
table {
    border-collapse: collapse;
    color: #000000;
    padding: 2px;
}
h1 {
    color: #000000;
    font-family: Trebuchet MS,Trebuchet,tahoma,arial,sans-serif,helvetica;
    font-size: 16pt;
}
h2 {
    color: #000000;
    font-family: Trebuchet MS,Trebuchet,tahoma,arial,sans-serif,helvetica;
    font-size: 12pt;
}
a {
    color: #3333FF;
    font-family: tahoma,arial,sans-serif,helvetica;
}
dt {
    color: #3333FF;
}
a:hover {
    color: #CC0000;
    text-decoration: none;
}
a.NavCurrent {
    font-weight: bold;
}
a.navbar {
    padding-left: 5px;
    padding-right: 5px;
}
.h1 {
    background-color: #95B8DB;
    color: #000000;
    font-family: Trebuchet MS,Trebuchet,tahoma,arial,sans-serif,helvetica;
    font-size: 16pt;
    font-weight: bold;
    margin-bottom: 5px;
    padding: 3px 3px 3px 6px;
}
.h2 {
    background-color: #EEEEEE;
    color: #000000;
    font-family: Trebuchet MS,Trebuchet,tahoma,arial,sans-serif,helvetica;
    font-size: 12pt;
    font-weight: bold;
    margin-bottom: 1px;
    margin-top: 3px;
    padding: 3px 3px 3px 6px;
}
.tableStnd {
    font-size: 10pt;
}
.tableheader {
    background-color: #EEEEEE;
    font-size: 10pt;
    font-weight: bold;
}
table.sortable a.sortheader {
    background-color: #EEEEEE;
    display: block;
    font-weight: bold;
    text-decoration: none;
}
.border {
    font-size: 10pt;
}
.editHeader {
    background-color: #95B8DB;
    color: #000000;
    font-family: arial,sans-serif;
    font-size: 12pt;
    font-weight: bold;
}
.editTabSel {
    background-color: #95B8DB;
    color: #000000;
    font-family: arial,sans-serif;
    font-size: 14pt;
    font-weight: bold;
    margin-bottom: 5px;
    padding: 3px 3px 3px 6px;
}
.editTabNoSel {
    color: #000000;
    font-family: arial,sans-serif;
    font-size: 14pt;
    font-weight: bold;
    margin-bottom: 5px;
    padding: 3px 3px 3px 6px;
}
.editSaveButton {
    color: #C0C0C0;
    font-size: 14pt;
    font-weight: bold;
}
.editError {
    color: #FF0000;
    font-weight: bold;
}
.editComment {
    font-size: 10pt;
}
.editTextInput {
    font-family: courier;
    font-size: 10pt;
}
.fviewheader {
    background-color: #999999;
    color: #FFFFFF;
    font-size: 9pt;
    font-weight: bold;
}
.fviewborder {
    background-color: #EEEEEE;
    border-bottom: 1px solid #000000;
    border-left: 1px solid #666666;
    border-right: 1px solid #666666;
    font-size: 9pt;
}
.fviewon {
    background-color: #CCCCCC;
}
.fviewoff {
    background-color: #FFFFFF;
}
.fview {
    font-family: tahoma,arial,sans-serif,helvetica;
    font-size: 9pt;
    line-height: 15px;
    text-decoration: none;
}
.fviewbold {
    font-family: tahoma,arial,sans-serif,helvetica;
    font-size: 9pt;
    font-weight: bold;
    line-height: 15px;
    text-decoration: none;
}
.histView {
    background-color: #EEEEEE;
    border-bottom: 1px solid #000000;
    border-left: 1px solid #000000;
    font-size: 10pt;
}
.histViewMis {
    background-color: #FFDDDD;
    border-bottom: 1px solid #000000;
    border-left: 1px solid #000000;
}
div.NavMenu {
    background-color: #EEEEEE;
    font-size: 9pt;
    margin: 0;
    width: 18%;
}
div.NavMenu a {
    display: block;
    font-family: arial,sans-serif;
    font-size: 9pt;
    margin-left: 8px;
    padding: 2px;
}
div.NavTitle {
    background-color: #95B8DB;
    color: #000000;
    font-family: Trebuchet MS,Trebuchet,tahoma,arial,sans-serif,helvetica;
    font-size: 12pt;
    font-weight: bold;
    margin-bottom: 2px;
    padding-left: 10px;
}
#Content {
    float: right;
    left: 20%;
    position: absolute;
    right: 10px;
    top: 10px;
    width: 79%;
}

Step 3. Configuring BackupPC

BackupPC has a tremendous amount of settings, to get more information just read the <a href="http://backuppc.sourceforge.net/faq/BackupPC.html">documentation</a> carefully. Happily the default main settings configuration file (/opt/etc/backuppc/config.pl) should be set correctly for the most part already.

Most settings can be done webbased. Browse to:

http://192.168.2.115:8081/cgi-bin/BackupPC_Admin.pl

Check following steps:

Edit Host-> Add Host

Enter the IP-address of the client pc in the host field and type root in the user field:

<Host: IP-address>  <dhcp: unchecked> <user: root> <moreUsers: leave empty>

Then select this computer, Edit config:

XFerMethod: rsyncd
 Further settings:
 RsyncShareName: docs
 RsyncdUserName: AdminBackupPC
 RsyncdPasswd: (Figure out yourself)

Following lines are optional but helps get rid of transfer errors in your log files while backing up in addition to not backing up some unnecessary temp and cache files: (Please note: If there are more computers on the network which should be backed up and share the same exclusion list, it may be easier to configure this as global setting)

BackupFilesExclude->enter for key: *

then in this group, create an entry for each item:

*parent.lock
*UsrClass.dat*
*Firefox*Cache*
*Local Settings/Temp*
NTUSER.DAT
ntuser.dat.LOG

BackupPC should be ready to backup <IP-address>, but we need to prepare computer1 with a client rsyncd now that you've edited the hosts file, you need to restart the BackupPC service:

/opt/sbin/backuppc restart
Change Schedule -> BlackoutGoodCnt -> -1

And:

Change Schedule -> BlackoutPeriods enable Override

Step 3.1 Configuring e-mail notifications

QNAP sends e-mail via "ssmtp". The program '/usr/sbin/sendmail' is actually a link to 'ssmtp'. Unfortunately, 'sendmail' and 'ssmtp' have different argument lists. This can be solved using the following script (you can create it in '/opt/local/bin'):

#!/bin/bash
#

from=""
while [ "$#" -gt 0 ]; do
	case "$1" in
	-f)
		shift
		from="$1"
		;;
	*)
		;;
	esac
	shift
done

msg=$(cat)
to=$(echo "$msg" | /opt/bin/head -1 | grep "^To: ")
to=${to#To: }

( echo "From: $from" ; echo "$msg" ) | /usr/sbin/ssmtp $to

Make it executable with:

chmod 755 /opt/local/bin/mymail

and change the parameter "SendmailPath" in '/opt/etc/backuppc/config.pl' so that it points to '/opt/local/bin/mymail'. This can also be done via the Web interface in the E-mail configuration panel. You can test the e-mail function with:

su - backuppc -c "/opt/local/backuppc/bin/BackupPC_sendEmail -u your@email.adress

Step 4. Configuring a Host for Backup

When using Microsoft Windows, use either option 1 or option 2 from below to install and configure rsyncd.

Option 1 - installing using the rsyncd from BackupPC

Download rsyncd (cygwin-rsyncd-2.6.8_0.zip) for Windows from the BackupPC website (hosted by SourceForge). Unzip the files to c:\rsyncd

Edit the rsyncd.conf file and edit the docs section to your liking, such as:

[docs]path = c:/Documents and Settings
comment = Documents and Settings
strict modes = false
auth users = USERNAME #this USERNAME comes from the computer1.pl file that we edited before
secrets file = c:/rsyncd/rsyncd.secrets
read only = true
list = false

Now edit rsyncd.secrets and change UUU:PPP to the username and password that we entered above in the computer1.pl file:

USERNAME:PASSWORD

Edit the service.bat file (Instead of notepad, you should use an editor which can handle the line breaks, like wordpad, gvim, notepad++, etc… )

You only need to edit this file if you need to remove the “rem ” from the last three lines to allow it to punch through the windows firewall.

So after editing it, run service.bat to set up rsyncd service. This method does not work on windows 7. Instead enter the following at a command console:

cd \rsyncd
cygrunsrv.exe -I rsyncd -e CYGWIN=nontsec -p c:/rsyncd/rsync.exe -a ” –config=c:/rsyncd/rsyncd.conf –daemon – -no-detach”

Check the service with the following command and search for rsyncd. It should state started:

services.msc

It is necessary to open tcp port 873 at the firewall to allow trafic from the rsyncd daemon. In the firewall configure the following exception:

  • Name: rsyncd
  • Type: TCP
  • Port: 873

Option 2 - installing rsyncd using cwRsync

Go to http://rsync.samba.org/download.html

Go to "cwRsync" is a packaging of rsync for MS Windows.

Which will take you to: http://sourceforge.net/projects/sereds/files/cwRsync/4.0.6/

Download the cwRsyncServer_4.0.6_Installer.zip file (or newer) and install.

Troubleshooting

To check whether a certain computer can be found on the network, type:

perl -e 'print(gethostbyname("myhost") ? "ok\n" : "not found\n")'

Enter for myhost the hostname of that certain computer.

perl module File::Listing

If an error occurs with a missing perl module File::Listing, compile this:

cd /share/MD0_DATA/installtemp
wget http://www.auditeon.com/xyz/File-List-0.3.1.tar.gz
tar zxvf File-List-0.3.1.tar.gz
cd List
perl Makefile.PL
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2"
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" test
make LD=ld LINKTYPE=dynamic LDDLFLAGS="-shared -O2" install
ln -s /opt/lib/perl5/site_perl/5.10.0/File/List.pm /opt/lib/perl5/site_perl/5.10.0/Listing.pm


Current issues

Helpful links