fix dest path when using filters
This commit is contained in:
parent
ca20881999
commit
fa7b4d89ee
67
msynk.sh
67
msynk.sh
@ -26,8 +26,8 @@ mkrypt=/usr/bin/mkrypt
|
||||
mkrypt_flags=()
|
||||
|
||||
rsync_flags=(-ruh)
|
||||
# rsync_flags+=(--rsh="ssh -p 42")
|
||||
# r - relative
|
||||
# rsync_flags+=(--rsh="ssh -p 22")
|
||||
# r - recursive
|
||||
# v - verbose
|
||||
# Ut - preserve modification&access times
|
||||
# u - update, skip files that are newer on the receiver
|
||||
@ -75,6 +75,27 @@ check_path_in_args()
|
||||
}
|
||||
|
||||
|
||||
_sync_set_dest() {
|
||||
if [[ -d "$path" ]]; then
|
||||
if [[ -n "$relative" ]]; then
|
||||
dest="$receiver"
|
||||
else
|
||||
dest="$receiver"$(basename "$path")
|
||||
fi
|
||||
elif [[ -f $path ]]; then
|
||||
dest="$receiver"
|
||||
elif [[ "$sender" == *:* ]]; then # if sender is remote, assume the path is a dir if it has a slash and a file otherwise
|
||||
if [[ "$path" == *\/ ]]; then
|
||||
dest="$receiver"$(basename "$path")
|
||||
else
|
||||
dest="$receiver"
|
||||
fi
|
||||
else
|
||||
printf "$FMT_ERROR" "Invalid path: $path"; exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# SYNC SENDER TO RECEIVER
|
||||
sync_sender_to_receiver()
|
||||
{
|
||||
@ -83,8 +104,14 @@ sync_sender_to_receiver()
|
||||
[[ $v -ge 1 ]] && printf "$FMT_MESSAGE" "Performing dryrun" "to generate list of files that will be deleted from $receiver..."
|
||||
echo "" > $TMP_FILE
|
||||
for path in "${filtered_paths[@]}"; do
|
||||
dest_subdir=$receiver$(basename $path)
|
||||
rsync "${rsync_flags[@]}" -v --dry-run --delete $path $dest_subdir | grep deleting | sed "s(deleting (${BACKUP_SUBDIR}/(" >> $TMP_FILE
|
||||
_sync_set_dest
|
||||
# if [ -n $relative ]; then
|
||||
# dest_subdir="$receiver"
|
||||
# else
|
||||
# dest_subdir="$receiver"$(basename "$path")
|
||||
# fi
|
||||
[[ $v -ge 3 ]] && printf "$FMT_CMD" "rsync ${rsync_flags[*]} -v --dry-run --delete $path $dest | grep deleting | sed \"s(deleting (${BACKUP_SUBDIR}/(\" >> $TMP_FILE"
|
||||
rsync "${rsync_flags[@]}" -v --dry-run --delete $path $dest | grep deleting | sed "s(deleting (${BACKUP_SUBDIR}/(" >> $TMP_FILE
|
||||
done
|
||||
# print files that will be deleted and ask if continue
|
||||
# grep deleting $TMP_FILE | sed "s(deleting (${receiver}/(" | less
|
||||
@ -115,15 +142,21 @@ sync_sender_to_receiver()
|
||||
# actual syncing
|
||||
for path in "${filtered_paths[@]}"; do
|
||||
[[ $v -ge 1 ]] && printf "$FMT_SYNC" "$path"
|
||||
if [[ -d "$path" ]]; then
|
||||
dest="$receiver"$(basename "$path")
|
||||
elif [[ -f $path ]]; then
|
||||
dest="$receiver"
|
||||
elif [[ "$sender" == *:* ]]; then # if sender is remote, assume the path is a dir if it has a slash and a file otherwise
|
||||
[[ "$path" == *"/" ]] && dest="$receiver"$(basename "$path") || dest="$receiver"
|
||||
else
|
||||
printf "$FMT_ERROR" "Invalid path: $path"; exit 1
|
||||
fi
|
||||
_sync_set_dest
|
||||
#if [[ -d "$path" ]]; then
|
||||
# if [[ -n "$relative" ]]; then
|
||||
# dest="$receiver"
|
||||
# else
|
||||
# dest="$receiver"$(basename "$path")
|
||||
# fi
|
||||
#elif [[ -f $path ]]; then
|
||||
# dest="$receiver"
|
||||
#elif [[ "$sender" == *:* ]]; then # if sender is remote, assume the path is a dir if it has a slash and a file otherwise
|
||||
# #[[ "$path" == *"/" ]] && dest="$receiver"$(basename "$path") || dest="$receiver"
|
||||
# dest=$receiver
|
||||
#else
|
||||
# printf "$FMT_ERROR" "Invalid path: $path"; exit 1
|
||||
#fi
|
||||
if [[ -n $encrypt || -n $decrypt ]]; then
|
||||
mkdir -p "$TMP_DIR"
|
||||
tmp_source="$TMP_DIR"
|
||||
@ -323,6 +356,9 @@ while (( "$#" )); do
|
||||
--exclude)
|
||||
exclude=1
|
||||
shift ;;
|
||||
-R|--relative)
|
||||
relative=1
|
||||
shift ;;
|
||||
-*|--*=) # unsupported flags
|
||||
printf "$FMT_ERROR" "Unsupported flag $1" >&2
|
||||
exit 1 ;;
|
||||
@ -404,6 +440,11 @@ fi
|
||||
[[ $v -ge 3 ]] && printf "$FMT_MESSAGE" "Filtered paths:" "${filtered_paths[*]}"
|
||||
IFS=$ifs
|
||||
|
||||
# apply correct base flags
|
||||
if [[ -n $relative ]]; then
|
||||
rsync_flags+=(--relative)
|
||||
fi
|
||||
|
||||
# sanity checks
|
||||
[[ -z $filtered_paths ]] && { printf "$FMT_ERROR" "Missing valid paths."; exit 1; }
|
||||
[[ -z $receiver ]] && { printf "$FMT_ERROR" "Missing receiver. Specifiy with --receiver"; exit 1; }
|
||||
|
Loading…
Reference in New Issue
Block a user