Change in osmo-ci[master]: contrib/obs-mirror: stop script on rsync error

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Fri Dec 17 18:50:54 UTC 2021


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ci/+/26624 )


Change subject: contrib/obs-mirror: stop script on rsync error
......................................................................

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
---
M contrib/obs-mirror/obs-mirror.sh
1 file changed, 12 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/24/26624/1

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 @@
 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 @@
 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
+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"
+	# update '.previous' for the next run
+	rm -f "$PREVIOUS"
+	ln -sf "$DATE" "$PREVIOUS"
+else
+	exit 1
+fi

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/26624
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: Icfefd8e4bae1fd6c73445c7427aaa842c0391b2d
Gerrit-Change-Number: 26624
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211217/c68c541b/attachment.htm>


More information about the gerrit-log mailing list