summaryrefslogtreecommitdiff
path: root/byteback-backup
diff options
context:
space:
mode:
authorMatthew Bloch <matthew@bytemark.co.uk>2014-01-08 12:34:52 +0000
committerMatthew Bloch <matthew@bytemark.co.uk>2014-01-08 12:34:52 +0000
commit760e0243daa0db0baef0ec209cd3fe5639c82fcb (patch)
tree324bb1059e02df5435f789859fbea2d6fe1ab06c /byteback-backup
parentc138effe83fe68234d9f630b62b52c3fdfdaca6a (diff)
Put ssh options in common function, moved hostname invocation to the place where we actually use it.
Diffstat (limited to 'byteback-backup')
-rw-r--r--byteback-backup44
1 files changed, 18 insertions, 26 deletions
diff --git a/byteback-backup b/byteback-backup
index 52a7d28..ffc4186 100644
--- a/byteback-backup
+++ b/byteback-backup
@@ -9,8 +9,6 @@
require 'trollop'
require 'resolv'
-HOSTNAME = `hostname -f`
-
@sources = ["/"]
@exclude = ["/swap.file", "/var/backups/localhost"]
@@ -76,8 +74,9 @@ end
#
if !@destination
guesses = []
+ hostname = `hostname -f`
Resolv::DNS.open do |dns|
- suffix = HOSTNAME.split(".")[2..-1].join(".")
+ suffix = hostname.split(".")[2..-1].join(".")
["byteback." + suffix].each do |name|
[Resolv::DNS::Resource::IN::AAAA,
Resolv::DNS::Resource::IN::A].each do |record_type|
@@ -91,7 +90,7 @@ if !@destination
error "Couldn't guess at backup host, please specify --destination"
end
- # ick, do I really have to do this to get a string represnetation of
+ # ick, do I really have to do this to get a string represnetion of
# the IP address?
#
guess = guesses.first.inspect
@@ -106,16 +105,18 @@ end
#
error("Could not read ssh key #{@ssh_key}") unless File.readable?(@ssh_key)
-error("Could not connect to #{@destination}") unless system(
- "ssh",
- "-a",
- "-i",
- @ssh_key,
- @destination.split(":")[0],
- "byteback-receive",
- "--ping",
- "#{@verbose}"
-)
+def ssh(*args)
+ ["ssh",
+ "-o", "BatchMode=yes",
+ "-x", "-a",
+ "-i", @ssh_key,
+ "-l", @destination_user
+ ] +
+ args
+end
+
+error("Could not connect to #{@destination}") unless
+ system(*ssh("byteback-receive", "--ping", @verbose))
# Call rsync to copy certain sources, returns exit status (see man rsync)
#
@@ -133,7 +134,7 @@ def rsync(*sources)
"--rsync-path",
"rsync --fake-super",
"--rsh",
- "ssh -a -i #{@ssh_key} -l #{@destination_user}",
+ ssh.join(" "),
"--delete",
"--one-file-system",
"--relative"
@@ -174,14 +175,5 @@ end
# Mark the backup as done on the other end
#
-error("Backup could not be marked complete") unless system(
- "ssh",
- "-a",
- "-i",
- @ssh_key,
- @destination.split(":")[0],
- "sudo",
- "byteback-snapshot",
- "--snapshot",
- "#{@verbose}"
-)
+error("Backup could not be marked complete") unless
+ system(*ssh("sudo", "byteback-snapshot", "--snapshot", @verbose))