Archive

Posts Tagged ‘rsync’

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).