Commits

Kaspar Schiess committed 10f60ce

A readme

  • Participants
  • Parent commits 5be41d3

Comments (0)

Files changed (7)

+Gemfile.lock
 *.gem
 pkg
 rdoc

Gemfile.lock

-PATH
-  remote: .
-  specs:
-    zfs_incremental_sync (0.1.8)
-      activesupport (>= 3.1)
-      i18n (>= 0.6)
-
-GEM
-  remote: http://rubygems.org/
-  specs:
-    activesupport (3.2.9)
-      i18n (~> 0.6)
-      multi_json (~> 1.0)
-    coderay (1.0.8)
-    diff-lcs (1.1.3)
-    flexmock (1.2.0)
-    growl (1.0.3)
-    guard (1.5.4)
-      listen (>= 0.4.2)
-      lumberjack (>= 1.0.2)
-      pry (>= 0.9.10)
-      thor (>= 0.14.6)
-    i18n (0.6.1)
-    json (1.7.5)
-    listen (0.6.0)
-    lumberjack (1.0.2)
-    method_source (0.8.1)
-    multi_json (1.5.0)
-    pry (0.9.10)
-      coderay (~> 1.0.5)
-      method_source (~> 0.8)
-      slop (~> 3.3.1)
-    rb-fsevent (0.9.2)
-    rdoc (3.12)
-      json (~> 1.4)
-    rspec (2.12.0)
-      rspec-core (~> 2.12.0)
-      rspec-expectations (~> 2.12.0)
-      rspec-mocks (~> 2.12.0)
-    rspec-core (2.12.1)
-    rspec-expectations (2.12.0)
-      diff-lcs (~> 1.1.3)
-    rspec-mocks (2.12.0)
-    sdoc (0.3.20)
-      json (>= 1.1.3)
-      rdoc (~> 3.10)
-    slop (3.3.3)
-    thor (0.16.0)
-
-PLATFORMS
-  ruby
-
-DEPENDENCIES
-  flexmock
-  growl
-  guard
-  rb-fsevent
-  rspec
-  sdoc
-  zfs_incremental_sync!
 
- Copyright (c) 2012 Kaspar Schiess
+ Copyright (c) 2012,2013 Kaspar Schiess
 
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
+
+A few ZFS tools, mostly related to snapshotting, cleaning up and synching.
+
+SYNOPSIS
+
+  # Snapshot any dataset, snapshot name is the current date/time in a 
+  # normalized format: 
+  zfs_snapshot pool1/my/dataset
+  
+  # List snapshots that are obsolete, given some rules about what is 
+  # considered obsolete: 
+  echo pool1 | zfs_list_obsolete_snapshots
+
+  # Safely destroy some dataset (recursively). This will always ask for
+  # permission!
+  zfs_safe_destroy pool1/my/dataset

bin/zfs_incremental_sync

-#!/usr/bin/env ruby
-
-# Call this as
-#   zfs_incremental_sync ROOT_DATASET TARGET_HOST TARGET_ROOT_DATASET
-#
-# ie: 
-#   zfs_incremental_sync pool1/active elara758 pool1/backup
-#
-
-$:.unshift File.dirname(__FILE__) + '/../lib'
-require 'zfs'
-
-unless ARGV.size == 3
-  puts %Q{
-Snapshots a dataset and then synchronizes it to another host.
-  
-  Usage: zfs_incremental_sync ROOT_DATASET TARGET_HOST TARGET_ROOT_DATASET
-  
-Where ROOT_DATASET is the dataset you want to (recursively) snapshot and
-synchronize, TARGET_HOST is the host that receives the data and
-TARGET_ROOT_DATASET is the dataset on the remote host.
-
-Note that the tool will assume that both local and remote user (ssh) have
-sudo rights to execute /sbin/zfs without password.
-  }
-  exit 0
-end
-
-ROOT_DATASET, TARGET_HOST, TARGET_ROOT_DATASET = ARGV.first(3)
-
-# Runs the given command and returns its output.
-#
-def run_command(cmd, exit_on_failure=true)
-  output = `#{cmd.strip}`
-  
-  unless $?.success?
-    if exit_on_failure
-      warn "THERE SEEMS TO BE A PROBLEM (from zfs_incremental_sync)"
-      warn "Command #{cmd} failed with exit code #{$?.exitstatus}."
-      exit 1
-    end
-    
-    # We don't exit (exit_on_failure), but we don't want to leak the error 
-    # message as regular output either.
-    return ''
-  end
-  
-  output
-end
-
-def remote_zfs_list(host, dataset_name)
-  puts "Retrieving list of snapshots for #{dataset_name} on #{host}..."
-  
-  return run_command("ssh #{host} sudo /sbin/zfs list -H -o name -r #{dataset_name}", false)
-end
-def zfs_list(dataset_name)
-  run_command("sudo /sbin/zfs list -H -o name -r #{dataset_name}", true)
-end
-
-def send_snapshot(pool, snapshot, remote_host, remote_pool, opts={}) 
-  puts "Sending #{pool} to #{remote_host}/#{remote_pool} (@#{snapshot})..."
-  puts "Reference point is @#{opts[:reference]}" if opts[:reference]
-  
-  additional_args = ''
-  additional_args << "-I #{pool}@#{opts[:reference]}" if opts[:reference]
-  
-  cmd = %Q{
-    sudo /sbin/zfs send #{additional_args} -R #{pool}@#{snapshot} | ssh #{remote_host} sudo /sbin/zfs receive -vFd #{remote_pool} 
-  }
-  run_command cmd
-end
-
-# Limits the charset of string to word characters
-#
-def limit_charset(str)
-  str.gsub(/\W/, '_')
-end
-
-# MAIN -----------------------------------------------------------------------
-
-# Create a new snapshot on ROOT_DATASET yyyymmddhhmm -------------------------
-dataset = ZFS::Dataset.new(ROOT_DATASET)
-snapshot_name = dataset.snapshot_with_timestamp("backup_to_#{TARGET_HOST}_#{TARGET_ROOT_DATASET}")
-
-# Find the latest snapshot on TARGET_HOST ------------------------------------
-
-# pool1/test -> test
-local_path = ROOT_DATASET.split('/')[1..-1].join('/')
-remote_dataset_name = "#{TARGET_ROOT_DATASET}/#{local_path}"
-
-remote = ZFS::SnapshotList.new(
-  remote_zfs_list(TARGET_HOST, remote_dataset_name))
-local  = ZFS::SnapshotList.new(
-  zfs_list(ROOT_DATASET))
-
-reference_snapshot = (
-  remote.snapshots(remote_dataset_name) & local.snapshots(ROOT_DATASET)
-).last
-
-# Send incremental stream ----------------------------------------------------
-if reference_snapshot
-  send_snapshot(ROOT_DATASET, snapshot_name, TARGET_HOST, TARGET_ROOT_DATASET, 
-    :reference => reference_snapshot)
-else
-  send_snapshot(ROOT_DATASET, snapshot_name, TARGET_HOST, TARGET_ROOT_DATASET)
-end

bin/zfs_safe_destroy

Empty file added.

zfs-tools.gemspec

   s.summary = %q{
     A few ZFS tools, mostly related to snapshotting, cleaning up and synching. }
   
+  s.add_dependency 'mixlib-shellout', '>= 1.0'
   s.add_dependency 'activesupport', '>= 3.1'
   s.add_dependency 'i18n', '>= 0.6'
 end