Implement fn_expire_backups to reduce code duplication.
This commit is contained in:
+10
-6
@@ -122,6 +122,11 @@ if [ -f "$INPROGRESS_FILE" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
fn_expire_backup() {
|
||||||
|
fn_log_info "Expiring $1"
|
||||||
|
echo rm -rf -- "$1"
|
||||||
|
}
|
||||||
|
|
||||||
# Run in a loop to handle the "No space left on device" logic.
|
# Run in a loop to handle the "No space left on device" logic.
|
||||||
while [ "1" ]; do
|
while [ "1" ]; do
|
||||||
|
|
||||||
@@ -165,11 +170,11 @@ while [ "1" ]; do
|
|||||||
|
|
||||||
elif [ $stamp -ge $KEEP_DAILIES_DATE ]; then
|
elif [ $stamp -ge $KEEP_DAILIES_DATE ]; then
|
||||||
# Delete all but the most recent of each day.
|
# Delete all but the most recent of each day.
|
||||||
[ ${date:8:2} -eq ${prev:8:2} ] && echo rm -rf -- "$DEST_FOLDER/$date"
|
[ ${date:8:2} -eq ${prev:8:2} ] && fn_expire_backup "$fname"
|
||||||
|
|
||||||
else
|
else
|
||||||
# Delete all but the most recent of each month.
|
# Delete all but the most recent of each month.
|
||||||
[ ${date:5:2} -eq ${prev:5:2} ] && echo rm -rf -- "$DEST_FOLDER/$date"
|
[ ${date:5:2} -eq ${prev:5:2} ] && fn_expire_backup "$fname"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
prev=$date
|
prev=$date
|
||||||
@@ -237,13 +242,13 @@ while [ "1" ]; do
|
|||||||
|
|
||||||
fn_log_warn "No space left on device - removing oldest backup and resuming."
|
fn_log_warn "No space left on device - removing oldest backup and resuming."
|
||||||
|
|
||||||
BACKUP_FOLDER_COUNT=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | wc -l)
|
BACKUP_FOLDER_COUNT=$(fn_find_backups | wc -l)
|
||||||
if [ "$BACKUP_FOLDER_COUNT" -lt "2" ]; then
|
if [ "$BACKUP_FOLDER_COUNT" -lt "2" ]; then
|
||||||
fn_log_error "No space left on device, and no old backup to delete."
|
fn_log_error "No space left on device, and no old backup to delete."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
OLD_BACKUP_PATH=$(find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune | head -n 1)
|
OLD_BACKUP_PATH=$(fn_find_backups | head -n 1)
|
||||||
if [ "$OLD_BACKUP_PATH" == "" ]; then
|
if [ "$OLD_BACKUP_PATH" == "" ]; then
|
||||||
fn_log_error "No space left on device, and cannot get path to oldest backup to delete."
|
fn_log_error "No space left on device, and cannot get path to oldest backup to delete."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -256,8 +261,7 @@ while [ "1" ]; do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fn_log_info "Deleting '$OLD_BACKUP_PATH'..."
|
fn_expire_backup "$OLD_BACKUP_PATH"
|
||||||
rm -rf -- "$OLD_BACKUP_PATH"
|
|
||||||
|
|
||||||
# Resume backup
|
# Resume backup
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user