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 PasswordAuthentication=no $desthost -l $destuser 'echo -n 1'"
47 ret=`ssh -o PasswordAuthentication=no $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 $desthost -l $destuser '$RDIFFBACKUP -V'\""
56 remoteversion=`ssh $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 [ "$label" != "" ] || fatal "Source missing label"
69 [ "$sourcetype" == "local" ] || fatal "Only local source type supported"
70 [ "$include" != "" -o "$vsinclude" != "" ] || fatal "No source includes specified"
71 #TODO should I test for vsinclude if usevservers=1?
73 execstr_clientpart="/"
77 if [ "`echo $keep | tr -d 0-9`" == "" ]; then
81 removestr="rdiff-backup --force --remove-older-than $keep "
82 if [ "$desttype" == "remote" ]; then
83 removestr="${removestr}${destuser}@${desthost}::"
85 removestr="${removestr}${destdir}/${label}";
89 output=`$removestr 2>&1`
91 if [ "$code" == "0" ]; then
93 info "Removing backups older than $keep days succeeded."
96 warning "Failed removing backups older than $keep."
102 execstr="$RDIFFBACKUP $options --print-statistics "
104 # TODO: order the includes and excludes
107 for i in $exclude; do
108 str="${i//__star__/*}"
109 execstr="${execstr}--exclude '$str' "
113 for i in $include; do
114 str="${i//__star__/*}"
115 execstr="${execstr}--include '$str' "
121 for vserver in `ls $VROOTDIR|grep -v lost+found`
125 str="${vi//__star__/*}"
126 execstr="${execstr}--include '$VROOTDIR/$vserver$str' "
131 # exclude everything else
132 execstr="${execstr}--exclude '/*' "
134 # include client-part and server-part
135 execstr="${execstr}$execstr_clientpart $execstr_serverpart"
139 output=`nice -n $nicelevel su -c "$execstr" 2>&1`
141 if [ "$code" == "0" ]; then
143 info "Successfully finished backing up source '$label'"
146 warning "Failed backup up source '$label'"