mirror of
https://github.com/laurent22/rsync-time-backup
synced 2024-12-14 14:12:29 +00:00
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.
This commit is contained in:
parent
855c77a83f
commit
12deac25d6
1 changed files with 2 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue