Periodic snapshots tasks: no purge of old snapshots

ECC

Explorer
Joined
Nov 8, 2020
Messages
65
Hi,
i enabled a periodic snapshot task for my pool. I configured "2 weeks" for "keep snapshot for". However, snapshots older than 2 weeks are still stored on my pool? That fills up my pool very quickly...
 

Samuel Tai

Never underestimate your own stupidity
Moderator
Joined
Apr 24, 2020
Messages
5,399
Did you change the naming scheme during the 2 weeks? That will affect the ability of the snapshot task to clear out older snapshots, which won't match the new naming scheme.
 

ECC

Explorer
Joined
Nov 8, 2020
Messages
65
Did you change the naming scheme during the 2 weeks?
i just edited the schedule but not the naming schema

Is there an easy way to delete a huge amount of snapshots at one time? Due to missing automatic purge option of truenas, i have now almost 100k of Snapshots...And I don't want to delete them one by one (truenas gui is only showing 15 at a time)
 
Last edited:

blanchet

Guru
Joined
Apr 17, 2018
Messages
516
For mass deletion, you can use the command line. For example to delete all snapshots with @auto-2020- in their name

The first time, run in dry-run mode (option -n) and and print some information (-p) to check that the command is correct. (it will delete nothing)
Code:
for s in `zfs list -r -t snap -H -o name tank1/mydataset | grep @auto-2020-` ; do
    zfs destroy -np $s ;
done


If it is OK, you can remove the -n option, to delete the snapshot

Code:
for s in `zfs list -r -t snap -H -o name tank1/mydataset | grep @auto-2020-` ; do
    zfs destroy -p $s ;
done


If you have 100K snapshots to delete, it will take a while.
 

ECC

Explorer
Joined
Nov 8, 2020
Messages
65
Code:
for s in `zfs list -r -t snap -H -o name tank1/mydataset | grep @auto-2020-` ; do
zfs destroy -np $s ;
done
Thank you, i think it worked (with -n). But is there an option to delete all snapshots that are older than timestamp X ? (e.g. X = @auto-2021-02-09_09-11)
 

blanchet

Guru
Joined
Apr 17, 2018
Messages
516
I think that there is no direct command to delete all snapshots older than a timestamp, so you have to write your own script to do it.
Therefore, it would be easier to delete only the oldest snapshots, because you can iterate several times.

To dry-run the deletion of the 1000 oldest snapshots
Code:
zfs list -H -t snapshot -o name -S creation -r <datasetname> | tail --lines=1000 | xargs -n 1  zfs destroy -np


When you are OK, just remove the -n option
Code:
zfs list -H -t snapshot -o name -S creation -r <datasetname> | tail --lines=1000 | xargs -n 1  zfs destroy -p


Reference:
 
Top