From: hackbard Date: Sun, 4 Oct 2015 11:40:47 +0000 (+0000) Subject: enabled old backup removal X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=26b498357009fee67377a8300db277d3a6c3ef02;p=outofuni%2Fbackup.git enabled old backup removal --- diff --git a/bin/backup b/bin/backup index e843da3..b758e14 100755 --- a/bin/backup +++ b/bin/backup @@ -107,7 +107,7 @@ for pb in $backupdir/[0-9]*; do else if [ ! -z "$lpb" ]; then rm -rf $cbd - mv $lpb $cbd + cp -r $lpb $cbd log "starting backup $today from $lpb ..." else log starting backup from scratch ... @@ -144,16 +144,27 @@ else log backup $bdd found completed ... fi +[ -z "$replicas" ] && replicas=3 +[ -z "$oldest" ] && oldest=0 + cob=`echo $ob | wc -w` if [ $cob -gt $replicas ]; then ((numdel=cob-replicas)) todel="`echo $ob | cut -d ' ' -f 1-${numdel}`" - log to delete: $todel - #for dirdel in $todel; do - # bdd=`basename $dirdel` - # rm -r $dirdel - # rm $backupdir/$bdd - #done + for dirdel in $todel; do + past=`basename $dirdel` + ns=`date --date="$today" +%s` + ps=`date --date="$past" +%s` + ((delta=(ns-ps)/86400)) + if [ $delta -gt $oldest ]; then + log "deleting $dirdel ($delta days old) ..." + bdd=`basename $dirdel` + rm -r $dirdel + rm $backupdir/.$bdd + else + log "keeping $dirdel ($delta days old) ..." + fi + done fi exit 0