summaryrefslogtreecommitdiff
path: root/byteback-snapshot
diff options
context:
space:
mode:
authorMatthew Bloch <matthew@bytemark.co.uk>2014-11-05 14:00:45 +0000
committerMatthew Bloch <matthew@bytemark.co.uk>2014-11-05 14:00:45 +0000
commitc88333e19b459685f57ba3f246c3fdd684681542 (patch)
tree3be762cf0a9ebb57c8a8528bcf98433434d371ad /byteback-snapshot
parentf6c155ff0b261f23b6fc9465b7f2e6d85bab573a (diff)
Split out -prune from -snapshot, tested the latter on various live setups.
Diffstat (limited to 'byteback-snapshot')
-rwxr-xr-xbyteback-snapshot64
1 files changed, 7 insertions, 57 deletions
diff --git a/byteback-snapshot b/byteback-snapshot
index 37834d4..a14e0f8 100755
--- a/byteback-snapshot
+++ b/byteback-snapshot
@@ -14,13 +14,7 @@ opts = Trollop::options do
opt :root, "Backups directory (must be a btrfs subvolume)",
:type => :string
- opt :snapshot, "Take a new snapshot"
-
- opt :prune, "Prune old backups (by 'age' or 'importance')",
- :type => :string
-
- opt :list, "List backups (by 'age' or 'importance')",
- :type => :string
+ opt :snapshot, "(ignored for compatibility)"
opt :verbose, "Print diagnostics"
@@ -28,61 +22,17 @@ end
@root = opts[:root]
@verbose = opts[:verbose]
-@do_snapshot = opts[:snapshot]
-@do_list = opts[:list]
-@do_prune = opts[:prune]
-
-fatal("Must specify snapshot, prune or list") unless @do_snapshot || @do_prune || @do_list
fatal("--root not readable") unless File.directory?("#{@root}")
@backups = BackupDirectory.new(@root)
-def get_snapshots_by(method)
- if method == 'importance'
- @backups.snapshot_times_by_importance.reverse # least important first
- elsif method == 'age'
- @backups.snapshot_times
- else
- raise ArgumentError.new("Unknown snapshot sort method #{method}")
- end
-end
-
-if @do_snapshot
- last_snapshot_time = @backups.snapshot_times.last
- fatal("Last snapshot was less than six hours ago") unless
- !last_snapshot_time ||
- Time.now - @backups.snapshot_times.last >= 6*60*60 # FIXME: make configurable
+last_snapshot_time = @backups.snapshot_times.last
+fatal("Last snapshot was less than six hours ago") unless
+ !last_snapshot_time ||
+ Time.now - @backups.snapshot_times.last >= 6*60*60 # FIXME: make configurable
- info "Making new snapshot"
- @backups.new_snapshot!
-end
-
-if @do_list
- list = get_snapshots_by(@do_list)
- print "Backups in #{@root} by #{@do_list}:\n"
- list.each_with_index do |time, index|
- print "#{sprintf('% 3d',index)}: #{time}\n"
- end
-end
-
-if @do_prune
- info "Counting last 10 backups"
- target_free_space = 1.5 * @backups.average_snapshot_size(10)
- info "Want to ensure we have #{target_free_space}"
-
- if @backups.free >= target_free_space
- info "(we have #{@backups.free} so no action needed)"
- else
- list = get_snapshots_by(@do_prune)
-
- while @backups.free < target_free_space && !list.empty?
- to_delete = list.pop
- info "Deleting #{to_delete}"
- @backups.delete_snapshot!(to_delete)
- info "Leaves us with #{@backups.free}"
- end
- end
-end
+info "Making new snapshot"
+@backups.new_snapshot!
info "Finished"