2 # rdiff-backup handler script for backupninja
3 # requires rdiff-backup
9 getconf type; sourcetype=$type
11 getconf user root; sourceuser=$user
19 getconf directory; destdir=$directory
22 getconf type; desttype=$type
23 getconf user; destuser=$user
24 getconf host; desthost=$host
26 [ "$destdir" != "" ] || fatal "Destination directory not set"
27 [ "$desttype" == "remote" ] || fatal "Only remote destinations are supported"
30 debug "su $sourceuser -c \"ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'\""
32 result=`su $sourceuser -c "ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'" 2>&1`
33 if [ "$result" != "1" ]; then
34 fatal "Can't connect to $desthost as $destuser."
38 # see that rdiff-backup has the same version as here
39 debug "su $sourceuser -c \"ssh $desthost -l $destuser '$RDIFFBACKUP -V'\""
41 remoteversion=`su $sourceuser -c "ssh $desthost -l $destuser '$RDIFFBACKUP -V'" 2>&1`
42 localversion=`$RDIFFBACKUP -V`
43 if [ "$remoteversion" != "$localversion" ]; then
44 fatal "rdiff-backup does not have the same version on this computer and the backup server."
48 execstr_serverpart="$destuser@$desthost::$destdir/$label"
52 [ "$label" != "" ] || fatal "Source missing label"
53 [ "$sourcetype" == "local" ] || fatal "Only local source type supported"
54 [ "$include" != "" ] || fatal "No source includes specified"
56 execstr_clientpart="/"
60 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
64 removestr="rdiff-backup --force --remove-older-than $keep "
65 if [ "$desttype" == "remote" ]; then
66 removestr="${removestr}${destuser}@${desthost}::"
68 removestr="${removestr}${destdir}/${label}";
70 debug "su $sourceuser -c '$removestr'"
72 output=`su $sourceuser -c "$removestr" 2>&1`
74 if [ "$code" == "0" ]; then
76 info "Removing backups older than $keep days succeeded."
79 warning "Failed removing backups older than $keep."
85 execstr="$RDIFFBACKUP $options --print-statistics "
87 # TODO: order the includes and excludes
91 str="${i//__star__/*}"
92 execstr="${execstr}--exclude '$str' "
97 str="${i//__star__/*}"
98 execstr="${execstr}--include '$str' "
101 # exclude everything else
102 execstr="${execstr}--exclude '/*' "
104 # include client-part and server-part
105 execstr="${execstr}$execstr_clientpart $execstr_serverpart"
107 debug "su $sourceuser -c '$execstr'"
109 output=`su $sourceuser -c "$execstr" 2>&1`
111 if [ "$code" == "0" ]; then
113 info "Successfully finished backing up source '$label'"
116 warning "Failed backup up source '$label'"