From d69f8fdbacef8935eba1e693f7fe070013647d9c Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Sun, 7 Jul 2024 10:17:47 -0500 Subject: [PATCH] Add rsync-backup & systemd units --- bin/rsync-backup | 29 +++++++++++++++++++++ systemd/system/hyperreal.coffee-share.mount | 15 +++++++++++ systemd/system/rsync-backup.service | 14 ++++++++++ systemd/system/rsync-backup.timer | 9 +++++++ 4 files changed, 67 insertions(+) create mode 100644 bin/rsync-backup create mode 100644 systemd/system/hyperreal.coffee-share.mount create mode 100644 systemd/system/rsync-backup.service create mode 100644 systemd/system/rsync-backup.timer diff --git a/bin/rsync-backup b/bin/rsync-backup new file mode 100644 index 0000000..33deada --- /dev/null +++ b/bin/rsync-backup @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# A script to perform incremental backups with rsync +# Source: https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux + +set -o errexit +set -o nounset +set -o pipefail + +readonly BACKUP_DIR="/mnt/backup" +readonly DATETIME +DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')" +readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}" +readonly LATEST_LINK="${BACKUP_DIR}/latest" +readonly TEMP_DIR +TEMP_DIR=$(mktemp -d || echo "Failed to make temp dir"; exit 1) +chmod 700 "${TEMP_DIR}" +trap 'rm -rf "${TEMP_DIR}"; exit 0' 0 1 2 3 15 + +mkdir -p "${BACKUP_DIR}" + +while read -r line; do + rsync -aAX "$line" "${TEMP_DIR}"; +done