From da904fe66ce384ff3f844fdfc81b6a4d95410d9a Mon Sep 17 00:00:00 2001 From: omer-musa-battal <34798379+omer-musa-battal@users.noreply.github.com> Date: Sun, 29 Sep 2019 17:57:59 +0300 Subject: File existence and file system type checks (#170) Added error checking for nonexistent source file. Also added file system type checks for destination and source, rsync flags are updated accordingly. --- rsync_tmbackup.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/rsync_tmbackup.sh b/rsync_tmbackup.sh index addda70..4d4dfab 100755 --- a/rsync_tmbackup.sh +++ b/rsync_tmbackup.sh @@ -208,6 +208,15 @@ fn_run_cmd() { fi } +fn_run_cmd_src() { + if [ -n "$SSH_SRC_FOLDER_PREFIX" ] + then + eval "$SSH_CMD '$1'" + else + eval $1 + fi +} + fn_find() { fn_run_cmd "find '$1'" 2>/dev/null } @@ -237,6 +246,18 @@ fn_ln() { fn_run_cmd "ln -s -- '$1' '$2'" } +fn_test_file_exists_src() { + fn_run_cmd_src "test -e '$1'" +} + +fn_df_t_src() { + fn_run_cmd_src "df -T '${1}'" +} + +fn_df_t() { + fn_run_cmd "df -T '${1}'" +} + # ----------------------------------------------------------------------------- # Source and destination information # ----------------------------------------------------------------------------- @@ -347,6 +368,12 @@ if [ -n "$SSH_SRC_FOLDER" ]; then SRC_FOLDER="$SSH_SRC_FOLDER" fi +# Exit if source folder does not exist. +if ! fn_test_file_exists_src ${SRC_FOLDER}; then + fn_log_error "Source folder \"${SRC_FOLDER}\" does not exist - aborting." + exit 1 +fi + # Now strip off last slash from source folder. SRC_FOLDER="${SRC_FOLDER%/}" @@ -375,6 +402,22 @@ if [ -z "$(fn_find_backup_marker "$DEST_FOLDER")" ]; then exit 1 fi +# Check source and destination file-system (df -T /dest). +# If one of them is FAT, use the --modify-window rsync parameter +# (see man rsync) with a value of 1 or 2. +# +# The check is performed by taking the second row +# of the output of the first command. +if [[ "$(fn_df_t_src "${SRC_FOLDER}" | awk '{print $2}' | grep -c -i -e "fat")" -gt 0 ]]; then + fn_log_info "Source file-system is a version of FAT." + fn_log_info "Using the --modify-window rsync parameter with value 2." + RSYNC_FLAGS="${RSYNC_FLAGS} --modify-window=2" +elif [[ "$(fn_df_t "${DEST_FOLDER}" | awk '{print $2}' | grep -c -i -e "fat")" -gt 0 ]]; then + fn_log_info "Destination file-system is a version of FAT." + fn_log_info "Using the --modify-window rsync parameter with value 2." + RSYNC_FLAGS="${RSYNC_FLAGS} --modify-window=2" +fi + # ----------------------------------------------------------------------------- # Setup additional variables # ----------------------------------------------------------------------------- -- cgit v1.2.3