2 # rdiff-backup handler script for backupninja
3 # requires rdiff-backup
7 getconf testconnect yes
11 getconf type; sourcetype=$type
21 getconf directory; destdir=$directory
24 getconf type; desttype=$type
25 getconf user; destuser=$user
26 getconf host; desthost=$host
28 # See if vservers are configured
29 if [ "$vservers" = "yes" ]
33 fatal "vservers enabled, but $VROOTDIR does not exist!"
35 info "vserver method enabled"
40 [ "$destdir" != "" ] || fatal "Destination directory not set"
42 if [ "$desttype" == "remote" ]; then
44 if [ "$testconnect" == "yes" ]; then
46 debug "ssh -o PreferredAuthentications=publickey $desthost -l $destuser 'echo -n 1'"
47 ret=`ssh -o PreferredAuthentications=publickey $desthost -l $destuser 'echo -n host is alive'`
48 if echo $ret | grep "host is alive"; then
49 debug "Connected to $desthost as $destuser successfully"
51 fatal "Can't connect to $desthost as $destuser."
54 # see that rdiff-backup has the same version as here
55 debug "ssh -o PreferredAuthentications=publickey $desthost -l $destuser '$RDIFFBACKUP -V'\""
56 remoteversion=`ssh -o PreferredAuthentications=publickey $desthost -l $destuser "$RDIFFBACKUP -V | grep rdiff-backup"`
57 localversion=`$RDIFFBACKUP -V`
58 if [ "$remoteversion" != "$localversion" ]; then
59 fatal "rdiff-backup does not have the same version on this computer and the backup server."
61 execstr_serverpart="$destuser@$desthost::$destdir/$label"
63 execstr_serverpart="$destdir/$label"
68 [ "$sourcetype" == "local" ] || fatal "Only local source type supported"
69 [ "$include" != "" -o "$vsinclude" != "" ] || fatal "No source includes specified"
70 #TODO should I test for vsinclude if usevservers=1?
72 execstr_clientpart="/"
76 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
80 removestr="rdiff-backup --force --remove-older-than $keep "
81 if [ "$desttype" == "remote" ]; then
82 removestr="${removestr}${destuser}@${desthost}::"
84 removestr="${removestr}${destdir}/${label}";
88 output=`$removestr 2>&1`
90 if [ "$code" == "0" ]; then
92 info "Removing backups older than $keep days succeeded."
95 warning "Failed removing backups older than $keep."
101 execstr="$RDIFFBACKUP $options --print-statistics "
103 # TODO: order the includes and excludes
106 for i in $exclude; do
107 str="${i//__star__/*}"
108 execstr="${execstr}--exclude '$str' "
112 for i in $include; do
113 str="${i//__star__/*}"
114 execstr="${execstr}--include '$str' "
120 for vserver in `ls $VROOTDIR | grep -E -v "lost+found|ARCHIVES"`
124 str="${vi//__star__/*}"
125 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
130 # exclude everything else
131 execstr="${execstr}--exclude '/*' "
133 # include client-part and server-part
134 execstr="${execstr}$execstr_clientpart $execstr_serverpart"
138 output=`nice -n $nicelevel su -c "$execstr" 2>&1`
140 if [ "$code" == "0" ]; then
142 info "Successfully finished backing up source $label"
145 warning "Failed backup up source $label"