Add example systemd units
Brought to you by:
edso
I believe it would be nice if duply comes with a set of systemd units that could speed up deployment. After configuring the backup profile user would be expect to run
systemctl --user start duply-backup@profile_name
to initiate backup,
systemctl --user enable --now duply-backup@profile_name.timer
to schedule regular daily backup and the same goes for cleanup and verify. With a configured MTA (e. g. msmtp
) a report of a failed job can be sent via e-mail).
The example units are attached and are supposed to be placed to /usr/lib/systemd/user
.
hey Jozef,
looks good to me! would you mind writing up a mini howto step-by-step setup (a little more elaborate than the above notes)?
i'd add it to the distro then as folder 'systemd-unit.examples/' with the HOWTO.txt in it.
thanks!.. ede
Scheduling backups using systemd timers
One way of setting up a regular backup and backup-related jobs on a systemd-based OS is via systemd timers.
For this purpose duply is coming with a set of units that makes this task easy to implement. The units are located
at
/usr/lib/systemd/user
and/usr/lib/systemd/system
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:
We can now see the next run has been scheduled by systemd:
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
. To makeall backups run every 30 minutes create
/etc/systemd/user/duply-backup@.timer.d/OnUnitActiveSec.conf
with the following contents:
Then reload the configuration:
To override this for a
humbug
profile only write these changes to/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, e. g.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:
Invocation as root
If the goal is to run
duply
as a root user, repeat the steps with leaving out the--user
switch. Drop-in units are to be placed into/etc/systemd/system
.Last edit: Jozef Riha 2020-01-09
released as v2.2.1