admin-scripts/.archived/rsync-backup

22 lines
640 B
Plaintext
Raw Normal View History

2024-07-07 17:17:47 +02:00
#!/usr/bin/env bash
# A script to perform incremental backups with rsync
DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
2024-07-08 03:25:03 +02:00
readonly BACKUP_DIR="/mnt/backup"
2024-07-07 17:17:47 +02:00
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
readonly LATEST_LINK="${BACKUP_DIR}/latest"
2024-07-08 03:25:03 +02:00
2024-07-07 17:17:47 +02:00
TEMP_DIR=$(mktemp -d || echo "Failed to make temp dir"; exit 1)
chmod 700 "${TEMP_DIR}"
2024-07-08 03:25:03 +02:00
trap 'rm -rf "${TEMP_DIR}"; exit 0' EXIT SIGHUP SIGINT SIGQUIT SIGTERM
2024-07-07 17:17:47 +02:00
while read -r line; do
rsync -aAX "$line" "${TEMP_DIR}";
done </etc/rsync-includes.txt
2024-07-08 03:25:03 +02:00
rsync -av --delete "${TEMP_DIR}/" --link-dest="${LATEST_LINK}" "${BACKUP_PATH}"
2024-07-07 17:17:47 +02:00
2024-07-08 03:25:03 +02:00
rm -f "${LATEST_LINK}"
ln -sf "${BACKUP_PATH}" "${LATEST_LINK}"