« HOWTO: Install and Configure sshHOWTO Enlarge A VMware Disk »

Backing Up and Restoring

30/07/08

Backing Up and Restoring

I use the rather wonderful bit of software called BackupPC to backup and restore my various PCs. The documentation is really very good and you should go read that rather than this mini-howto. :>

Hint:
This document is really for me so I can remember what I did to get it setup and working. I already have a working system that is backed up .

Follow up:

Installation

This is done with apt-get that way all the dependent Perl modules get installed too. Well almost par2 didn't :)

Installation
sudo apt-get install backuppc par2

During the installation you will be asked which web server to preconfigure Backuppc to use, I use Apache2 as it is already running on my backup machine.

Configuration

I then ran the configuration script to customize the installation. I have a very large disk array on the machine I'm using as my backup server. So I created a new LVM logical volume called backup. That is where the data from all the backups will live.

Creating my LVM logical group
sudo lvcreate -L 100G -nbackup vg1  
 
sudo mkfs.reiserfs /dev/vg1/backup 
 
sudo mkdir /backup 
sudo mount /dev/vg1/backup /backup 

I ended up using tar transport, as the only windows I have are in the outside wall of my house. ;)

Edit the file /etc/backuppc/config.pl customizing it for your needs. Stop the service before doing the edit and update.

sudo /etc/init.d/backuppc stop

As I have my backup data store on an LVM drive, /backup, I need to move the existing directory and create a symbolic link to join them back up.

sudo chown backuppc:backuppc /backup 
sudo chmod 750 /backup 
cd /var/lib 
sudo mv backuppc/* /backup 
sudo rmdir backuppc 
sudo ln -s /backup backuppc
sudo gedit /etc/backuppc/config.pl

Change the Web access password, as I always forget to write down the generated one :oops:

cd /etc/backuppc 
sudo htpasswd ./htpasswd backuppc 

I like to change the hostname used for localhost to be the servers real name. You do that by editing the backuppc hosts file.

sudo nano /etc/backuppc/hosts

Restart the backuppc service.

sudo /etc/init.d/backuppc start

Now check that the CGI interface is running, http://localhost/backuppc/index.cgi

To make the backup and restore more secure. We should remove the need for the backuppc user to ssh as root to all the client machines. To do this we create two shell scripts one for backup the other for restore. So that we can use sudo after backuppc has ssh'ed tot he client. We also need to allow access/permissions to sudo without a password forthese two commands only.

sudo nano /etc/backuppc/BackupPC_tarCreate.sh
#!/bin/sh -f 
 
exec /bin/tar -c $*
sudo nano /etc/backuppc/BackupPC_tarRestore.sh
#!/bin/sh -f 
 
exec /bin/tar -x $*

These must have their permissions changed or they leave a large security hole, for anyone to replace files anywhere on the system.

sudo chown root:backuppc /etc/backuppc/BackupPC_* 
sudo chmod 750 /etc/backuppc/BackupPC_*

We need to change TarClientCmd so it reads

$sshPath -q -x -n -l backuppc $host env LC_ALL=C sudo /etc/backuppc/BackupPC_tarCreate.sh \ 
        -v -f - -C $shareName+ --totals --one-file-system

and the TarClientRestoreCmd should now read

$sshPath -q -x -l backuppc $host env LC_ALL=C sudo /etc/backuppc/BackupPC_tarRestore.sh \ 
        -p --numeric-owner --same-owner -v -f - -C $shareName+

sudo nano /etc/backuppc/config.pl

$Conf{BackupFilesOnly} = { 
  '/' => [ 'bin','boot', 'cdrom', 'data', 'dev', 'etc', 'home', 
    'initrd.img', 'initrd.img.old', 'lib', 'lib32', 'lib64', 
    'media', 'mnt', 'net', 'opt', 'proc', 'root', 'sbin', 'selinux',  
    'srv', 'sys', 'tmp','vmlinuz','vmlinuz.old' 
  ] 
};
$Conf{BackupFilesExclude} = { 
  '*' => [ 
    '.gvfs', 'backup', 'Cache', 'cache', 'tmp', 
    '*~', '*bak', '*log' 
  ] 
};

Server Side.

You should already have a user called backuppc that was created by the installation process. Set up ssh to work from the server machine so you can ssh to all the clients you wish to backup. See my mini-HOWTO on setting up ssh.

You will need to ssh fro the server to each client at least once from the command line. This will setup the entry in the known hosts file.

Client Side

Create a new unprivileged user called backuppc

sudo groupadd -g 119 backuppc  sudo useradd -g backuppc -u 126 backuppc -d /home/backuppc -m

Create a new shell script /etc/backuppc/BackupPC_rsync.sh

sudo mkdir /etc/backuppc
sudo gedit /etc/backuppc/BackupPC_rsync.sh
/etc/backuppc/BackupPC_rsync.sh
#!/bin/bash -f
exec /usr/bin/rsync $*

and then set the permissions so it is owned by root and executable by the backuppc user

sudo chown root:backuppc /etc/backuppc/BackupPC_rsync.sh
sudo chmod 750 /etc/backuppc/BackupPC_rsync.sh

and finally allow the user backuppc to run the command /etc/backuppc/BackupPC_rsync.sh as the user root without a password.

Edit the file /etc/sudoer and add the following line to the end

sudo visudo
backuppc ALL=NOPASSWD:    /etc/backuppc/BackupPC_rsync.sh *

From the server make sure you can ssh to the clients as the user backuppc without the need of a password.

You should now be able to backup and restore.


Pages: 1 · 2 · 3

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
What can birds and aeroplanes both do?
antispam test