I am trying to implement custom function for backup using rsync
. For this, I modified the following exist code https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux as follows:
#!/bin/zsh
#https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux
# A script to perform incremental backups using rsync
set -o errexit
set -o nounset
set -o pipefail
incremental_bckp_rsync_dir(){
readonly SOURCE_DIR="/$1"
readonly BACKUP_DIR="/$2/$1"
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
readonly LATEST_LINK="${BACKUP_DIR}/latest"
mkdir -p "${BACKUP_DIR}"
rsync -av --delete \
"${SOURCE_DIR}/" \
--link-dest "${LATEST_LINK}" \
--exclude=".cache" \
"${BACKUP_PATH}"
rm -rf "${LATEST_LINK}"
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
}
incremental_bckp_rsync_dir path/to/dir path/to/backup
It does successfully a backup of the dir
, however the size of the backup dir (obtained with the command du -h path/to/backup
) seems to double every time I run the script (which means that it is not incremental, from what I understand. Is there a way to fix it?