Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide systemd service and timer files #71

Open
OlliC opened this issue Sep 1, 2017 · 5 comments
Open

Provide systemd service and timer files #71

OlliC opened this issue Sep 1, 2017 · 5 comments

Comments

@OlliC
Copy link

OlliC commented Sep 1, 2017

Hi,

i just started using zfs-auto-snapshot on my Debian 9 server and want to suggest to add native
systemd service files for the script and also to add systemd timers to replace cron.

I run my server very infrequently and cronjobs only run when the server is online during that time. So it would probably miss most of the weekly snapshots i intended to make. With systemd there is the Persistent option on timers which let the service run whenever the server is running again and not missing snapshots.

Here are the service files and timers i made, based on an archlinux aur repo which provided systemd files, with some tweaks (using Type oneshot instead of simple).

These really should be provided upstream so every distribution gets it.

# /etc/systemd/system/zfs-auto-snapshot-frequent.service
[Unit]
Description=ZFS frequent snapshot service

[Service]
Type=oneshot
ExecStart=/usr/sbin/zfs-auto-snapshot --skip-scrub --prefix=znap --label=frequent --keep=4 //

# /etc/systemd/system/zfs-auto-snapshot-frequent.timer
[Unit]
Description=ZFS frequent snapshot timer

[Timer]
OnCalendar=*:0/15
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/zfs-auto-snapshot-hourly.service
[Unit]
Description=ZFS hourly snapshot service

[Service]
Type=oneshot
ExecStart=/usr/sbin/zfs-auto-snapshot --skip-scrub --prefix=znap --label=hourly --keep=24 //
# /etc/systemd/system/zfs-auto-snapshot-hourly.timer
[Unit]
Description=ZFS hourly snapshot timer

[Timer]
OnCalendar=hourly
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/zfs-auto-snapshot-daily.service
[Unit]
Description=ZFS daily snapshot service

[Service]
Type=oneshot
ExecStart=/usr/sbin/zfs-auto-snapshot --skip-scrub --prefix=znap --label=daily --keep=31 //
# /etc/systemd/system/zfs-auto-snapshot-daily.timer
[Unit]
Description=ZFS daily snapshot timer

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
# /etc/systemd/system/zfs-auto-snapshot-weekly.service
[Unit]
Description=ZFS weekly snapshot service

[Service]
Type=oneshot
ExecStart=/usr/sbin/zfs-auto-snapshot --skip-scrub --prefix=znap --label=weekly --keep=8 //
# /etc/systemd/system/zfs-auto-snapshot-weekly.timer
[Unit]
Description=ZFS weekly snapshot timer

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target

# /etc/systemd/system/zfs-auto-snapshot-monthly.service
[Unit]
Description=ZFS monthly snapshot service

[Service]
Type=oneshot
ExecStart=/usr/sbin/zfs-auto-snapshot --skip-scrub --prefix=znap --label=monthly --keep=12 //
# /etc/systemd/system/zfs-auto-snapshot-monthly.timer
[Unit]
Description=ZFS monthly snapshot timer

[Timer]
OnCalendar=monthly
Persistent=true

[Install]
WantedBy=timers.target

@jbnance
Copy link
Contributor

jbnance commented Dec 27, 2017

I run my server very infrequently and cronjobs only run when the server is online during that time.

Does Debian 9 not include an anacron configuration that runs jobs that were missed due to system being powered down?

@OlliC
Copy link
Author

OlliC commented Dec 28, 2017

As far as i know anacron can only do jobs daily. So the hourly or frequent jobs would not be possible.
Otherwise this would probably be an option.

@jbnance
Copy link
Contributor

jbnance commented Dec 28, 2017

We may have different definitions of "infrequent" in our heads. If a box is off for most of the day that also means that changes aren't being made to the filesystem, so I wouldn't think that hourly jobs would be needed. Perhaps on-boot and/or on-shutdown snaps would be a suited option.

@bgeron
Copy link

bgeron commented Jan 30, 2018

Anacron should be started at boot (at least it is on Ubuntu), but to avoid slowing down the boot too much it starts the daily/weekly/monthly tasks with a delay. On Ubuntu, this is configured in /etc/anacrontab and the default delay for weekly tasks is 10 minutes after boot. Perhaps it suits you to set this to a lower value?

@OlliC
Copy link
Author

OlliC commented Jan 30, 2018

I have deinstalled cron completly und just use systemd timers on my Debian system. Maybe it can be done with anacron also but i have never tried it. I think its not installed on Debian by default but i could be wrong. This issue was not really to solve my problem but to include the systemd timer files in the package for people who want to use them instead of cron.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants