1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
SCHEDULING BACKUPS USING SYSTEMD TIMERS
a mini-howto written by Jozef Riha [09.01.2020]
One way of setting up a regular backup and backup-related jobs on a
systemd-based OS is via systemd timers. Duply is coming is coming with a set
of example units that makes this task easy to implement. The units have to be
placed at
`/etc/systemd/user`
and allow user-independent scheduling of multiple duply profiles.
Let's consider a regular backup with an example `humbug` profile configured.
This command schedules the backup of this profile in predefined intervals:
```
$ systemctl --user enable --now duply-backup@humbug.timer
```
To start the count-down timer we need to run the backup via systemd once:
```
$ systemctl --user start duply-backup@humbug.service
$ systemctl --user status duply-backup@humbug.service
```
We can now list the next run as scheduled by systemd:
```
$ systemctl --user list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Fri 2020-01-10 11:15:47 CET 23h left Thu 2020-01-09 11:05:42 CET 10min ago duply-backup@humbug.timer duply-backup@humbug.service
```
You may schedule verify (`duply-verify@`) and cleanup (`duply-cleanup@`) similarly.
CHANGING THE DEFAULTS
To override default scheduling interval create a drop-in service file in
`/etc/systemd/user`
. Eg. to make all backups run every 30 minutes create
`/etc/systemd/user/duply-backup@.timer.d/OnUnitActiveSec.conf`
with the following contents:
```
[Timer]
OnUnitActiveSec=30m
```
Then reload the configuration:
```
$ systemctl --user daemon-reload
```
To override this for the `humbug` profile only write these changes into
`/etc/systemd/user/duply-backup@humbug.timer.d/OnUnitActiveSec.conf`
.
E-MAIL NOTIFICATION
All units are configured with `OnFailure` directive that sends e-mail if
a unit ends with a failure. This assumes a working MTA, eg. msmtp.
Note that emails are sent to a user having the profile set, so defining
an alias may be required. For msmtp this would be:
```
/etc/msmtprc
..
..
aliases /etc/aliases
/etc/aliases
MYUSER: MYUSER@MYPROVIDER.com
```
|