i migrated away from truenas (formerly freenas) and decided to use vanilla freebsd. truenas tended to be far behind freebsd version and in the past couple of years or so their support with relation to bug reports has tanked with them requesting a verbose log for easily reproducible bugs; else WONTFIX. i also wanted the zfs support without the awkward gpl vs. cddl tomfoolery you tend to find with linux distributions. i understand that zfs is well integrated into linux but freebsd was the best support for a long time.
after setting everything up so freebsd could be used as a fileserver (really just samba) i wanted to be able to do periodic backups. i first tried zfs-snapshot-mgmt which seemed straightforward but did not run properly. someone in #freebsd on liberachat suggested zfs-periodic.
install it:
# pkg install zfs-periodic
zfs-periodic uses /etc/periodic.conf for its configuration. it gives you some suggestions on how to set it up after its install from pkg. (i use pkg because it’s quick and easy. some people use the ports tree because they need certain things baked in.)
Message from zfs-periodic-1.0.20130213
—
FreeBSD 13.1 pkg install for zfs-periodic-1.0.20130213
In order to enable periodic snapshots you need to add these lines to your /etc/periodic.conf
hourly_output=”root”
hourly_show_success=”NO”
hourly_show_info=”YES”
hourly_show_badconfig=”NO”
hourly_zfs_snapshot_enable=”YES”
hourly_zfs_snapshot_pools=”tank”
hourly_zfs_snapshot_keep=6
going off the github page it seems as though output show_success show_info show_badconfig are only required in hourly_. the rest of the options are similar if you want to make a daily_ weekly_ or monthly_ block too. example: add daily_zfs_snapshot_enable=”YES” with the same types of options as hourly_ underneath. to break this down. hourly_output=”root” is the user that will run zfs snapshot. the show options are a bit obvious. <type>_zfs_snapshot_enable=”YES” is to enable the type of snapshot schedule. hourly_zfs_snapshot_pools=”tank” is what datasets you want to snapshot. you add more than one by putting a space. for instance if you have more than one pool with datasets and want to add both of them for a scheduled snapshot then make it “tank foo”. This is based on datasets so if you don’t want tank and want tank/home then just put “tank/home foo”. hourly_zfs_snapshot_keep=6 means it will keep the last 6 snapshots (or last 6 hours worth). any snapshots that are older than this will be destroyed (or pruned if you want to use that word instead).
afterwards you have to edit /etc/crontab and add an hourly line for periodic.
2 * * * * root periodic hourly
FreeBSD 13.1 pkg install for zfs-periodic-1.0.20130213
this will run periodic and run through the hourly scripts (these don’t have to just be the zfs-periodic scripts; it can do a lot more) every 2nd minute of the hour. freebsd periodic already comes with entries for daily weekly and monthly. might as well leave those alone.
# service cron restart
this will restart the cron service in order for your changes to cron to work.
if you make changes mid week or month you can always just run periodic <weekly/monthly> to snapshot right away.
# periodic weekly
# zfs list -t snapshot
you should see your snapshots. weekly will show the week number at the end. so it would be weekly_year_11 if you are in the 11th week of the year.