summaryrefslogtreecommitdiff
path: root/byteback-prune
diff options
context:
space:
mode:
authorMatthew Bloch <mattbee@yoga.home.bloch.tv>2014-11-05 18:54:12 +0000
committerMatthew Bloch <mattbee@yoga.home.bloch.tv>2014-11-05 18:54:12 +0000
commit8a12e8e9d1a06c4b071a46966bd43c44c8136faa (patch)
tree240ae6f653669c73adc9a5cf4f2a2b6c97ab5029 /byteback-prune
parentaa9d3eba052a45e57b2ad0362f0671a5a4b471cd (diff)
Usability and bug fixes for byteback-prune, including --prune-force flag.
Diffstat (limited to 'byteback-prune')
-rwxr-xr-xbyteback-prune31
1 files changed, 20 insertions, 11 deletions
diff --git a/byteback-prune b/byteback-prune
index ed5bf0c..f49068f 100755
--- a/byteback-prune
+++ b/byteback-prune
@@ -26,6 +26,8 @@ opts = Trollop::options do
opt :prune, "Prune the next backup if necessary"
+ opt :prune_force, "Prune the next backup regardless"
+
opt :order, "Order backups by 'age' or 'importance'",
:type => :string,
:default => "importance"
@@ -38,9 +40,12 @@ end
@verbose = opts[:verbose]
@do_list = opts[:list]
@do_prune = opts[:prune]
+@do_prune_force = opts[:prune_force]
@minpercent = opts[:minpercent]
@maxpercent = opts[:maxpercent]
+@do_prune = true if @do_prune_force
+
fatal("Must specify one of --prune or --list") unless
(@do_prune || @do_list) &&
!(@do_prune && @do_list)
@@ -55,23 +60,16 @@ end
@df_history = DiskFreeHistory.new(ENV['HOME'])
@df_history.new_reading!
-# Don't do anything if we've not got two hours of readings
-#
-if @df_history.list.last.time - @df_history.list.first.time < 7200
- warn("Not enough disc space history to make a decision")
- exit 0
-end
-
gradient_30m = @df_history.gradient(1800)
-debug("Disc space gradient over 30m = #{gradient_30m}")
-exit
# Check whether we should still be pruning
#
@free = @df_history.list.last.percent_free
PRUNING_FLAG = "#{ENV['HOME']}/.byteback.pruning"
-if @free <= @minpercent && !File.exists?(PRUNING_FLAG)
+if @do_prune_force
+ warn("Forcing prune")
+elsif @free <= @minpercent && !File.exists?(PRUNING_FLAG)
warn("Starting prune, #{@free}% free (aiming for #{@maxpercent})")
File.write(PRUNING_FLAG,"")
elsif @free >= @maxpercent && File.exists?(PRUNING_FLAG)
@@ -81,6 +79,8 @@ elsif File.exists?(PRUNING_FLAG)
warn("Continuing prune, #{@free}% free (aiming for #{@maxpercent})")
end
+debug("Disc free #{@free}%, 30m gradient = #{gradient_30m}")
+
def snapshots_in_order
list = BackupDirectory.all_snapshots
if list.empty?
@@ -104,9 +104,18 @@ if @do_list
end
end
+# Don't do anything if we've not got two hours of readings
+#
+if !@do_prune_force
+ if @df_history.list.last.time - @df_history.list.first.time < 1800
+ warn("Not enough disc space history to make a decision")
+ exit 0
+ end
+end
+
exit 0 unless File.exists?(PRUNING_FLAG) && @do_prune
-exit 0 if gradient_30m != 0
+exit 0 unless @do_prune_force || gradient_30m == 0
info("Deleting #{snapshots.last.path}")
log_system("sudo btrfs subvolume delete #{snapshots.last.path}")