Posts Tagged ‘zfs’

Automatic ZFS snapshot tool

Sunday, November 6th, 2011

This post is written in English, because this tool might be useful for ZFS people outside the Netherlands too. I wrote this automatic snapshotter, because I was in need of a simple tool that automatically creates new snapshots and removes old ones.

A few notes:
* This tool is provided as-is. I cannot be held responsible for any dataloss.
* It is tested on Ubuntu 11.10 with native ZFS, but it should work on other platforms too. The only requirements are ZFS and Perl.
* Feel free to modify the tool in any way you like, to suit your needs.
* It is not allowed to sell this tool, or to receive money in any way for distributing this tool.

Features:
* You can configure the total number of snapshots you’d like to keep.
* You can disable or enable overwriting. This overwrites a snapshot if one with the same name (same date) already exists.
* It will not touch mounts not listed in the configuration.
* It will not touch snapshots you made yourself (all snapshots created by this tool are tagged with the prefix ‘auto_’). So it will only remove snapshots created by this tool.
* Snapshots are named by date.

Installation is simple. Just put the script somewhere and run it. You can also put it in /etc/cron.daily if you want to run it daily from the cron. Another option is to save it somewhere else on the system and put it in the crontab yourself.

By piping it to sendmail, you can automatically let it send you an email, example: perl zfs_snapshots.pl | sendmail cybje@cybje.nl

You can download the tool here: http://www.cybje.nl/downloads/zfs_snapshots.pl