From: Andrew Ruthven Date: Thu, 26 Apr 2012 08:55:02 +0000 (+1200) Subject: Add commwnts. X-Git-Tag: v0.2~3 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d336dc66e49b83f1aa20770cf237c75523168bd;p=etc-obnam.git Add commwnts. --- diff --git a/run-backup b/run-backup index 43cd3ce..0eb54f3 100755 --- a/run-backup +++ b/run-backup @@ -1,11 +1,20 @@ #!/bin/bash +# Conditionally run obnam. +# +# If $HOST_NAME is defined, check that we can ping it. +# If $HOST_MAC is defined, check that the arp/neighbour table has a matching +# MAC address. +# If those conditions are meet, then backup $SOURCE, but first grab some +# debconf data so we can reconstruct the packages installed if we need to. + . /etc/default/etc-obnam CLIENT=$(hostname) SOURCE=${SOURCE:-/home /etc} WORKDIR=/var/lib/etc-obnam +# Check that the host is local, support both IPv4 and IPv6. function check_host() { local type=$1 if [ "x$type" != "xA" -a "x$type" != "xAAAA" ] @@ -20,23 +29,29 @@ function check_host() { return 0 fi + # Make sure that we can get DNS details for the host first. local ip=$(host -t $type $HOST_NAME | grep address | awk '{ print $NF }' | head -1) if [ "x$ip" = "x" ] then return 1 fi + # ping or ping6? local cmd=ping if [ $type = "AAAA" ] then cmd=ping6 fi + # ping at will. if ! $cmd -n -c3 $HOST_NAME &> /dev/null then return 1 fi + # Check the neighbour table. If $HOST_NAME is *us* then we won't have an + # entry, that is why HOST_MAC is optional. Could check ip link to see if + $ $HOST_MAC is on this box. local mac=$(ip neigh | egrep "^$ip " | grep REACHABLE | awk '{ print $5 }' ) if [ $(echo $mac | wc -l ) -ne 1 ] then @@ -51,6 +66,8 @@ function check_host() { return 0 } +# Grab enough details to hopefully be able to reconstuct the installed +# packages. function capture_debconf_info() { # Keep a list of the installed files dpkg --get-selections > $WORKDIR/installed.packages.new @@ -69,7 +86,7 @@ function capture_debconf_info() { fi } - +# Check to see if the right host is present, if it is, do a backup. if ( check_host 'AAAA' -o check_host 'A' ) then capture_debconf_info