summaryrefslogtreecommitdiff
path: root/byteback-receive
diff options
context:
space:
mode:
authorMatthew Bloch <matthew@bytemark.co.uk>2014-01-06 02:19:54 +0000
committerMatthew Bloch <matthew@bytemark.co.uk>2014-01-06 02:19:54 +0000
commitc138effe83fe68234d9f630b62b52c3fdfdaca6a (patch)
tree2d44db957098eff9e73a3b09785413a2467d7b3a /byteback-receive
parent103d4e4278feed14dc5cf732d9c9875220cb8eff (diff)
First commit of working code, needs a lot more writing and testing
Diffstat (limited to 'byteback-receive')
-rw-r--r--byteback-receive52
1 files changed, 52 insertions, 0 deletions
diff --git a/byteback-receive b/byteback-receive
new file mode 100644
index 0000000..1d87f6f
--- /dev/null
+++ b/byteback-receive
@@ -0,0 +1,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.
+
+require 'trollop'
+
+def error(message)
+ STDERR.print "*** #{message}\n"
+ exit 1
+end
+
+#STDERR.print "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}"
+
+byteback_host = ENV['BYTEBACK_HOST']
+error("BYTEBACK_HOST environment not set") unless byteback_host
+
+byteback_root = ENV['HOME'] + "/" + ENV["BYTEBACK_HOST"]
+error("#{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[0] == 'sudo' && ARGV[1] == '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
+