From e7efac5564221f6be04a2df824b3843cd6ff3646 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Fri, 11 Jun 2021 21:56:18 +0200 Subject: [PATCH] cleanup: use explicit tests instead of ...IfError The ...IfError functions have multiple problems, see the comments at their definition. --- .../RSYNC/GNU/Linux/620_force_autorelabel.sh | 3 +- .../RSYNC/default/200_make_prefix_dir.sh | 14 ++++------ .../RSYNC/default/900_copy_result_files.sh | 28 +++++++++---------- .../prep/RSYNC/default/100_check_rsync.sh | 11 ++++---- .../150_check_rsync_protocol_version.sh | 8 +++--- .../550_check_remote_backup_archive.sh | 8 +++--- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh b/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh index 13c6704224..99c921337e 100644 --- a/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh +++ b/usr/share/rear/backup/RSYNC/GNU/Linux/620_force_autorelabel.sh @@ -37,8 +37,7 @@ local backup_prog_rc # probably using the BACKUP=NETFS workflow instead if [ -d "${opath}" ]; then if [ ! -f "${opath}/selinux.autorelabel" ]; then - > "${opath}/selinux.autorelabel" - StopIfError "Failed to create selinux.autorelabel on ${opath}" + > "${opath}/selinux.autorelabel" || Error "Failed to create selinux.autorelabel on ${opath}" fi fi ;; diff --git a/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh b/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh index 32ac391d77..50c71171f1 100644 --- a/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh +++ b/usr/share/rear/output/RSYNC/default/200_make_prefix_dir.sh @@ -2,21 +2,19 @@ # RSYNC_PREFIX=$HOSTNAME as set in default.conf # create temporary local work-spaces to collect files (we already make the remote backup dir with the correct mode!!) -mkdir -p $v -m0750 "${TMP_DIR}/rsync/${RSYNC_PREFIX}" >&2 -StopIfError "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}'" -mkdir -p $v -m0755 "${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup" >&2 -StopIfError "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup'" +mkdir -p $v -m0750 "${TMP_DIR}/rsync/${RSYNC_PREFIX}" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}'" +mkdir -p $v -m0755 "${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup" >&2 || Error "Could not mkdir '${TMP_DIR}/rsync/${RSYNC_PREFIX}/backup'" case $RSYNC_PROTO in (ssh) - $BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}" >/dev/null 2>&1 - StopIfError "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}" + $BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}" >/dev/null 2>&1 \ + || Error "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}" ;; (rsync) - $BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" ${BACKUP_RSYNC_OPTIONS[@]} "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/" >/dev/null - StopIfError "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}" + $BACKUP_PROG -a $v -r "${TMP_DIR}/rsync/${RSYNC_PREFIX}" ${BACKUP_RSYNC_OPTIONS[@]} "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/" >/dev/null \ + || Error "Could not create '${RSYNC_PATH}/${RSYNC_PREFIX}' on remote ${RSYNC_HOST}" ;; esac diff --git a/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh b/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh index cbd57bc9de..65117142fc 100644 --- a/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh +++ b/usr/share/rear/output/RSYNC/default/900_copy_result_files.sh @@ -6,18 +6,18 @@ LogPrint "Copying resulting files to $OUTPUT_URL location" # if called as mkbackuponly then we just don't have any result files. if test "$RESULT_FILES" ; then Log "Copying files '${RESULT_FILES[@]}' to $OUTPUT_URL location" - cp $v "${RESULT_FILES[@]}" "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" - StopIfError "Could not copy files to local rsync location" + cp $v "${RESULT_FILES[@]}" "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" \ + || Error "Could not copy files to local rsync location" fi -echo "$VERSION_INFO" >"${TMP_DIR}/rsync/${RSYNC_PREFIX}/VERSION" -StopIfError "Could not create VERSION file on local rsync location" +echo "$VERSION_INFO" >"${TMP_DIR}/rsync/${RSYNC_PREFIX}/VERSION" \ + || Error "Could not create VERSION file on local rsync location" -cp $v $(get_template "RESULT_usage_$OUTPUT.txt") "${TMP_DIR}/rsync/${RSYNC_PREFIX}/README" -StopIfError "Could not copy usage file to local rsync location" +cp $v $(get_template "RESULT_usage_$OUTPUT.txt") "${TMP_DIR}/rsync/${RSYNC_PREFIX}/README" \ + || Error "Could not copy usage file to local rsync location" -cat "$RUNTIME_LOGFILE" >"${TMP_DIR}/rsync/${RSYNC_PREFIX}/rear.log" -StopIfError "Could not copy $RUNTIME_LOGFILE to local rsync location" +cat "$RUNTIME_LOGFILE" >"${TMP_DIR}/rsync/${RSYNC_PREFIX}/rear.log" \ + || Error "Could not copy $RUNTIME_LOGFILE to local rsync location" case $RSYNC_PROTO in @@ -25,20 +25,20 @@ case $RSYNC_PROTO in Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ ${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/" # FIXME: Add an explanatory comment why "2>/dev/null" is useful here # or remove it according to https://github.com/rear/rear/issues/1395 - $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null - StopIfError "Could not copy '${RESULT_FILES[@]}' to $OUTPUT_URL location" + $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" "${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null \ + || Error "Could not copy '${RESULT_FILES[@]}' to $OUTPUT_URL location" ;; (rsync) Log "$BACKUP_PROG -a ${TMP_DIR}/rsync/${RSYNC_PREFIX}/ ${BACKUP_RSYNC_OPTIONS[@]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/" # FIXME: Add an explanatory comment why "2>/dev/null" is useful here # or remove it according to https://github.com/rear/rear/issues/1395 - $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" ${BACKUP_RSYNC_OPTIONS[@]} "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null - StopIfError "Could not copy '${RESULT_FILES[@]}' to $OUTPUT_URL location" + $BACKUP_PROG -a "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" ${BACKUP_RSYNC_OPTIONS[@]} "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/" 2>/dev/null \ + || Error "Could not copy '${RESULT_FILES[@]}' to $OUTPUT_URL location" ;; esac # cleanup the temporary space (need it for the log file during backup) -rm -rf "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" -LogIfError "Could not cleanup temporary rsync space: ${TMP_DIR}/rsync/${RSYNC_PREFIX}/" +rm -rf "${TMP_DIR}/rsync/${RSYNC_PREFIX}/" \ + || Log "Could not cleanup temporary rsync space: ${TMP_DIR}/rsync/${RSYNC_PREFIX}/" diff --git a/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh b/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh index b853535251..caa62a6bad 100644 --- a/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh +++ b/usr/share/rear/prep/RSYNC/default/100_check_rsync.sh @@ -79,8 +79,7 @@ esac # check if host is reachable if test "$PING" ; then - ping -c 2 "$RSYNC_HOST" >/dev/null - StopIfError "Backup host [$RSYNC_HOST] not reachable." + ping -c 2 "$RSYNC_HOST" >/dev/null || Error "Backup host [$RSYNC_HOST] not reachable." else Log "Skipping ping test" fi @@ -90,14 +89,14 @@ case "$RSYNC_PROTO" in (rsync) Log "Test: $BACKUP_PROG ${BACKUP_RSYNC_OPTIONS[@]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/" - $BACKUP_PROG ${BACKUP_RSYNC_OPTIONS[@]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/ >/dev/null - StopIfError "Rsync daemon not running on $RSYNC_HOST" + $BACKUP_PROG ${BACKUP_RSYNC_OPTIONS[@]} ${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/ >/dev/null \ + || Error "Rsync daemon not running on $RSYNC_HOST" ;; (ssh) Log "Test: ssh ${RSYNC_USER}@${RSYNC_HOST} /bin/true" - ssh ${RSYNC_USER}@${RSYNC_HOST} /bin/true >/dev/null 2>&1 - StopIfError "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]" + ssh ${RSYNC_USER}@${RSYNC_HOST} /bin/true >/dev/null 2>&1 \ + || Error "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]" ;; esac diff --git a/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh b/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh index a3cbd2033c..82fabb180e 100644 --- a/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh +++ b/usr/share/rear/prep/RSYNC/default/150_check_rsync_protocol_version.sh @@ -10,8 +10,8 @@ if [ -z "$RSYNC_PROTOCOL_VERSION" ]; then case $RSYNC_PROTO in (ssh) - ssh ${RSYNC_USER}@${RSYNC_HOST} rsync --version >"$TMP_DIR/rsync_protocol" 2>&1 - StopIfError "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]" + ssh ${RSYNC_USER}@${RSYNC_HOST} rsync --version >"$TMP_DIR/rsync_protocol" 2>&1 \ + || Error "Secure shell connection not setup properly [$RSYNC_USER@$RSYNC_HOST]" grep -q "protocol version" "$TMP_DIR/rsync_protocol" if [ $? -eq 0 ]; then RSYNC_PROTOCOL_VERSION=$(grep 'protocol version' "$TMP_DIR/rsync_protocol" | awk '{print $6}') @@ -41,8 +41,8 @@ if [ "${RSYNC_USER}" != "root" ]; then else # when using --fake-super we must have user_xattr mount options on the remote mntpt remote_mountpoint=$(ssh ${RSYNC_USER}@${RSYNC_HOST} 'cd ${RSYNC_PATH}; df -P .' 2>/dev/null | tail -1 | awk '{print $6}') - ssh ${RSYNC_USER}@${RSYNC_HOST} "cd ${RSYNC_PATH} && touch .is_xattr_supported && setfattr -n user.comment -v 'File created by ReaR to test if this filesystems supports extended attributes.' .is_xattr_supported && getfattr -n user.comment .is_xattr_supported 1>/dev/null; find .is_xattr_supported -empty -delete" - StopIfError "Remote file system $remote_mountpoint does not have user_xattr mount option set!" + ssh ${RSYNC_USER}@${RSYNC_HOST} "cd ${RSYNC_PATH} && touch .is_xattr_supported && setfattr -n user.comment -v 'File created by ReaR to test if this filesystems supports extended attributes.' .is_xattr_supported && getfattr -n user.comment .is_xattr_supported 1>/dev/null; find .is_xattr_supported -empty -delete" \ + || Error "Remote file system $remote_mountpoint does not have user_xattr mount option set!" #BACKUP_RSYNC_OPTIONS+=( --xattrs --rsync-path="rsync --fake-super" ) # see issue #366 for explanation of removing --xattrs BACKUP_RSYNC_OPTIONS+=( --rsync-path="rsync --fake-super" ) diff --git a/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh b/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh index 47ed9e026c..b2fb72f509 100644 --- a/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh +++ b/usr/share/rear/verify/RSYNC/default/550_check_remote_backup_archive.sh @@ -3,12 +3,12 @@ case $RSYNC_PROTO in (ssh) - ssh ${RSYNC_USER}@${RSYNC_HOST} "ls -ld ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 - StopIfError "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]" + ssh ${RSYNC_USER}@${RSYNC_HOST} "ls -ld ${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 \ + || Error "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]" ;; (rsync) - $BACKUP_PROG "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 - StopIfError "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]" + $BACKUP_PROG "${RSYNC_PROTO}://${RSYNC_USER}@${RSYNC_HOST}:${RSYNC_PORT}/${RSYNC_PATH}/${RSYNC_PREFIX}/backup" >/dev/null 2>&1 \ + || Error "Archive not found on [$RSYNC_USER@$RSYNC_HOST:${RSYNC_PATH}/${RSYNC_PREFIX}]" ;; esac