#!/bin/bash set -e #init some vars. This should move to a config file sometime. use_dataq="NO" ip_of_backupserver="192.168.2.2" my_hostname=`hostname` mac_of_backupserver="00:60:08:6E:7A:27" dataq_host="192.168.2.2" dataq_user="dataq" dataq_password="dataq" dataq_port="50000" dataq_queue="backup" keep_time="30D" #give the user a change to abort read -t10 -n1 -s -p "Press Q to cancel automatic backup. If no input for 10 seconds we will backup anyway." || true if [ "$REPLY" == "Q" ]; then echo "" echo "user aborted" exit 1 else echo "" echo "Starting backup run." fi #check if my server is here #first run a ping to fill arp table. Thnx Ferry Boender for this tip. uselessvar=`ping -q -c1 $ip_of_backupserver` #now check the hardware address arpreq=`arp -a $ip_of_backupserver | cut -d " " -f 4` if [ "$arpreq" == "$mac_of_backupserver" ]; then echo "mac address ok, checking status..." else echo "mac address not ok, bailing out." exit 1 fi #check if backups are allowed by the server #only if $use_dataq = YES if [ "$use_dataq" == "YES" ]; then serverstatus=`echo "PEEK $dataq_user:$dataq_password@$dataq_queue" | nc6 $dataq_host $dataq_port` if [ "$serverstatus" == "allowed" ]; then echo "server reported ok, starting backup..." else echo "server reported not allowed to make backus, bailing out." exit 1 fi fi #do the backup #add all the dirs you want to backup here rdiff-backup --terminal-verbosity 0 /home $ip_of_backupserver::/var/backups/remote/$my_hostname/home rdiff-backup --terminal-verbosity 0 /etc $ip_of_backupserver::/var/backups/remote/$my_hostname/etc #cleanup #since rdiff-backup cannot do backup and cleanup in one run, we have to do it here. #all dirs you specified above should be listed here rdiff-backup --force --remove-older-than $keep_time $ip_of_backupserver::/var/backups/remote/$my_hostname/home >/dev/null 2>&1 || true rdiff-backup --force --remove-older-than $keep_time $ip_of_backupserver::/var/backups/remote/$my_hostname/etc >/dev/null 2>&1 || true echo "Backup completed"