From 12deac25d69b63523507855218d3279ce29ab6eb Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Thu, 14 Nov 2013 19:31:22 -0800 Subject: [PATCH] Correctly handle most recent backup if it's older than 24hs. Code was assuming that you'd run backups hourly, eg, so you'd have many backups within the last 24 hours. Code assumed that by the time you found a backup more than 24h old, you'd already have a value for $prev set. In the event that your most recent backup is more than 24 hours old, $prev would not be set and bash would get an error "unary operator expected" when it tried to compare the day of the newest backup to the empty $prev value. I fix this by setting a default value for $prev, one that cannot be mistaken for an existing backup because it does not represent a valid date. This ensures that the most recent backup is correctly preserved regardless of it's age. --- rsync_tmbackup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 883415c..d260115 100644 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -164,6 +164,8 @@ while [ "1" ]; do # Purge certain old backups before beginning new backup. # ----------------------------------------------------------------------------- + # Default value for $prev ensures that the most recent backup is never deleted. + prev="0000-00-00-000000" for fname in $(fn_find_backups | sort -r); do date=$(basename "$fname") stamp=$(fn_parse_date $date)