8

Using the below zfs-auto-snapshot commands, how to specify to keep 52 weekly snapshots and infinite number of monthly snapshots?

sudo zfs set com.sun:auto-snapshot=true storage
sudo zfs set com.sun:auto-snapshot:weekly=true storage
sudo zfs set com.sun:auto-snapshot:monthly=true storage

When I specified it as a keyword or argument it failed both times:

sudo zfs set com.sun:auto-snapshot:weekly=true storage keep=52
cannot open 'keep=52': invalid dataset name

sudo zfs set com.sun:auto-snapshot:weekly=true storage --keep=52
cannot open '--keep=52': invalid dataset name
Greg
  • 1,557
  • 5
  • 24
  • 35

4 Answers4

6

Here is a sample of one of my system's /etc/cron.d/zfs-auto-snapshot.

PATH="/usr/bin:/bin:/usr/sbin:/sbin"

*/5 * * * * root /sbin/zfs-auto-snapshot -q -g --label=frequent --keep=24 //
00 * * * * root /sbin/zfs-auto-snapshot -q -g --label=hourly --keep=24 //
59 23 * * * root /sbin/zfs-auto-snapshot -q -g --label=daily --keep=14 //
59 23 * * 0 root /sbin/zfs-auto-snapshot -q -g --label=weekly --keep=4 //
00 00 1 * * root /sbin/zfs-auto-snapshot -q -g --label=monthly --keep=18 //
ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • Running `> /usr/sbin/zfs-auto-snapshot -q -g --label=frequent --keep=24` results in: `bash: /usr/sbin/zfs-auto-snapshot: No such file or directory`. If I run `> which zfs-auto-snapshot`, I get: `/usr/local/sbin/zfs-auto-snapshot`. I then tried `> zfs-auto-snapshot -q -g --label=frequent --keep=24` which returned `Error: The filesystem argument list is empty.`. Do those commands work on Ubuntu? – Greg Jun 16 '17 at 01:37
  • 2
    Please don't run `> anything`, especially as root, unless you know for a fact that you really want to do this. A bare `> x` will truncate the file `x`, causing loss of data, and parameters intended for `x` (if it is an executable) will likely not help you there. @Dave, if you want to illustrate the shell prompt, use `$` or `#` as those are the common symbols for ordinary user and superuser prompts, respectively. Or just leave it out entirely. – user Jul 08 '17 at 13:23
  • 1
    In case someone else comes across this post about `zfs-auto-snapshot` tool, it installs the Cron jobs on installation under all Cron paths. `ls -la /etc/cron.*/zfs-auto-snapshot`. It can turn into a runaway disaster of snapshotting. I didn't figure this out until I started uninstalling a cleaning anything "zfs-auto-snapshot". – Praveen Premaratne Apr 27 '21 at 21:27
1

Sorry if I'm answering a old question, but none of the answers provided what the OP wanted. When setting up the auto-snapshot for zPool, if you need to include multiple settings you need to separate them with a comma and then put your container's name at then end. This is the command you'll need:

sudo zfs set com.sun:auto-snapshot:weekly=true,keep=52 storage

You can also go to your cron's schedules (Ubuntu: /etc/cron.weekly) and change it there as others have mentioned.

GeekyDaddy
  • 126
  • 3
1

You need to edit the invocation of zfs-auto-snapshot. The file should be located in /etc/cron.weekly/zfs-auto-snapshot. There a default value of 8 is set.

I personally didn't know about this tool before. What I use is zfSnap. It's available in the standard repositories.

Sethos II
  • 497
  • 4
  • 7
  • 18
0
apt install zfs-auto-snapshot

solved it for me. It installs the cron entries from @ewwhite's answer in a nice way (daily=31, hourly=24, monthly=12, weekly=8). Only weekly is a bit surprising to me.

Ole Tange
  • 2,836
  • 5
  • 29
  • 45