X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=bin%2Fbackup;h=b29d2b7a0a1cbc2a3c63d4ba81eafaf2f8717f53;hb=8f054797a11631cf2973d397c3a4449abd8e72a9;hp=b758e14f7d464a473c1fb258ade844346e2f1e1a;hpb=26b498357009fee67377a8300db277d3a6c3ef02;p=outofuni%2Fbackup.git diff --git a/bin/backup b/bin/backup index b758e14..b29d2b7 100755 --- a/bin/backup +++ b/bin/backup @@ -29,6 +29,8 @@ bandwidth=`grep ^bandwidth $config | cut -d ' ' -f 2` bwconn="`grep ^bandwidth $config | cut -d ' ' -f 3-`" compression=`grep ^compression $config | cut -d ' ' -f 2` compconn="`grep ^compression $config | cut -d ' ' -f 3-`" +cipher=`grep ^cipher $config | cut -d ' ' -f 2` +ciconn=`grep ^cipher $config | cut -d ' ' -f 3-` logdir=`grep ^logdir $config | cut -d ' ' -f 2` dolog=0 @@ -53,6 +55,11 @@ else log "host $host (via $remote) is online ..." fi +if [ ! -z "`ssh $user@$remote 'cat ~/.backup | grep ^off'`" ]; then + log "backup rejected by client ..." + exit 0 +fi + comp=6 if [ ! -z "$compression" ]; then comp=$compression @@ -74,13 +81,28 @@ if [ ! -z "$bandwidth" ]; then ch=`echo $bwpair | cut -d ':' -f 1` if [[ "$remote" == "$ch"* ]]; then bwl=`echo $cpair | cut -d ':' -f 2` - [ ! -z "$bwl" ]] && bw=$bwl + [ ! -z "$bwl" ] && bw=$bwl fi done fi -rbw="--bandwidth=$bw" +rbw="--bwlimit=$bw" log applying bandwidth of $bw ... +ciph="" +if [ ! -z "$cipher" ]; then + ciph=$cipher + for cipair in "$ciconn"; do + ch=`echo $cipair | cut -d ':' -f 1` + if [[ "$remote" == "$ch"* ]]; then + cl=`echo $cipair | cut -d ':' -f 2` + [ ! -z "$cl" ] && ciph=$cl + fi + done +fi +if [ ! -z "$ciph" ]; then + log using cipher $ciph ... +fi + if [ ! -d $data ]; then log no data directory ... exit -4 @@ -89,35 +111,36 @@ log backing up to $data ... today=`date -I` backupdir=$data/${user}_at_${host} - cbd=$backupdir/$today -mkdir -p $cbd - -rsync="rsync -azR --delete --bwlimit=$bandwidth" ob="" lpb="" for pb in $backupdir/[0-9]*; do + [ ! -d $pb ] && continue bdd=`basename $pb` if [ ! -f $backupdir/.$bdd ]; then if [ "$pb" != "$cbd" ]; then rm -rf $cbd mv $pb $cbd log continuing $pb as $cbd ... - else - if [ ! -z "$lpb" ]; then - rm -rf $cbd - cp -r $lpb $cbd - log "starting backup $today from $lpb ..." - else - log starting backup from scratch ... - fi fi + else + lpb=$pb + ob="$ob $pb" fi - lpb=$pb - ob="$ob $pb" done + +if [ ! -d $cbd ]; then + if [ ! -z "$lpb" ]; then + cp -r $lpb $cbd + log starting backup $today from $lpb ... + else + mkdir -p $cbd + log starting backup $today from scratch ... + fi +fi + if [ ! -f $backupdir/.$today ]; then rsrc="" for dir in $homedirs; do @@ -131,10 +154,20 @@ if [ ! -f $backupdir/.$today ]; then log backing up home directories $homedirs ... [ ! -z "$extradirs" ] && \ log backing up directories $extradirs ... - $rsync $user@$remote$rsrc $cbd + + if [ -z "$ciph" ]; then + rsync=(rsync -aR $rcomp --delete $rbw $user@$remote$rsrc $cbd) + else + rsync=(rsync -aR -e "ssh -c $ciph" $rcomp --delete) + rsync+=($rbw $user@$remote$rsrc $cbd) + fi + res=`"${rsync[@]}" 2>&1` + ret=$? if [ "$ret" != "0" ]; then log backup terminated before completion ... + log reason: + log $res exit -50 fi