Skip to content

Instantly share code, notes, and snippets.

@njam
Last active February 15, 2020 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njam/32c80571b23246ab98a6ca9c22f9c527 to your computer and use it in GitHub Desktop.
Save njam/32c80571b23246ab98a6ca9c22f9c527 to your computer and use it in GitHub Desktop.
restic systemd config
[Unit]
Description=Restic backup %I
[Service]
Type=oneshot
Environment="HOME=%h"
ExecStart=/usr/bin/restic backup $BACKUP_ARGS "${BACKUP_PATH}"
ExecStart=/usr/bin/restic forget --prune $FORGET_ARGS
ExecStart=/usr/bin/restic check
[Unit]
Description=Restic backup %I
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
@njam
Copy link
Author

njam commented Feb 14, 2020

Setup

Copy template files restic-backup@.service and restic-backup@.timer into /etc/systemd/system/.

Create a new scheduled backup

  1. To create a backup called "foo" run the following command:
sudo systemctl edit restic-backup@foo.service

Insert the following configuration, adjusted to your needs:

[Service]
Environment="BACKUP_PATH=/test/source"
Environment='BACKUP_ARGS=\
--exclude "/test/source/file3" \
'
Environment='FORGET_ARGS=\
--keep-hourly 24 \
--keep-daily 30 \
--keep-monthly 12 \
'
Environment="RESTIC_REPOSITORY=/test/repo"
Environment="RESTIC_PASSWORD=my-pass"
  1. Enable a timer for the new service:
sudo systemctl enable --now restic-backup@foo.timer

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