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 
  `/usr/lib/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
```
