From ddbf375ac5a93ca984252340f989f6f43f8829d3 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Mon, 3 May 2021 15:59:55 +0200 Subject: [PATCH] Fix symlink override --- home/.local/bin/incremental-backup | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/home/.local/bin/incremental-backup b/home/.local/bin/incremental-backup index 8b73bda..6aba77a 100755 --- a/home/.local/bin/incremental-backup +++ b/home/.local/bin/incremental-backup @@ -6,7 +6,7 @@ # This script will respect .rsync-filter files, which can be used # to define custom exclude rules for files/dirs in which it is present -if [ $# -ge 2 ]; then +if [ $# -lt 2 ]; then echo "Invalid amount of arguments passed!" echo "Arguments: [Source path] [Backup path]" echo " Source path: directory to be backed up, usually '/'" @@ -28,4 +28,10 @@ rsync -avHAXS \ --link-dest "${LATEST_LINK}" \ "${@:3}" "${SOURCE_DIR}/" "${BACKUP_PATH}" -ln -sf "${BACKUP_PATH}" "${LATEST_LINK}" +# Only attempt to override the symlink if we made new backup_path +# user might've passed --dry-run option in which case we wouldn't +# want to override latest symlink to non-existent location +if [ -d "${BACKUP_PATH}" ]; then + rm "${LATEST_LINK}" 2>/dev/null + ln -s "${BACKUP_PATH}" "${LATEST_LINK}" +fi