Archive
Windows backup with BackupPC
In my last post I explained how BackupPC is installed on a fresh openSuse 13.1 machine. Now it is time to setup a backup of a windows machine.
Defining hosts
Each host that has to be backuped has to be defined in the /etc/BackupPC/hosts file. As I will be using DHCP you have to put there the real host name (I will be using myhost). Add this line to the end of the hosts file:
myhost 1
The first parameter is the host name, and the second is the using DHCP flag.
To be sure this will work issue the following command on the prompt:
nmblookup -A X.Y.Z.W
Where X.Y.Z.W is the current IP of the myhost. You should get some lines like this back:
Looking up status of X.Y.Z.W
MYHOST - B
MYHOST - B
To define specific backup options for that host create a file named hostname.pl in /etc/BackupPC/pc/. In my case it is /etc/BackupPC/pc/myhost.pl . The content of the file is the following:
$Conf{XferMethod} = 'rsyncd';
$Conf{RsyncdUserName} = 'backuppc';
$Conf{RsyncdPasswd} = 'backuppc';
$Conf{RsyncShareName} = 'backup_folder';
I will be using rsyncd transfer method because it is the fastest one. The username/password I will configure on the myhost will be backuppc/backuppc and I will setup a share named backup_folder there.
We are still not done because BackupPC doesn’t know how to find the host by it’s name. It has to scan a IP range to find it first. To setup the IP range open the /etc/BackupPC/config.pl file and find the $Conf{DHCPAddressRanges} parameter. You can setup multiple ranges, but I need only one. I will use real numbers in this example:
$Conf{DHCPAddressRanges} = [ { ipAddrBase => '192.168.1', first => 21, last => 200, }, ];
This will scann all IPs from 192.168.1.21 to 192.168.1.200 and check the hostname it gets back with the one you defined. It is a nice feature if you have an ADSL router with DHCP which changes your host IP address every time you ask a new lease.
You can now reload the configuration with:
service backuppc reload
Installation on the windows machine
The rsync daemon/service has to be installed on the windows machine. The easiest way is to use the one from the BackupPC repository. The current is this one. Once installed open the c:\rsyncd\rsyncd.conf and setup a share like this:
[backup_folder]
path = /cygdrive/c/Users/
comment = Users folder
strict modes = false
# Limit this share to just these users (needs to match $Conf{RsyncdUserName}
# and the c:/rsyncd/rsyncd.secrets files)
auth users = backuppc
# Password to match $Conf(RsyncdPasswd)
secrets file = c:/rsyncd/rsyncd.secrets
# List the IP address(es) of your BackupPC server(s), so only connections from these hosts will be allowed.
hosts allow = 192.168.1.1/24
# Allows restores to write to this share
read only = true
list = true
This will backup the Users folder which is usually the most important folder people put stuff in. The name in square brackets must match the one defined in the myhost.pl file. Multiple shares can be defined, with different options for each one. This one is readonly, accessible for user backuppc and limited to the local network (192.168.1.1/24). Remember to use foward slashes in this file and that the path mapping of folders is linux-like (c:\ is /cygdrive/c/).
The password for the backuppc user is setup in the c:\rsyncd\rsync.secrets file. Add the following line at the end of that file:
backuppc:backuppc
And be sure to add an empty line at the end.
You can restart the RsyncServer service with a right click on My Computer -> Manage -> Services and Application -> Services -> Rsync Server (right click) -> Restart
Go, go, go…
You are done. The first full backup will occur at the time specified in the BackupPC config file (20:00, from the last post).
Installing BackupPC on openSuse 13.1
I was trying to install BackupPC on my fresh openSuse 13.1 install. There was no package for openSuse so I used the documentation from the original site.
Prerequisites
The missing prerequsite for perl is File::RsyncP which you can install from repository in version 0.43, or use the newer one from Sourceforge in version 0.68. I like being on the bleeding edge (0.43 is from 2003, and 0.68 is from 2006) and actually BackupPC states that it needs at least 0.68.
wget http://downloads.sourceforge.net/project/perlrsync/perlrsync/0.68/File-RsyncP-0.68.tar.gz
tar -xvf File-RsyncP-0.68.tar.gz
cd File-RsyncP-0.68
perl Makefile.PL
make
Error 1:
Make is missing so I have to install that also.
Fix 1:
zypper install make
Continuing the installation of File::RsyncP.
make
Error 2:
GCC is missing so I have to install that also.
Fix 2:
zypper install gcc
Continuing the installation of File::RsyncP.
make
make install
There were some warnings, but the tests passed OK, so I think this will work just fine.
Creating a dedicated user and group
For security reasons a dedicated user and group should be used for running BackupPc.
useradd -d /home/backuppc -c 'BackupPC user' -U -r -M backuppc
mkdir /home/backuppc
chown -R backuppc:backuppc /home/backuppc
Getting and installing BackupPC 3.3.0
The source can be downloaded from Sourceforge and the installation is trivial.
wget http://downloads.sourceforge.net/project/backuppc/backuppc/3.3.0/BackupPC-3.3.0.tar.gz
tar -xvf BackupPC-3.3.0.tar.gz
cd BackupPC-3.3.0
perl configure.pl
Now is the time to answer some questions:
- Full path to existing main config.pl – leave empty
- Are these paths correct? – yes
- BackupPC will run on host [your_host_name]? – acknowledge the default
- BackupPC should run as user [backuppc]? – use the default
- Install directory (full path) – /opt/BackupPC
- Data directory (full path) – /home/backuppc/data
- Compression level [3]? – user default
- CGI bin directory (full path) – /srv/www/cgi-bin
- Apache image directory (full path) – /srv/www/htdocs/BackupPC
- URL for image directory (omit http://host; starts with ‘/’) – /BackupPC
- Do you want to continue? – yes
Now that BackupPC is installed, in needs to be configured. So open /etc/BackupPC/config.pl and configure it:
$Conf{WakeupSchedule} = [20];
$Conf{FullKeepCnt} = [4, 0, 4];
$Conf{IncrLevels} = [1, 2, 3, 4, 5, 6];
$Conf{CgiAdminUsers} = 'your_username';
Run every day at 20:00, have 5 months of full backups (4 * 1 week + 4 * 1 month), create 6 incremental backups between full backups (every day between the weekly full backup), and setup a user as admin.
Acording to this article, the default init script is not good so another one should be used. As that script is also broken, you can use the following:
#!/bin/sh
#
# /etc/init.d/backuppc
#
### BEGIN INIT INFO
# Provides: backuppc
# Required-Start: $local_fs $remote_fs $network
# X-UnitedLinux-Should-Start:
# Required-Stop: $local_fs $remote_fs $network
# X-UnitedLinux-Should-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: BackupPC - High End Archive Server
# Description: Start the BackupPC daemon
### END INIT INFO
pname=backuppc
set -e
#
BINDIR=/opt/BackupPC/bin
DATADIR=/home/backuppc/data
LOGDIR=/var/log/BackupPC
USER=backuppc
#
NAME=backuppc
DAEMON=BackupPC
test -x $BINDIR/$DAEMON || exit 0
case "$1" in
start)
echo -n "Starting $NAME: "
startproc -p $LOGDIR/BackupPC.pid -u $USER $BINDIR/$DAEMON -d
echo "ok."
;;
stop)
echo -n "Stopping $NAME: "
killproc -TERM -p $LOGDIR/BackupPC.pid $BINDIR/$DAEMON
echo "ok."
;;
restart)
$0 stop
$0 start
;;
reload|force-reload)
echo "Reloading $NAME configuration files"
killproc -SIGHUP -p $LOGDIR/BackupPC.pid $BINDIR/$DAEMON
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
After that register the service with this command:
install -m 0755 backuppc /etc/init.d/
Go, go, go…
Run the service with:
service backuppc start
And that’s it. Now, to configure clients and Nginx you will have to wait for the next article.