2 # rdiff-backup handler script for backupninja
3 # requires rdiff-backup
7 getconf type; sourcetype=$type
9 getconf user; sourceuser=$user
17 getconf directory; destdir=$directory
20 getconf type; desttype=$type
21 getconf user; destuser=$user
22 getconf host; desthost=$host
24 [ "$destdir" != "" ] || fatal "Destination directory not set"
25 [ "$desttype" == "remote" ] || fatal "Only remote destinations are supported"
28 debug 0 "su $sourceuser -c \"ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'\""
30 result=`su $sourceuser -c "ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'" 2>&1`
31 if [ "$result" != "1" ]; then
32 fatal "Can't connect to $desthost as $destuser."
36 # see that rdiff-backup has the same version as here
37 debug 0 "su $sourceuser -c \"ssh $desthost -l $destuser '$RDIFFBACKUP -V'\""
39 remoteversion=`su $sourceuser -c "ssh $desthost -l $destuser '$RDIFFBACKUP -V'" 2>&1`
40 localversion=`$RDIFFBACKUP -V`
41 if [ "$remoteversion" != "$localversion" ]; then
42 fatal "rdiff-backup does not have the same version on this computer and the backup server."
46 execstr_serverpart="$destuser@$desthost::$destdir/$label"
50 [ "$label" != "" ] || fatal "Source missing label"
51 [ "$sourcetype" == "local" ] || fatal "Only local source type supported"
52 [ "$include" != "" ] || fatal "No source includes specified"
54 execstr_clientpart="/"
58 if [ "$keep" -gt "0" ]; then
59 removestr="rdiff-backup --force --remove-older-than ${keep}D "
60 if [ "$desttype" == "remote" ]; then
61 removestr="${removestr}${destuser}@${desthost}::"
63 removestr="${removestr}${destdir}/${label}";
65 debug 0 "su $sourceuser -c '$removestr'"
67 output=`su $sourceuser -c "$removestr" 2>&1`
69 if [ "$code" == "0" ]; then
71 debug 1 "Removing backups older than $keep days succeeded."
74 debug 2 "Failed removing backups older than $keep."
81 execstr="$RDIFFBACKUP --print-statistics "
83 # TODO: order the includes and excludes
87 str="${i//__star__/*}"
88 execstr="${execstr}--exclude '$str' "
93 str="${i//__star__/*}"
94 execstr="${execstr}--include '$str' "
97 # exclude everything else
98 execstr="${execstr}--exclude '/*' "
100 # include client-part and server-part
101 execstr="${execstr}$execstr_clientpart $execstr_serverpart"
103 debug 0 "su $sourceuser -c '$execstr'"
105 output=`su $sourceuser -c "$execstr" 2>&1`
107 if [ "$code" == "0" ]; then
109 debug 1 "Successfully finished backing up source '$label'"
112 debug 2 "Failed backup up source '$label'"