50 lines
1.1 KiB
Bash
50 lines
1.1 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -Eeuo pipefail
|
||
|
|
|
||
|
|
SRC="${HOME}/"
|
||
|
|
DEST_BASE="/run/media/hans/usbsicherung/jacboy_sicherung"
|
||
|
|
HOST="$(hostname -s)"
|
||
|
|
STAMP="$(date +%F_%H-%M-%S)"
|
||
|
|
SNAPSHOT_DIR="${DEST_BASE}/${HOST}/${STAMP}"
|
||
|
|
LAST_LINK="${DEST_BASE}/${HOST}/latest"
|
||
|
|
LOG_DIR="${DEST_BASE}/${HOST}/logs"
|
||
|
|
LOG_FILE="${LOG_DIR}/backup-${STAMP}.log"
|
||
|
|
KEEP=30
|
||
|
|
|
||
|
|
mkdir -p "${SNAPSHOT_DIR}" "${LOG_DIR}"
|
||
|
|
|
||
|
|
RSYNC_OPTS=(
|
||
|
|
-aHAXx
|
||
|
|
--numeric-ids
|
||
|
|
--delete
|
||
|
|
--delete-excluded
|
||
|
|
--info=stats2,progress2
|
||
|
|
--human-readable
|
||
|
|
--partial
|
||
|
|
)
|
||
|
|
|
||
|
|
EXCLUDES=(
|
||
|
|
--exclude=".cache/"
|
||
|
|
--exclude="Downloads/"
|
||
|
|
--exclude=".local/share/Trash/"
|
||
|
|
--exclude=".gvfs/"
|
||
|
|
--exclude=".dotnet/"
|
||
|
|
--exclude=".codegpt/"
|
||
|
|
--exclude=".copilot/"
|
||
|
|
--exclude=".var/"
|
||
|
|
--exclude=".vscode/"
|
||
|
|
--exclude="temp/"
|
||
|
|
)
|
||
|
|
|
||
|
|
if [ -L "${LAST_LINK}" ] && [ -d "$(readlink -f "${LAST_LINK}")" ]; then
|
||
|
|
RSYNC_OPTS+=(--link-dest="$(readlink -f "${LAST_LINK}")")
|
||
|
|
fi
|
||
|
|
|
||
|
|
rsync "${RSYNC_OPTS[@]}" \
|
||
|
|
"${EXCLUDES[@]}" \
|
||
|
|
"${SRC}" "${SNAPSHOT_DIR}/" | tee "${LOG_FILE}"
|
||
|
|
|
||
|
|
ln -sfn "${SNAPSHOT_DIR}" "${LAST_LINK}"
|
||
|
|
|
||
|
|
cd "${DEST_BASE}/${HOST}"
|
||
|
|
ls -1dt 20* | tail -n +$((KEEP + 1)) | xargs -r rm -rf
|