summaryrefslogtreecommitdiff
path: root/bin/byteback-snapshot
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-06-03 15:55:28 +0100
committerSteve Kemp <steve@steve.org.uk>2015-06-03 15:55:28 +0100
commita29380762b93737ae6949121010cd9bceb8196b2 (patch)
tree4dfe2931401d0cc73c38b9a90377e31210d6706e /bin/byteback-snapshot
parentc4da983bd2a1e35450dcb21bdc7110f5fc0d166a (diff)
Relocated the binaries to bin/
Diffstat (limited to 'bin/byteback-snapshot')
-rwxr-xr-xbin/byteback-snapshot40
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/byteback-snapshot b/bin/byteback-snapshot
new file mode 100755
index 0000000..fc9aab3
--- /dev/null
+++ b/bin/byteback-snapshot
@@ -0,0 +1,40 @@
+#!/usr/bin/ruby
+#
+# Program to create a snapshot and/or rotate a directory of backup snapshots
+# using btrfs subvolume commands.
+#
+
+$LOAD_PATH.unshift('/usr/lib/byteback')
+
+require 'trollop'
+require 'byteback'
+include Byteback
+include Byteback::Log
+
+opts = Trollop.options do
+ opt :root, 'Backups directory (must be a btrfs subvolume)',
+ type: :string
+
+ opt :snapshot, '(ignored for compatibility)'
+
+ opt :verbose, 'Print diagnostics'
+end
+
+@root = opts[:root]
+@verbose = opts[:verbose]
+
+fatal('--root not readable') unless File.directory?("#{@root}")
+
+@backups = BackupDirectory.new(@root)
+snapshots = @backups.snapshots
+
+unless snapshots.empty?
+ last_snapshot_time = snapshots.last.time
+ fatal('Last snapshot was less than six hours ago') unless
+ !last_snapshot_time ||
+ Time.now - last_snapshot_time >= 6 * 60 * 60 # FIXME: make configurable
+end
+
+info 'Making new snapshot'
+@backups.new_snapshot!
+info 'Finished'