MSameer
Dabbler
- Joined
- Feb 12, 2019
- Messages
- 14
I decided to split out the snapshot cleanup part to a separate script ...
Code:#!/bin/bash ##### Destroy all snapshots for the dataset having an auto:expire property value less than or equal to date +%s for OLDSNAP in $(zfs list -t snapshot -r -H -o name zfsdata) do if [ $(zfs list -t snapshot -H -o auto:expire $OLDSNAP) == '-' ] then continue elif [ $(zfs list -t snapshot -H -o auto:expire $OLDSNAP) -le $(date +%s) ] then zfs destroy $OLDSNAP fi done
The above is slightly modified to run in freeNAS. I'm actually running this on a Linux system where the line
Code:zfs set auto:expire=$(date -v+$TTL +%s) $NEWSNAP
actually needs to be ...
Code:zfs set auto:expire=$(date -d "+$TTL" +%s) $NEWSNAP
The reason I've split out the rolling snapshot cleanup script is because I wanted it to run on it's own schedule and more frequently. If it is only run when the snapshoting script is run then you have the possibility to have snapshots that have "auto:expired" hanging around on the system until the cleanup next occurs. So i have created multiple cron tasks to run the "rolling-snapshot.sh" script on various datasets with different "TTL" values. and I have another cron task which runs every 5 mins to run the "rolling-snapshot-cleanup.sh" script.
Thanks for sharing.
I just noticed that the script will delete all snapshots from all datasets. I am not sure if I should like it or not.
I currently snapshot my main data set but I am planning to snapshot more.
BTW: Why are you running a linux server instead of freenas?
I am asking because I am more familiar with linux and I find myself doing a lot using the command line