diff options
| author | Laurent <laurent@pogopixels.com> | 2013-12-21 02:26:32 -0800 |
|---|---|---|
| committer | Laurent <laurent@pogopixels.com> | 2013-12-21 02:26:32 -0800 |
| commit | c105c0a9e26ecac7aec7a6c25d87f6ce9d05d988 (patch) | |
| tree | 7572a9538d6e57b3c72923c936c307586aa12490 | |
| parent | 7b9de2b5f55e2c4ccd601cb1ccf28a55249c3b0f (diff) | |
| parent | c8ae23490478a014696ea78f8d662e6ab07ed5eb (diff) | |
Merge pull request #27 from bhuvi8/master
Added rsync error handling and modified WARN and ERROR functions to print to stderr
| -rwxr-xr-x[-rw-r--r--] | rsync_tmbackup.sh | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index b2131c9..dc108e1 100644..100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -7,8 +7,8 @@ APPNAME=$(basename $0 | sed "s/\.sh$//") # ----------------------------------------------------------------------------- fn_log_info() { echo "$APPNAME: $1"; } -fn_log_warn() { echo "$APPNAME: [WARNING] $1"; } -fn_log_error() { echo "$APPNAME: [ERROR] $1"; } +fn_log_warn() { echo "$APPNAME: [WARNING] $1" 1>&2; } +fn_log_error() { echo "$APPNAME: [ERROR] $1" 1>&2; } # ----------------------------------------------------------------------------- # Make sure everything really stops when CTRL+C is pressed @@ -214,7 +214,6 @@ while : ; do touch -- "$INPROGRESS_FILE" eval $CMD - RSYNC_EXIT_CODE=$? # ----------------------------------------------------------------------------- # Check if we ran out of space @@ -223,8 +222,6 @@ while : ; do # TODO: find better way to check for out of space condition without parsing log. NO_SPACE_LEFT="$(grep "No space left on device (28)\|Result too large (34)" "$LOG_FILE")" - rm -- "$LOG_FILE" - if [ -n "$NO_SPACE_LEFT" ]; then fn_log_warn "No space left on device - removing oldest backup and resuming." @@ -239,9 +236,12 @@ while : ; do continue fi - if [ "$RSYNC_EXIT_CODE" != "0" ]; then - fn_log_error "Exited with error code $RSYNC_EXIT_CODE" - exit $RSYNC_EXIT_CODE + # ----------------------------------------------------------------------------- + # Check whether rsync reported any errors + # ----------------------------------------------------------------------------- + if [[ "$(sed -n '/rsync error:/p;/rsync:/p' -- "$LOG_FILE" | wc -l)" -ge 1 ]]; then + fn_log_error "Encountered error, please check $LOG_FILE for more details." + exit 1 fi # ----------------------------------------------------------------------------- @@ -252,7 +252,9 @@ while : ; do ln -vs -- "$(basename -- "$DEST")" "$DEST_FOLDER/latest" rm -f -- "$INPROGRESS_FILE" - # TODO: grep for "^rsync error:.*$" in log + rm -- "$LOG_FILE" + fn_log_info "Backup completed without errors." + exit 0 done |
