diff options
author | Oliver Smith <osmith@sysmocom.de> | 2021-12-17 18:26:43 +0100 |
---|---|---|
committer | laforge <laforge@osmocom.org> | 2021-12-20 13:35:19 +0000 |
commit | e3aaae199f007b9f583856a392a6369c5effe59a (patch) | |
tree | 4a407642059ffa2cd79f2859262aca45ccd4dba7 | |
parent | 68896ff0ae74e26e61e6979ecd07ccb27842b1b7 (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-x | contrib/obs-mirror/obs-mirror.sh | 22 |
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 |