SOLVED periodic snapshot task triggers ... ?

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
 

jjb2018

Dabbler
Joined
Aug 12, 2018
Messages
28
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
I use Arch Linux at home for a variety of things. It's a virtualization host running KVM virtual machines, it also runs a number of different LXC containers (running: owncloud, nginx reverse proxy, subsonic, squid). I also use it for internal DNS & DHCP services (BIND9 & ISC DHCP), as well as file storage of course (ALL of my family photos, videos, music. Hence why I've chosen ZFS). It basically runs my home IT and I do a lot of tinkering with VMs on it! I use the Gnome Shell GUI for when I want a GUI. Linux has probably got better support for some of the hardware I have in my server build ... although I've never checked how well it would be supported with freeBSD.

I'm sure I could probably do everything/most of I want with freeBSD / freeNAS, but I'm much more familiar with Linux, so I stick with that. I only use a separate freeNAS machine (in my office) as a ZFS replication destination for my ZFS pool at home (I have another, less than perfect, script for doing this over SSH). On the freeNAS machine I've also setup a windows share where I keep VMWare images and other junk that I don't want to keep on my work laptop.
 

MSameer

Dabbler
Joined
Feb 12, 2019
Messages
14
I'm sure I could probably do everything/most of I want with freeBSD / freeNAS, but I'm much more familiar with Linux, so I stick with that. I only use a separate freeNAS machine (in my office) as a ZFS replication destination for my ZFS pool at home (I have another, less than perfect, script for doing this over SSH). On the freeNAS machine I've also setup a windows share where I keep VMWare images and other junk that I don't want to keep on my work laptop.

I have been having thoughts about the issue. I am more familiar with debian (since woody) and I feel more at home.
I also had an issue when FreeNAS cron stopped firing for half a day by itself. This which made me annoyed. A reboot fixed it but my daily backup script did not get executed as well as smart tests and mail backup.

Thank you for sharing your details :)
 

pro lamer

Guru
Joined
Feb 16, 2018
Messages
626
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
It could have an advantage unless I'm missing something: old snapshots are not deleted until I have new ones ready. This way I keep having a number of older snapshots of something goes wrong with the snapshotting job...

Sent from my phone
 
Top