Fork me on GitHub

zfs-snapshot-cleaner by Ask Bjørn Hansen

ZFS Snapshot Cleanup

zfs-snapshot-cleaner purges old ZFS snapshots in an intelligent (and careful) manner.

Features

Dependencies

Perl and the DateTime and IPC::Cmd modules. Tested on FreeBSD, but should also work on Solaris, SmartOS, OpenIndiana etc.

The Perl modules are most easily installed with `cpanm`.

        mkdir -p ~/bin
        curl --compressed -L -o ~/bin/cpanm http://xrl.us/cpanm
        chmod a+x ~/bin/cpanm
        ~/bin/cpanm DateTime IPC::Cmd
      

Usage

For now look in the script for the options, the most important one is "-n" that makes the script not actually execute the zfs destroy commands. Use that while testing.

       ./zfs-snapshot-cleaner -n [file-system] [file-system]
      

License

Copyright (C) 2011 Ask Bjørn Hansen, Develooper LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Authors

Ask Bjørn Hansen (ask@develooper.com)

Other similar programs

Unsurprisingly there are about a gazillion other similar programs to this. I chose to write another because the ones I found were either "too integrated" (as in wanting to also manage doing the snapshots, I make snapshots from my backup script) and/or too simple and written in bash so too error prone (for me) to extend. You might like them better though!

The closest in spirit and functionality is zfs-snapshot-clean. If date parsing and handling wasn't such a pain in bash I'd have extended this script to be more flexible with regards to the particular day and date snapshots have to be made instead of writing a new program.

zfSnap prefers to do the snapshots, too. Has a clever (too clever?) option of putting the longevity of each snapshot into the snapshot name.

There's also zsnap (formerly zfs-snapshot-mgmt). It's supposed to run regularly in cron and have a yaml configuration file for when to make snapshots (and purge them, I think). Last update as of this writing was a change of maintainer a few year ago.

Ralf S. Engelschall made snapshot tools that work with both UFS and ZFS filesystems on FreeBSD. That seems to be the main feature. Again it really wants to also make the snapshots, seems best for snapshotting locally used file systems (vs backups of other computers) and is implemented as a sh script.

Contact

Ask Bjørn Hansen (ask@develooper.com)

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/abh/zfs-snapshot-cleaner