X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fbackupninja.git;a=blobdiff_plain;f=handlers%2Fmaildir.in;h=87cad4eaa2a6db492158d59085f5e78f120ac17f;hp=7a68e858a5f36fbcf07defab659d430dd8e5dbfe;hb=56617bfc5bd846f660ac015d7ee349e0134c7a43;hpb=84a6d7fa7a6c2ebd4e2b6687dba8fc6addfb843a diff --git a/handlers/maildir.in b/handlers/maildir.in index 7a68e85..87cad4e 100644 --- a/handlers/maildir.in +++ b/handlers/maildir.in @@ -49,10 +49,11 @@ getconf destdir getconf desthost getconf destport 22 getconf destuser +getconf destid_file /root/.ssh/id_rsa getconf multiconnection notset -letters="a b c d e f g h i j k l m n o p q r s t u v w x y z" +letters="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z" failedcount=0 # strip trailing / destdir=${destdir%/} @@ -66,7 +67,7 @@ if [ $test ]; then testflags="--dry-run -v" fi -rsyncflags="$testflags -e 'ssh -p $destport' -r -v --ignore-existing --delete --size-only --bwlimit=$speedlimit" +rsyncflags="$testflags -e 'ssh -p $destport -i $destid_file' -r -v --ignore-existing --delete --size-only --bwlimit=$speedlimit" excludes="--exclude '.Trash/\*' --exclude '.Mistakes/\*' --exclude '.Spam/\*'" ################################################################## @@ -84,7 +85,7 @@ function do_user() { fi debug "syncing" - ret=`$RSYNC -e "ssh -p $destport" -r \ + ret=`$RSYNC -e "ssh -p $destport -i $destid_file" -r \ --links --ignore-existing --delete --size-only --bwlimit=$speedlimit \ --exclude '.Trash/*' --exclude '.Mistakes/*' --exclude '.Spam/*' \ $source $destuser@$desthost:$target \ @@ -99,7 +100,7 @@ function do_user() { fatal "100 rsync errors -- something is not working right. bailing out." fi fi - ssh -o PasswordAuthentication=no $desthost -l $destuser "date +%c%n%s > $target/created" + ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file "date +%c%n%s > $target/created" } # remove any maildirs from backup which might have been deleted @@ -110,14 +111,15 @@ function do_remove() { local tmp1=`maketemp maildir-tmp-file` local tmp2=`maketemp maildir-tmp-file` - ssh -p $destport $destuser@$desthost mkdir -p "$destdir/deleted" - for i in a b c d e f g h i j k l m n o p q r s t u v w x y z; do + ssh -p $destport -i $estid_file $destuser@$desthost mkdir -p "$destdir/deleted" + for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z; do ls -1 "$srcdir/$i/" | sort > $tmp1 ssh -p $destport $destuser@$desthost ls -1 "$destdir/$i/" | sort > $tmp2 for deluser in `join -v 2 $tmp1 $tmp2`; do [ "$deluser" != "" ] || continue info "removing $destuser@$desthost:$destdir/$i/$deluser/" - ssh -p $destport $destuser@$desthost mv "$destdir/$i/$deluser/" "$destdir/deleted" + ssh -p $destport -i $destid_file $destuser@$desthost mv "$destdir/$i/$deluser/" "$destdir/deleted" + ssh -p $destport -i $destid_file $destuser@$desthost "date +%c%n%s > '$destdir/$i/$deluser/deleted_on'" done done rm $tmp1 @@ -130,7 +132,7 @@ function do_rotate() { local letter=${user:0:1} local backuproot="$destdir/$letter/$user" ( - ssh -T -o PasswordAuthentication=no $desthost -l $destuser < 0; i-- )); do @@ -201,7 +203,7 @@ function do_rotate() { for rottype in daily weekly monthly; do max=\$((keep\${rottype}+1)) dir="$backuproot/\$rottype" - oldest=\`find $backuproot -type d -maxdepth 1 -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` + oldest=\`find $backuproot -maxdepth 1 -type d -name \$rottype'.*' | @SED@ 's/^.*\.//' | sort -n | tail -1\` [ "\$oldest" == "" ] && oldest=0 # if we've rotated the last backup off the stack, remove it. for (( i=\$oldest; i >= \$max; i-- )); do @@ -229,7 +231,7 @@ function setup_remote_dirs() { local dir="$destdir/$letter/$user/$backuptype" local tmpdir="$destdir/$letter/$user/rotate.tmp" ( - ssh -T -o PasswordAuthentication=no $desthost -l $destuser <&1` + result=`ssh -o PasswordAuthentication=no $desthost -l $destuser -i $destid_file 'echo -n 1' 2>&1` if [ "$result" != "1" ]; then - fatal "Can't connect to $desthost as $destuser." + fatal "Can't connect to $desthost as $destuser using $destid_file." fi fi @@ -302,7 +304,7 @@ end_mux start_mux ## SANITY CHECKS ## -status=`ssh -p $destport $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` +status=`ssh -p $destport -i $destid_file $destuser@$desthost "[ -d \"$destdir\" ] && echo 'ok'"` if [ "$status" != "ok" ]; then end_mux fatal "Destination directory $destdir doesn't exist!"