restic backups ftw

This commit is contained in:
Daylin Morgan 2023-12-19 23:14:16 -06:00
parent af4c606e75
commit 81c93a1bf8
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
6 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -a
source "$HOME/.config/restic/othalan.env"
declare -a flags
# if [[ "$1" == "backup" ]]; then
# flags=(
# "--exclude-file" "$HOME/.config/restic/excludes.txt"
# "--exclude-file" "$HOME/.conda/environments.txt"
# )
# fi
#
# echo "${flags[@]}"
# assumes subcommand always comes first
case $1 in
-*) restic "$@" && exit "$?";;
backup) cmd=backup; shift;;
*) cmd="$1"; shift;;
esac
if [[ $cmd == "backup" ]]; then
flags=(
"--exclude-file" "$HOME/.config/restic/excludes.txt"
"--exclude-file" "$HOME/.conda/environments.txt"
)
fi
# echo restic "$@" "${flags[@]}"
restic "$cmd" "${flags[@]}" "$@"

View file

@ -0,0 +1,11 @@
RESTIC_REPOSITORY=rclone:g:othalan
RESTIC_PASSWORD_FILE=/home/daylin/.config/restic/othalan-pass
BACKUP_EXCLUDES="
--exclude-file /home/daylin/.config/restic/excludes.txt
--exclude-file /home/daylin/.conda/environments.txt
"
RETENTION_DAYS=7
RETENTION_WEEKS=4
RETENTION_MONTHS=6
RETENTION_YEARS=3
BACKUP_PATHS="/home/daylin/dev /home/daylin/stuff"

View file

@ -0,0 +1,21 @@
;ref: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/
[Unit]
Description=Restic backup service
[Service]
Type=oneshot
ExecStart=restic backup \
--verbose \
--one-file-system \
--tag systemd.timer \
$BACKUP_EXCLUDES $BACKUP_PATHS
ExecStartPost=restic forget \
--verbose \
--tag systemd.timer \
--group-by "paths,tags" \
--keep-daily $RETENTION_DAYS \
--keep-weekly $RETENTION_WEEKS \
--keep-monthly $RETENTION_MONTHS \
--keep-yearly $RETENTION_YEARS
EnvironmentFile=%h/.config/restic/othalan.env

View file

@ -0,0 +1,9 @@
[Unit]
Description=Backup with restic daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target

View file

@ -0,0 +1,7 @@
[Unit]
Description=Restic backup service (data pruning)
[Service]
Type=oneshot
ExecStart=restic prune
EnvironmentFile=%h/.config/restic/othalan.env

View file

@ -0,0 +1,9 @@
[Unit]
Description=Prune data from the restic repository monthly
[Timer]
OnCalendar=monthly
Persistent=true
[Install]
WantedBy=timers.target