mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 13:14:35 +00:00
32 lines
895 B
Bash
Executable file
32 lines
895 B
Bash
Executable file
#!/bin/bash
|
|
|
|
# Script to perform incremental backups using rsync
|
|
# It is often ran as crontab rule for automated backup solution
|
|
#
|
|
# 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
|
|
echo "Invalid amount of arguments passed!"
|
|
echo "Arguments: [Source path] [Backup path]"
|
|
echo " Source path: directory to be backed up, usually '/'"
|
|
echo " Backup path: directory to back up to (destination), usually mounted drive"
|
|
exit
|
|
fi
|
|
|
|
SOURCE_DIR="$1"
|
|
BACKUP_DIR="$2"
|
|
DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
|
|
BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
|
|
LATEST_LINK="${BACKUP_DIR}/latest"
|
|
|
|
mkdir -p "$BACKUP_DIR"
|
|
|
|
rsync -avHAXS \
|
|
--delete \
|
|
--filter='dir-merge /.rsync-filter' \
|
|
--link-dest "${LATEST_LINK}" \
|
|
"${@:3}" "${SOURCE_DIR}/" "${BACKUP_PATH}"
|
|
|
|
ln -sf "${BACKUP_PATH}" "${LATEST_LINK}"
|