diff options
| author | Steve Kemp <steve@steve.org.uk> | 2015-06-03 12:50:00 +0100 | 
|---|---|---|
| committer | Steve Kemp <steve@steve.org.uk> | 2015-06-03 12:50:00 +0100 | 
| commit | 1877a5d328f918540e75444747a7b3903803c8cc (patch) | |
| tree | aeaa663dcccb18633ab359769aa716e977140e23 | |
| parent | 30cdbf783417b74c3c1a2a07d48bd0ab6399f5c4 (diff) | |
Working restorations.
| -rwxr-xr-x | byteback-receive | 26 | ||||
| -rwxr-xr-x | byteback-restore | 15 | 
2 files changed, 33 insertions, 8 deletions
| diff --git a/byteback-receive b/byteback-receive index 1c8f4ae..9756978 100755 --- a/byteback-receive +++ b/byteback-receive @@ -3,13 +3,13 @@  # 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 +  if ENV['SSH_ORIGINAL_COMMAND']  	ARGV.concat(ENV['SSH_ORIGINAL_COMMAND'].split(" "))  end @@ -20,11 +20,22 @@ 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) +#  Force restores to be limited to the hostname we're connecting form +# +if ( ARGV[0] == 'restore' ) +     ARGV[0] = 'rsync' +     a = [] +     ARGV.each do |tmp| +        if ( tmp =~ /^\/(.*)/ ) +           tmp = "#{byteback_host}/#{$1.dup}" +        end +        a.push(tmp) +     end +     exec(*a) +eslif ARGV[0] == 'rsync' +        ARGV[-1] = "#{byteback_root}/current" +  exec(*ARGV)  elsif ARGV[0] == 'byteback-snapshot'  	ARGV.concat(["--root", "#{byteback_root}"])  	exec(*ARGV) @@ -34,6 +45,7 @@ opts = Trollop::options do  	opt :verbose, "Print diagnostics"  	opt :ping, "Check connection parameters and exit"  	opt :list, "Show backed up files matching the given pattern", :type => :string +	opt :restore, "Perform a restoration operation", :type => :string  	opt :complete, "Mark current backup as complete"  end @@ -41,7 +53,7 @@ error("Please only choose one mode") if opts[:ping] && opts[:complete]  if opts[:complete]  	system("byteback-snapshot", "--root", byteback_root)  elsif opts[:list] -	system( "find #{byteback_root} -print | grep #{opts[:list]}" ) +	system( "cd #{byteback_root} && find . -print | grep #{opts[:list]}" )  	exit(0 )  elsif opts[:ping]  	exit 0 diff --git a/byteback-restore b/byteback-restore index 00964f1..4972cf4 100755 --- a/byteback-restore +++ b/byteback-restore @@ -47,8 +47,21 @@ def list_files( pattern )  end +# +#  We cannot use plain 'rsync' here because the receiver command will +# see that, and rewrite our arguments. +# +#  To cater to this we have to wrap the rsync for the restore and we +# do that by setting "rsync-path" to point to the receiver program. +# +#  def restore_file( path, revision ) -  puts "Restoring revision #{revision} of file #{path}" +  cmd = %w( rsync ) +  cmd += [ "--rsh", "ssh -o BatchMode=yes -x -a -i /etc/byteback/key -l byteback" ] +  cmd += [ "--rsync-path", "restore" ] +  cmd += [ "#{@destination_host}:/#{revision}/#{path}", "." ] +  system(*cmd) +  end | 
