Fix symlink override

This commit is contained in:
ItsDrike 2021-05-03 15:59:55 +02:00
parent 76e40cd44a
commit ddbf375ac5
No known key found for this signature in database
GPG key ID: B5F6B41F708C3ADD

View file

@ -6,7 +6,7 @@
# This script will respect .rsync-filter files, which can be used # This script will respect .rsync-filter files, which can be used
# to define custom exclude rules for files/dirs in which it is present # 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 "Invalid amount of arguments passed!"
echo "Arguments: [Source path] [Backup path]" echo "Arguments: [Source path] [Backup path]"
echo " Source path: directory to be backed up, usually '/'" echo " Source path: directory to be backed up, usually '/'"
@ -28,4 +28,10 @@ rsync -avHAXS \
--link-dest "${LATEST_LINK}" \ --link-dest "${LATEST_LINK}" \
"${@:3}" "${SOURCE_DIR}/" "${BACKUP_PATH}" "${@: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