Skip to content

Instantly share code, notes, and snippets.

@patryk
Created July 30, 2020 16:33
Show Gist options
  • Save patryk/e8a19393f57a054cb87aafff1b00652d to your computer and use it in GitHub Desktop.
Save patryk/e8a19393f57a054cb87aafff1b00652d to your computer and use it in GitHub Desktop.
restic systemd
BACKUP_PATHS="/etc /home /root /var/lib/mysql"
BACKUP_EXCLUDES="--exclude-file /home/rupert/.restic_excludes --exclude-if-present .exclude_from_backup --exclude-caches"
RETENTION_DAYS=7
RETENTION_WEEKS=4
RETENTION_MONTHS=6
RETENTION_YEARS=3
B2_ACCOUNT_ID=xxx
B2_ACCOUNT_KEY=yyy
RESTIC_REPOSITORY=b2:patryk-restic-backups:/restic/backup/felucia
RESTIC_PASSWORD=zzz
XDG_CACHE_HOME=/var/cache/restic
[Unit]
Description=Restic backup service
[Service]
Type=oneshot
ExecStart=/usr/bin/restic backup --one-file-system --tag systemd.timer $BACKUP_EXCLUDES $BACKUP_PATHS
ExecStartPost=/usr/bin/restic forget --tag systemd.timer --group-by "paths,tags" --keep-daily $RETENTION_DAYS --keep-weekly $RETENTION_WEEKS --keep-monthly $RETENTION_MONTHS --keep-yearly $RETENTION_YEARS
EnvironmentFile=/etc/restic-backup.conf
[Unit]
Description=Backup with restic daily
[Timer]
OnCalendar=daily
RandomizedDelaySec=5min
Persistent=true
[Install]
WantedBy=timers.target
[Unit]
Description=Restic backup service (data pruning)
[Service]
Type=oneshot
ExecStart=/usr/bin/restic prune
EnvironmentFile=/etc/restic-backup.conf
[Unit]
Description=Prune data from the restic repository monthly
[Timer]
OnCalendar=monthly
RandomizedDelaySec=5min
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment