How to set the number of snapshots zfs-auto-snapshot should retain?

15,684

Solution 1

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 //

Solution 2

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.

Solution 3

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.

Share:
15,684

Related videos on Youtube

Greg
Author by

Greg

Updated on September 18, 2022

Comments

  • Greg
    Greg over 1 year

    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
    Greg almost 7 years
    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?
  • Praveen Premaratne
    Praveen Premaratne about 3 years
    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".