From fbf25018bea6b5cb630ee15b401b385d5e9f7084 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Thu, 10 May 2012 21:03:37 -0300 Subject: Set/restore pipefail to not mess with other scripts (#3892) --- handlers/rsync.in | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/handlers/rsync.in b/handlers/rsync.in index 73507c8..85e1c99 100644 --- a/handlers/rsync.in +++ b/handlers/rsync.in @@ -1100,6 +1100,28 @@ function end_mux { } +function set_pipefail { + + # Save initial pipefail status for later restoration + if echo "$SHELLOPTS" | grep -q ":pipefail"; then + pipefail="-o" + else + pipefail="+o" + fi + + # Ensure that a non-zero rsync exit status is caught by our handler + set -o pipefail + +} + +function restore_pipefail { + + if [ ! -z "$pipefail" ]; then + set $pipefail pipefail + fi + +} + # the backup procedure eval_config @@ -1109,6 +1131,7 @@ set_rsync_options start_mux stop_services mount_rw +set_pipefail starttime="`date +%c%n%s`" echo "Starting backup at `echo $starttime | head -n 1`" >> $log @@ -1121,9 +1144,6 @@ for SECTION in $include; do set_filelist set_dest - # Ensure that a non-zero rsync exit status is caught by our handler - set -o pipefail - info "Syncing $SECTION on $dest_path..." debug $nice $rsync "${rsync_options[@]}" $filelist_flag $excludes $batch_option $orig $dest_path $nice $rsync "${rsync_options[@]}" $filelist_flag $excludes $batch_option $orig $dest_path | tee -a $log @@ -1136,6 +1156,7 @@ for SECTION in $include; do done +restore_pipefail mount_ro run_fsck start_services -- cgit v1.2.3