Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions rsync_tmbackup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,24 @@ fn_test_file_exists_src() {
fn_run_cmd_src "test -e '$1'"
}

# Outputs 0 if given directory is not a type of FAT filesystem.
# Outputs greater than 0 otherwise. Has to be implemented for different OSes.
fn_df_t_src() {
fn_run_cmd_src "df -T '${1}'"
OSTYPE_STR="$(fn_run_cmd_src 'echo ${OSTYPE}')"
case "${OSTYPE_STR}" in
linux*) fn_run_cmd_src "df -T '${1}' | awk 'NR==2' | awk '{print \$2}' | grep -c -i -e 'fat'" ;;
darwin*) fn_run_cmd_src "df -T msdos,exfat ${1} | awk 'NR==2' | grep -c -e '${1%/}'" ;;
*) echo 0 ;; # not implemented OSes, do not perform check.
esac
}

fn_df_t() {
fn_run_cmd "df -T '${1}'"
OSTYPE_STR="$(fn_run_cmd 'echo ${OSTYPE}')"
case "${OSTYPE_STR}" in
linux*) fn_run_cmd "df -T '${1}' | awk 'NR==2' | awk '{print \$2}' | grep -c -i -e 'fat'" ;;
darwin*) fn_run_cmd "df -T msdos,exfat ${1} | awk 'NR==2' | grep -c -e '${1%/}'" ;;
*) echo 0 ;; # not implemented OSes, do not perform check.
esac
}

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -369,7 +381,7 @@ if [ -n "$SSH_SRC_FOLDER" ]; then
fi

# Exit if source folder does not exist.
if ! fn_test_file_exists_src ${SRC_FOLDER}; then
if ! fn_test_file_exists_src "${SRC_FOLDER}"; then
fn_log_error "Source folder \"${SRC_FOLDER}\" does not exist - aborting."
exit 1
fi
Expand Down Expand Up @@ -406,13 +418,12 @@ fi
# 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_df_t commands output 0 when disk is not FAT, and >0 otherwise.
if [[ "$(fn_df_t_src "${SRC_FOLDER}/")" -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
elif [[ "$(fn_df_t "${DEST_FOLDER}/")" -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"
Expand Down