Add automated Restic backups for edge01
This commit is contained in:
@@ -9,3 +9,7 @@ presharedkey
|
|||||||
# Environment and credential files
|
# Environment and credential files
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
|
|
||||||
|
# Restic credentials
|
||||||
|
*.env
|
||||||
|
!*.env.example
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export RESTIC_REPOSITORY="b2:zerafa-infrastructure:/edge01"
|
||||||
|
export B2_ACCOUNT_ID="REPLACE_ME"
|
||||||
|
export B2_ACCOUNT_KEY="REPLACE_ME"
|
||||||
|
export RESTIC_PASSWORD="REPLACE_ME"
|
||||||
Executable
+25
@@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source /etc/restic/edge01.env
|
||||||
|
|
||||||
|
exec 9>/run/restic-edge01.lock
|
||||||
|
|
||||||
|
if ! flock -n 9; then
|
||||||
|
echo "Another Restic operation is already running."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting edge01 backup at $(date --iso-8601=seconds)"
|
||||||
|
|
||||||
|
restic backup \
|
||||||
|
/etc \
|
||||||
|
/home/debian \
|
||||||
|
/opt \
|
||||||
|
--exclude /opt/backups \
|
||||||
|
--exclude '/opt/docker/gitea/data/git/repositories/*/*.git/tmp' \
|
||||||
|
--tag edge01 \
|
||||||
|
--tag automatic
|
||||||
|
|
||||||
|
echo "Backup completed at $(date --iso-8601=seconds)"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Restic backup of edge01 to Backblaze B2
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target docker.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/sbin/restic-edge01-backup
|
||||||
|
Nice=10
|
||||||
|
IOSchedulingClass=best-effort
|
||||||
|
IOSchedulingPriority=7
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Nightly Restic backup of edge01
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* 03:15:00
|
||||||
|
RandomizedDelaySec=10m
|
||||||
|
Persistent=true
|
||||||
|
Unit=restic-edge01-backup.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
Executable
+24
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source /etc/restic/edge01.env
|
||||||
|
|
||||||
|
exec 9>/run/restic-edge01.lock
|
||||||
|
|
||||||
|
if ! flock -n 9; then
|
||||||
|
echo "Another Restic operation is already running."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting Restic retention at $(date --iso-8601=seconds)"
|
||||||
|
|
||||||
|
restic forget \
|
||||||
|
--host edge01 \
|
||||||
|
--tag automatic \
|
||||||
|
--keep-daily 7 \
|
||||||
|
--keep-weekly 4 \
|
||||||
|
--keep-monthly 12 \
|
||||||
|
--prune
|
||||||
|
|
||||||
|
echo "Retention completed at $(date --iso-8601=seconds)"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Restic retention and pruning for edge01
|
||||||
|
Wants=network-online.target
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/sbin/restic-edge01-retention
|
||||||
|
Nice=10
|
||||||
|
IOSchedulingClass=best-effort
|
||||||
|
IOSchedulingPriority=7
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Weekly Restic retention for edge01
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=Sun *-*-* 04:15:00
|
||||||
|
RandomizedDelaySec=15m
|
||||||
|
Persistent=true
|
||||||
|
Unit=restic-edge01-retention.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
Reference in New Issue
Block a user