Menu

#46 Add example systemd units

closed
nobody
None
5
2020-01-22
2019-12-31
Jozef Riha
No

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.

1 Attachments

Discussion

  • ede

    ede - 2020-01-04

    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

     
  • Jozef Riha

    Jozef Riha - 2020-01-09

    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:

    $ systemctl --user start duply-backup@humbug.service
    $ systemctl --user status duply-backup@humbug.service
    

    We can now see the next run has been 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. 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 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:

    /etc/msmtprc
     ..
     ..
     aliases /etc/aliases
    
    /etc/aliases
     MYUSER:  MYUSER@MYPROVIDER.com
    

    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
  • ede

    ede - 2020-01-22
    • status: open --> closed
     
  • ede

    ede - 2020-01-22

    released as v2.2.1

     

Log in to post a comment.