From 6b44c86915d5e8634173260758013df0878a33b5 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Sun, 7 Jul 2024 20:25:03 -0500 Subject: [PATCH] Refactor rsync-backup --- bin/rsync-backup | 20 ++++++------------- ...al.coffee-share.mount => mnt-backup.mount} | 0 systemd/system/rsync-backup.service | 4 ++-- systemd/system/rsync-backup.timer | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) mode change 100644 => 100755 bin/rsync-backup rename systemd/system/{hyperreal.coffee-share.mount => mnt-backup.mount} (100%) diff --git a/bin/rsync-backup b/bin/rsync-backup old mode 100644 new mode 100755 index 33deada..a621c0b --- a/bin/rsync-backup +++ b/bin/rsync-backup @@ -1,29 +1,21 @@ #!/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_DIR="/mnt/backup" 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}" +trap 'rm -rf "${TEMP_DIR}"; exit 0' EXIT SIGHUP SIGINT SIGQUIT SIGTERM while read -r line; do rsync -aAX "$line" "${TEMP_DIR}"; done