aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2012-05-10 21:03:37 -0300
committerSilvio Rhatto <rhatto@riseup.net>2012-05-10 21:03:37 -0300
commitfbf25018bea6b5cb630ee15b401b385d5e9f7084 (patch)
treef34f39893d2796bcc7da1f088847175b676510e6
parentc43bac5911f8d97044b505466f21ed87f43d84fc (diff)
downloadbackupninja-fbf25018bea6b5cb630ee15b401b385d5e9f7084.tar.gz
backupninja-fbf25018bea6b5cb630ee15b401b385d5e9f7084.tar.bz2
Set/restore pipefail to not mess with other scripts (#3892)
-rw-r--r--handlers/rsync.in27
1 files 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