From c4098e64396d324603341045ca54f8c19caa993b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 6 Mar 2014 09:58:08 +0000 Subject: [PATCH] rsync-backup.in: Factor out log file expiry into a separate function. No real use for this yet, but it's tidier this way. --- rsync-backup.in | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) 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 () { -- 2.11.0