BackupPC - restoring backups from command line

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

This simple script makes tar.gz packages for hosts you have in your BackupPC archive.

You can later write these packages to tape, or copy them somewhere else.


Note that you have to set up an "archive host", as described in BackupPC documentation.

Change the variables and other details to suit your needs.


#!/bin/bash

# Script for restoring hosts (last full backup) from command line.
# The restored backups can be found in $RESTOREDIR (defined below),
# and are to be written on tape.

BACKUPPCDIR=/srv/backuppc-data
HOSTSDIR=$BACKUPPCDIR/pc
RESTOREDIR=$HOSTSDIR/restore/restore

# put the hosts/directories you do not want to restore into egrep...
HOSTS=$(ls $HOSTSDIR | egrep -v '(HOST_CONFIG_FILES|restore)' | tr / " ")
# or use:
# HOSTS="HOST1 HOST2 REMOTE3"


# no need to change anything below...

DATE=$(date +%F)
mkdir -p $RESTOREDIR/$DATE

for HOST in $HOSTS
do
# find the last full backup
NUMBER=$(grep full $HOSTSDIR/$HOST/backups| tail -1 | cut -f1)

if [ "$NUMBER" ]
then

# do the backup for the host
$BACKUPPCDIR/bin/BackupPC_archiveHost $BACKUPPCDIR/bin/BackupPC_tarCreate /usr/bin/split /usr/bin/par2 \
            "$HOST" "$NUMBER" /usr/bin/gzip .gz 0000000 $RESTOREDIR/$DATE 0 \*
fi

done