mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Add rsync-backup & systemd units
This commit is contained in:
parent
fcd582f4a6
commit
d69f8fdbac
29
bin/rsync-backup
Normal file
29
bin/rsync-backup
Normal file
@ -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 </etc/rsync-includes.txt
|
||||
|
||||
rsync -av --delete "${TEMP_DIR}/" --link-dest "${LATEST_LINK}" --exclude=".cache" "${BACKUP_PATH}"
|
||||
|
||||
rm -rf "${LATEST_LINK}"
|
||||
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
|
15
systemd/system/hyperreal.coffee-share.mount
Normal file
15
systemd/system/hyperreal.coffee-share.mount
Normal file
@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=hyperreal.coffee NFS share from TrueNAS (10.0.0.81)
|
||||
DefaultDependencies=no
|
||||
Conflicts=umount.target
|
||||
After=network-online.target remote-fs.target
|
||||
Before=umount.target
|
||||
|
||||
[Mount]
|
||||
What=10.0.0.81:/mnt/coffeeNAS/hyperreal.coffee
|
||||
Where=/mnt/backup
|
||||
Type=nfs
|
||||
Options=defaults
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
14
systemd/system/rsync-backup.service
Normal file
14
systemd/system/rsync-backup.service
Normal file
@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=rsync-backup
|
||||
AssertFileIsExecutable=/usr/local/bin/rsync-backup
|
||||
Requires=hyperreal.coffee-share.mount
|
||||
After=hyperreal.coffee-share.mount
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=root
|
||||
Group=root
|
||||
ExecStart=/usr/local/bin/rsync-backup
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
9
systemd/system/rsync-backup.timer
Normal file
9
systemd/system/rsync-backup.timer
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=rsync-backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=weekly
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Loading…
Reference in New Issue
Block a user