]> hackdaworld.org Git - outofuni/backup.git/commitdiff
enabled old backup removal
authorhackbard <hackbard@hackdaworld.org>
Sun, 4 Oct 2015 11:40:47 +0000 (11:40 +0000)
committerhackbard <hackbard@hackdaworld.org>
Sun, 4 Oct 2015 11:40:47 +0000 (11:40 +0000)
bin/backup

index e843da37fdd2ef425fab7b62c33e6367431bc90a..b758e14f7d464a473c1fb258ade844346e2f1e1a 100755 (executable)
@@ -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