aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2021-12-17 18:26:43 +0100
committerOliver Smith <osmith@sysmocom.de>2021-12-17 19:09:35 +0100
commit70d6a263a9a88ed8de8c535fbe955136a1276c7e (patch)
tree97ada697a58cb5424f41f92723a766bc4d88ecf4
parent97700073672ace138a49c1abc89a60ed52bdb792 (diff)
contrib/obs-mirror: stop script on rsync error
Sync files into a temporary directory first, and only rename the temp dir to the final dir name if rsync succeeds. Otherwise, exit with error. Related: SYS#5764 Change-Id: Icfefd8e4bae1fd6c73445c7427aaa842c0391b2d
-rwxr-xr-xcontrib/obs-mirror/obs-mirror.sh22
1 files changed, 13 insertions, 9 deletions
diff --git a/contrib/obs-mirror/obs-mirror.sh b/contrib/obs-mirror/obs-mirror.sh
index 8d25c2d..6ac3484 100755
--- a/contrib/obs-mirror/obs-mirror.sh
+++ b/contrib/obs-mirror/obs-mirror.sh
@@ -22,10 +22,11 @@ cd "$BASE_DIR"
RSYNC_ARGS="-av --delete"
RSYNC_ARGS="$RSYNC_ARGS --files-from $SCRIPT_DIR/obs-mirror-include.txt --recursive"
DATE=`date +%Y%m%d-%H%M%S`
-
-# create output directory
DIR="$BASE_DIR/$DATE"
-mkdir -p "$DIR"
+TEMP_DIR="$BASE_DIR/.temp"
+
+rm -rf "$TEMP_DIR"
+mkdir "$TEMP_DIR"
PREVIOUS="$BASE_DIR/.previous"
if [ -d "$PREVIOUS" ]; then
@@ -33,9 +34,12 @@ if [ -d "$PREVIOUS" ]; then
fi
# finally, perform rsync
-# || true: don't stop here if one of the dirs from the include list does not exist
-rsync $RSYNC_ARGS "$REMOTE"/ "$DIR"/ || true
-
-# update '.previous' for the next run
-rm -f "$PREVIOUS"
-ln -sf "$DATE" "$PREVIOUS"
+if rsync $RSYNC_ARGS "$REMOTE"/ "$TEMP_DIR"/; then
+ mv "$TEMP_DIR" "$DIR"
+
+ # update '.previous' for the next run
+ rm -f "$PREVIOUS"
+ ln -sf "$DATE" "$PREVIOUS"
+else
+ exit 1
+fi