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/.

laforge gerrit-no-reply at lists.osmocom.org
Mon Dec 20 13:35:21 UTC 2021


laforge has submitted this change. ( 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(-)

Approvals:
  laforge: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



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: 2
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211220/872f59d6/attachment.htm>


More information about the gerrit-log mailing list