summaryrefslogtreecommitdiff
path: root/byteback-receive
blob: d412beaa4bac832604bb7c2a77dfb7e48f439568 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/ruby
#
# Program to receive backups and run rsync in receive mode.  Must check that
# user as authorised by SSH is allowed to access particular directory.

#STDERR.print ARGV.inspect + "\n"

$LOAD_PATH << '/usr/lib/byteback'
require 'trollop'
require 'byteback'
include Byteback::Log

#debug "ARGV=#{ARGV.inspect}\nSSH_ORIGINAL_COMMAND=#{ENV['SSH_ORIGINAL_COMMAND']}\n"

if ENV['SSH_ORIGINAL_COMMAND']
	ARGV.concat(ENV['SSH_ORIGINAL_COMMAND'].split(" "))
end

#STDERR.print "after ARGV=#{ARGV.inspect}\n"

byteback_host = ENV['BYTEBACK_HOST']
fatal("BYTEBACK_HOST environment not set") unless byteback_host

byteback_root = ENV['HOME'] + "/" + ENV["BYTEBACK_HOST"]
fatal("#{byteback_root} does not exist") unless File.directory?(byteback_root)

# force destination to be where we expect
#
if ARGV[0] == 'rsync'
	ARGV[-1] = "#{byteback_root}/current"
	exec(*ARGV)
elsif ARGV[0] == 'byteback-snapshot'
	ARGV.concat(["--root", "#{byteback_root}"])
	exec(*ARGV)
end

opts = Trollop::options do
	opt :verbose, "Print diagnostics"
	opt :ping, "Check connection parameters and exit"
	opt :complete, "Mark current backup as complete"
end

error("Please only choose one mode") if opts[:ping] && opts[:complete]
if opts[:complete]
	system("byteback-snapshot", byteback_root)
elsif opts[:ping]
	exit 0
else
	STDERR.print "byteback-receive failed\n"
	exit 9
end