#!/usr/local/bin/ruby # # Simple ZFS Snapshotting # Copyright (c) 2009, Jeremy Tregunna, All Rights Reserved # # This work `as-is' we provide. # No warranties of any kind, express or implied. # We've done our best, # to debug and test. # Liability for damages denied. # # Permission is granted hereby, # to copy, share, and modify. # Use as is fit, # free or for profit. # These rights, on this notice, rely. # # == Synopsis # Simple utility to take snapshots at periodic intervals defined by the user # with the assistance of a cron daemon. # This utility is meant to be run through cron, and not at the command line. # # == Examples # To take snapshots hourly, on the hour, one might use: # # 0 * * * * root /usr/local/bin/zfs-snapshot tank/home hourly # # To recursively take a snapshot monthly, at 4:20 AM on the 1st one might use: # # 20 4 1 * * root /usr/local/bin/zfs-snapshot -r tank/home monthly # # == Usage # zfs-snapshot [options] filesystem_name snapshot_name # # == Options # -h, --help Display this help message # -v, --version Display the version of this script, and exit # -r, --recursive Recursively create snapshots # # == Author # Jeremy Tregunna # # == Copyright # Copyright (c) 2009, Jeremy Tregunna, All Rights Reserved. # Released under the Poetic Licence. # # This work `as-is' we provide. # No warranties of any kind, express or implied. # We've done our best, # to debug and test. # Liability for damages denied. # # Permission is granted hereby, # to copy, share, and modify. # Use as is fit, # free or for profit. # These rights, on this notice, rely. require 'rdoc/usage' require 'time' require 'ostruct' require 'optparse' require 'zfs-snapshot' SZS_VERSION = "1.0.1" $options = OpenStruct.new $options.recursive = false def output_version puts "#{File.basename(__FILE__)} version #{SZS_VERSION}" end def output_help output_version RDoc::usage() end opts = OptionParser.new opts.on("-h", "--help") { output_help } opts.on("-v", "--version") { output_version; exit 0 } opts.on("-r", "--recursive") { $options.recursive = true } opts.parse!(ARGV) output_help if ARGV[0].nil? fs = Filesystem.new(ARGV[0], ARGV[1], $options.recursive) fs.take_snapshot