Skip to content

Instantly share code, notes, and snippets.

@njam
Last active February 15, 2020 10:52
Show Gist options
  • 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 [email protected] and [email protected] into /etc/systemd/system/.

Create a new scheduled backup

  1. To create a backup called "foo" run the following command:
sudo systemctl edit [email protected]

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 [email protected]

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