sanoid icon indicating copy to clipboard operation
sanoid copied to clipboard

Feature Request: snapshot every X hours

Open develop-Greenant opened this issue 2 years ago • 5 comments

I have read the documentation and looked at options like frequently but I can't see a way to implement the following:

  • snapshot every 2 hours

Is there a method to allow this sort of behaviour for a dataset?

develop-Greenant avatar Mar 16 '22 01:03 develop-Greenant

Why reimplement a cron service?

benjamir avatar Mar 16 '22 05:03 benjamir

Hi @benjamir because cron may be running more frequently than the desired snapshots for a particular dataset.

For instance, there may be one dataset that is snapshotted every 15minutes, while a different dataset only needs to be snapshotted every 2nd hour.

My understanding is that the sanoid config should be agnostic to how often the cron is run (especially with prune operations).

edit for clarification: (typically the sanoid cron is run every 5 minutes)

develop-Greenant avatar Mar 16 '22 05:03 develop-Greenant

Multiple cronjobs, per case -- I have a setup from non-zfs to zfs+autosnapshots: that just setups multiple cronjobs (.monthly, .weekly, .daily, .hourly and frequent jobs). The infrastructure is already there. No need to reinvent the wheel. When you need a special case: configure it there -- why would an app need internal logic to do so?

benjamir avatar Mar 16 '22 12:03 benjamir

OK I see what you mean, so have multiple sanoid crons and sanoid.confs

For instance, let's try to get a config that keeps snaps for every 2nd hour:

  • [x] cron running every 2nd hour
0 */2 * * * /usr/bin/flock -n /run/sanoid-lock /usr/sbin/sanoid --cron --configdir=/etc/sanoid/conf_2ndHourly

for our sanoid.conf, let's say we want to keep every 2nd hour over the last day (a total of 12 hourly snaps):

/etc/sanoid/conf_2ndHourly/sanoid.conf:

# note this config runs every 2nd hour via cron

### DATA SETS ###

[zpool1/testset]
        use_template = 2ndHourly
        recursive = no

### TEMPLATES ###

[template_2ndHourly]
        autoprune = yes
        hourly = 12
        daily = 30
        autosnap = 1

Ok, I can see how cron can take care of that and I think the pruning should be fine too as it just works on the hourly tag on the snapshot (not it's actual time).

So I guess the only inconvenient part of this is having to have multiple sanoid.conf files. But not too bad overall, thanks @benjamir for the pointer.

develop-Greenant avatar Mar 16 '22 12:03 develop-Greenant

p.s. I guess that the sanoid locks will also need to be duplicated (one for each sanoid cron job)

develop-Greenant avatar Mar 16 '22 12:03 develop-Greenant