Skip to content

Instantly share code, notes, and snippets.

@abraithwaite
Last active January 27, 2024 13:14
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abraithwaite/50f933e70cc0744877c7dcd8d6139c4b to your computer and use it in GitHub Desktop.
Save abraithwaite/50f933e70cc0744877c7dcd8d6139c4b to your computer and use it in GitHub Desktop.
Automated Restic Backups with CPU+Memory throttling, inspired by: https://fedoramagazine.org/automate-backups-with-restic-and-systemd/
B2_ACCOUNT_ID=XXXXXXXXXXXXXXXXXXXXXXXXX
B2_ACCOUNT_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
RESTIC_REPOSITORY=b2:XXXXXXXXXXXXXXXXXX:/
RESTIC_PASSWORD=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
BACKUP_PATHS="/home/naomi.nagata"
BACKUP_EXCLUDES="--exclude-file /home/rupert/.restic_excludes --exclude-if-present .exclude_from_backup"
RETENTION_DAYS=7
RETENTION_WEEKS=4
RETENTION_MONTHS=6
RETENTION_YEARS=3
[Unit]
Description=Restic backup service
[Service]
Type=oneshot
Slice=restic.slice
ExecStart=/usr/bin/restic backup --verbose --one-file-system --tag systemd.timer $BACKUP_EXCLUDES $BACKUP_PATHS
EnvironmentFile=%h/.config/restic-backup.conf
# TODO: retention
# 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
[Slice]
# 2 CPUs, adjust to preference
CPUQuota=200%
MemoryHigh=4G
[Unit]
Description=Backup with restic daily
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
@abraithwaite
Copy link
Author

abraithwaite commented Dec 1, 2022

  1. Put restic.{service,slice,timer} into ~/.config/systemd/user
  2. Modify the config to fit your needs and place into ~/.config/restic-backup.conf
  3. exec: systemctl --user daemon-reload
  4. exec: systemctl --user enable restic.timer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment