mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-01 16:03:06 +01:00
22 lines
640 B
Bash
Executable File
22 lines
640 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# A script to perform incremental backups with rsync
|
|
|
|
DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
|
|
readonly BACKUP_DIR="/mnt/backup"
|
|
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
|
|
readonly LATEST_LINK="${BACKUP_DIR}/latest"
|
|
|
|
TEMP_DIR=$(mktemp -d || echo "Failed to make temp dir"; exit 1)
|
|
chmod 700 "${TEMP_DIR}"
|
|
trap 'rm -rf "${TEMP_DIR}"; exit 0' EXIT SIGHUP SIGINT SIGQUIT SIGTERM
|
|
|
|
while read -r line; do
|
|
rsync -aAX "$line" "${TEMP_DIR}";
|
|
done </etc/rsync-includes.txt
|
|
|
|
rsync -av --delete "${TEMP_DIR}/" --link-dest="${LATEST_LINK}" "${BACKUP_PATH}"
|
|
|
|
rm -f "${LATEST_LINK}"
|
|
ln -sf "${BACKUP_PATH}" "${LATEST_LINK}"
|