summaryrefslogtreecommitdiff
path: root/byteback-snapshot
blob: 0f0c9e95c29d75eba90506ce44a38d2334f15102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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)

last_snapshot_time = @backups.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

info "Making new snapshot"
@backups.new_snapshot! 

info "Finished"