From 8bb5b3f2650282330e400cf88839be02e6830029 Mon Sep 17 00:00:00 2001 From: Robert Bruce Park Date: Wed, 13 Nov 2013 10:21:47 -0800 Subject: [PATCH] Rearrange function definitions. --- rsync_tmbackup.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index 00fab0d..1413db8 100644 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -28,13 +28,26 @@ fn_terminate_script() { trap 'fn_terminate_script' SIGINT # ----------------------------------------------------------------------------- -# Source and destination information +# Small utility functions for reducing code duplication # ----------------------------------------------------------------------------- fn_parse_date() { date -d "${1:0:10} ${1:11:2}:${1:13:2}:${1:15:2}" +%s } +fn_find_backups() { + find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune +} + +fn_expire_backup() { + fn_log_info "Expiring $1" + echo rm -rf -- "$1" +} + +# ----------------------------------------------------------------------------- +# Source and destination information +# ----------------------------------------------------------------------------- + SRC_FOLDER=${1%/} DEST_FOLDER=${2%/} EXCLUSION_FILE=$3 @@ -78,10 +91,6 @@ fi # Setup additional variables # ----------------------------------------------------------------------------- -fn_find_backups() { - find "$DEST_FOLDER" -type d -name "$BACKUP_FOLDER_PATTERN" -prune -} - export IFS=$'\n' # Better for handling spaces in filenames. BACKUP_FOLDER_PATTERN=????-??-??-?????? NOW=$(date +"%Y-%m-%d-%H%M%S") @@ -122,11 +131,6 @@ if [ -f "$INPROGRESS_FILE" ]; then 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. while [ "1" ]; do