X-Git-Url: https://git.distorted.org.uk/~mdw/rsync-backup/blobdiff_plain/e0ff797b44481f8e84a16ce7af0ab5be2a4b244e..9e224eb10854cbc51964722b2a79ea89d7390fba:/rsync-backup.in diff --git a/rsync-backup.in b/rsync-backup.in index d7267ca..a9145d6 100644 --- a/rsync-backup.in +++ b/rsync-backup.in @@ -177,6 +177,30 @@ runhook () { done } +remove_old_logfiles () { + base=$1 + ## Remove old logfiles with names of the form BASE.DATE#N, so that there + ## are at most $MAXLOG of them. + + ## Count up the logfiles. + nlog=0 + for i in "$base".*; do + if [ ! -f "$i" ]; then continue; fi + nlog=$(( nlog + 1 )) + done + + ## If there are too many, go through and delete some early ones. + if [ $dryrun = nil ] && [ $nlog -gt $MAXLOG ]; then + n=$(( nlog - MAXLOG )) + for i in "$base".*; do + if [ ! -f "$i" ]; then continue; fi + rm -f "$i" + n=$(( n - 1 )) + if [ $n -eq 0 ]; then break; fi + done + fi +} + ###-------------------------------------------------------------------------- ### Database operations. @@ -744,23 +768,8 @@ run_backup_cmd () { bkprc=1 fi - ## Count up the logfiles. - nlog=0 - for i in "$logdir/$host/$fs".*; do - if [ ! -f "$i" ]; then continue; fi - nlog=$(( nlog + 1 )) - done - - ## If there are too many, go through and delete some early ones. - if [ $dryrun = nil ] && [ $nlog -gt $MAXLOG ]; then - n=$(( nlog - MAXLOG )) - for i in "$logdir/$host/$fs".*; do - if [ ! -f "$i" ]; then continue; fi - rm -f "$i" - n=$(( n - 1 )) - if [ $n -eq 0 ]; then break; fi - done - fi + ## Clear away any old logfiles. + remove_old_logfiles "$logdir/$host/$fs" } backup () {