How to set the number of snapshots zfs-auto-snapshot should retain?
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
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 //
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.