+function setup_remote_dirs() {
+ local backuptype=$1
+ local dir="$destdir/$backuptype"
+
+(
+ ssh -T -o PasswordAuthentication=no $desthost -l $destuser <<EOF
+ if [ ! -d $destdir ]; then
+ echo "Fatal: Destination directory $destdir does not exist on host $desthost."
+ exit 1
+ elif [ -d $dir.1 ]; then
+ if [ -f $dir.1/created ]; then
+ echo "Warning: $dir.1 already exists. Overwriting contents."
+ else
+ echo "Warning: we seem to be resuming a partially written $dir.1"
+ fi
+ else
+ if [ -d $destdir/rotate.tmp ]; then
+ mv $destdir/rotate.tmp $dir.1
+ if [ \$? == 1 ]; then
+ echo "Fatal: could mv $destdir/rotate.tmp $dir.1 on host $desthost"
+ exit 1
+ fi
+ else
+ mkdir $dir.1
+ if [ \$? == 1 ]; then
+ echo "Fatal: could not create directory $dir.1 on host $desthost"
+ exit 1
+ fi
+ 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 y x z; do
+ mkdir $dir.1/\$i
+ done
+ fi
+ if [ -d $destdir/$backuptype.2 ]; then
+ echo "Info: updating hard links to $dir.1. This may take a while."
+ cp -alf $destdir/$backuptype.2/. $dir.1
+ #if [ \$? == 1 ]; then
+ # echo "Fatal: could not create hard links to $dir.1 on host $desthost"
+ # exit 1
+ #fi
+ fi
+ fi
+ [ -f $dir.1/created ] && rm $dir.1/created
+ [ -f $dir.1/rotated ] && rm $dir.1/rotated
+ exit 0
+EOF
+) | (while read a; do passthru $a; done)
+
+ if [ $? == 1 ]; then exit; fi
+}
+