Added rsync error handling and modified WARN and ERROR functions to print to

stderr
This commit is contained in:
bhuvi8
2013-12-17 02:15:43 +05:30
parent 7b9de2b5f5
commit 25ad8f07a6
Regular → Executable
+11 -4
View File
@@ -7,8 +7,8 @@ APPNAME=$(basename $0 | sed "s/\.sh$//")
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
fn_log_info() { echo "$APPNAME: $1"; } fn_log_info() { echo "$APPNAME: $1"; }
fn_log_warn() { echo "$APPNAME: [WARNING] $1"; } fn_log_warn() { echo "$APPNAME: [WARNING] $1" 1>&2; }
fn_log_error() { echo "$APPNAME: [ERROR] $1"; } fn_log_error() { echo "$APPNAME: [ERROR] $1" 1>&2; }
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Make sure everything really stops when CTRL+C is pressed # Make sure everything really stops when CTRL+C is pressed
@@ -223,7 +223,7 @@ while : ; do
# TODO: find better way to check for out of space condition without parsing log. # 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")" NO_SPACE_LEFT="$(grep "No space left on device (28)\|Result too large (34)" "$LOG_FILE")"
rm -- "$LOG_FILE" #rm -- "$LOG_FILE"
if [ -n "$NO_SPACE_LEFT" ]; then if [ -n "$NO_SPACE_LEFT" ]; then
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."
@@ -252,7 +252,14 @@ while : ; do
ln -vs -- "$(basename -- "$DEST")" "$DEST_FOLDER/latest" ln -vs -- "$(basename -- "$DEST")" "$DEST_FOLDER/latest"
rm -f -- "$INPROGRESS_FILE" rm -f -- "$INPROGRESS_FILE"
# TODO: grep for "^rsync error:.*$" in log
# -----------------------------------------------------------------------------
# Check whether rsync reported any errors
# -----------------------------------------------------------------------------
if [[ "$(sed -n '/rsync error:/p;/rsync:/p' -- "$LOG_FILE" | wc -l)" -ge 1 ]]; then
fn_log_error "rsync encountered error, please check $LOG_FILE for more details."
else
fn_log_info "Backup completed without errors." fn_log_info "Backup completed without errors."
fi
exit 0 exit 0
done done