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 ...
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