2 # rdiff-backup handler script for backupninja
3 # requires rdiff-backup
7 getconf testconnect yes
11 getconf type; sourcetype=$type
20 getconf directory; destdir=$directory
23 getconf type; desttype=$type
24 getconf user; destuser=$user
25 getconf host; desthost=$host
27 [ "$destdir" != "" ] || fatal "Destination directory not set"
29 if [ "$desttype" == "remote" ]; then
31 if [ "$testconnect" == "yes" ]; then
33 debug "ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
34 ret=`ssh -o PasswordAuthentication=no $desthost -l $destuser 'echo -n host is alive'`
35 if echo $ret | grep "host is alive"; then
36 debug "Connected to $desthost as $destuser successfully"
38 fatal "Can't connect to $desthost as $destuser."
41 # see that rdiff-backup has the same version as here
42 debug "ssh $desthost -l $destuser '$RDIFFBACKUP -V'\""
43 remoteversion=`ssh $desthost -l $destuser "$RDIFFBACKUP -V | grep rdiff-backup"`
44 localversion=`$RDIFFBACKUP -V`
45 if [ "$remoteversion" != "$localversion" ]; then
46 fatal "rdiff-backup does not have the same version on this computer and the backup server."
48 execstr_serverpart="$destuser@$desthost::$destdir/$label"
50 execstr_serverpart="$destdir/$label"
55 [ "$label" != "" ] || fatal "Source missing label"
56 [ "$sourcetype" == "local" ] || fatal "Only local source type supported"
57 [ "$include" != "" ] || fatal "No source includes specified"
59 execstr_clientpart="/"
63 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
67 removestr="rdiff-backup --force --remove-older-than $keep "
68 if [ "$desttype" == "remote" ]; then
69 removestr="${removestr}${destuser}@${desthost}::"
71 removestr="${removestr}${destdir}/${label}";
75 output=`$removestr 2>&1`
77 if [ "$code" == "0" ]; then
79 info "Removing backups older than $keep days succeeded."
82 warning "Failed removing backups older than $keep."
88 execstr="$RDIFFBACKUP $options --print-statistics "
90 # TODO: order the includes and excludes
94 str="${i//__star__/*}"
95 execstr="${execstr}--exclude '$str' "
100 str="${i//__star__/*}"
101 execstr="${execstr}--include '$str' "
104 # exclude everything else
105 execstr="${execstr}--exclude '/*' "
107 # include client-part and server-part
108 execstr="${execstr}$execstr_clientpart $execstr_serverpart"
112 output=`nice -n $nicelevel su -c "$execstr" 2>&1`
114 if [ "$code" == "0" ]; then
116 info "Successfully finished backing up source '$label'"
119 warning "Failed backup up source '$label'"