summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbyteback-backup35
-rwxr-xr-xbyteback-prune15
-rwxr-xr-xbyteback-receive4
-rwxr-xr-xbyteback-setup-client11
-rwxr-xr-xbyteback-setup-client-receive11
-rwxr-xr-xbyteback-snapshot9
6 files changed, 45 insertions, 40 deletions
diff --git a/byteback-backup b/byteback-backup
index cbf6f7b..202323d 100755
--- a/byteback-backup
+++ b/byteback-backup
@@ -9,6 +9,7 @@
require 'resolv'
$LOAD_PATH.unshift("/usr/lib/byteback")
+
require 'trollop'
require 'byteback/util'
require 'byteback/log'
@@ -30,7 +31,7 @@ opts = Trollop::options do
:default => ["/"]
opt :exclude, "Paths to exclude",
- :type => :strings,
+ :type => :strings,
:short => "x"
opt :verbose, "Show debugging messages"
@@ -98,23 +99,23 @@ fatal("No sources specified") if @sources.empty?
end
# Automatically exclude anything mounted on a non-local filesystem, plus
-# various cache and temporary directories common on Bytemark & Debian
+# various cache and temporary directories common on Bytemark & Debian
# systems
#
if @excludes.nil?
- PROBABLY_LOCAL = %w(
- btrfs
- ext2
- ext3
- ext4
- reiserfs
- xfs
- nilfs
- jfs
- reiser4
- zfs
- rootfs
+ PROBABLY_LOCAL = %w(
+ btrfs
+ ext2
+ ext3
+ ext4
+ reiserfs
+ xfs
+ nilfs
+ jfs
+ reiser4
+ zfs
+ rootfs
)
COMMON_JUNK = %w(
@@ -133,7 +134,7 @@ if @excludes.nil?
Hash[MOUNT_HEADINGS.zip(line.split(" "))]
end
- @excludes =
+ @excludes =
mounts.
select { |m| !PROBABLY_LOCAL.include?(m[:vfstype]) }.
@@ -186,7 +187,7 @@ def rsync(*sources)
# The timeout is set to 12 hours - rsync can spend a long time at the
# far end checking over its files at the far end without transfer, so we
# want to wait as long as possible without jeopardising the timing of the
- # next backup run. Obviously if rsync itself takes nearly 24 hours for a
+ # next backup run. Obviously if rsync itself takes nearly 24 hours for a
# given filesystem, daily backups (with this tool) are out of the question.
#
args = %w( rsync --archive --numeric-ids --delete-delay --inplace --relative --timeout 43200 )
@@ -237,7 +238,7 @@ RSYNC_EXIT_STATUSES_TO_RETRY_ON = [10,11,20,21,22,23,30]
loop do
status = rsync(*@sources)
- if RSYNC_EXIT_STATUSES_TO_ACCEPT.any?{|s| s === status}
+ if RSYNC_EXIT_STATUSES_TO_ACCEPT.any?{|s| s === status}
break
elsif RSYNC_EXIT_STATUSES_TO_RETRY_ON.any?{|s| s === status}
diff --git a/byteback-prune b/byteback-prune
index 2a92209..427ecd8 100755
--- a/byteback-prune
+++ b/byteback-prune
@@ -1,8 +1,9 @@
#!/usr/bin/ruby
#
-# Program to prune a byteback installation
+# Program to prune a byteback installation
$LOAD_PATH.unshift("/usr/lib/byteback")
+
require 'trollop'
require 'byteback'
require 'sys/filesystem'
@@ -46,8 +47,8 @@ end
@do_prune = true if @do_prune_force
-fatal("Must specify one of --prune or --list") unless
- (@do_prune || @do_list) &&
+fatal("Must specify one of --prune or --list") unless
+ (@do_prune || @do_list) &&
!(@do_prune && @do_list)
fatal("Must specify --order as 'age' or 'importance'") unless
@@ -64,7 +65,7 @@ begin
@df_history.new_reading!
rescue Errno::ENOSPC
if @do_list
- warn("Couldn't write disk history file due to lack of space, ignoring")
+ warn("Couldn't write disk history file due to lack of space, ignoring")
else
warn("Couldn't write disk history file due to lack of space, going to --prune-force")
@do_prune = @do_prune_force = true
@@ -85,10 +86,10 @@ if @do_prune_force
info("Forcing prune")
elsif @free <= @minpercent && !File.exists?(PRUNING_FLAG)
info("Starting prune #{@free}% -> #{@maxpercent} free")
- File.write(PRUNING_FLAG,"")
+ File.write(PRUNING_FLAG,"")
elsif @free >= @maxpercent && File.exists?(PRUNING_FLAG)
info("Stopping prune, reached #{@free}% free")
- File.unlink(PRUNING_FLAG)
+ File.unlink(PRUNING_FLAG)
elsif File.exists?(PRUNING_FLAG)
info("Continuing prune #{@free}% -> #{@maxpercent}, gradient = #{gradient_30m}")
end
@@ -124,7 +125,7 @@ if !@do_prune_force
end
end
-exit 0 unless
+exit 0 unless
(@do_prune && File.exists?(PRUNING_FLAG)) ||
@do_prune_force
diff --git a/byteback-receive b/byteback-receive
index 2c85005..54163d6 100755
--- a/byteback-receive
+++ b/byteback-receive
@@ -5,7 +5,8 @@
#STDERR.print ARGV.inspect + "\n"
-$LOAD_PATH << '/usr/lib/byteback'
+$LOAD_PATH.unshift("/usr/lib/byteback")
+
require 'trollop'
require 'byteback'
include Byteback::Log
@@ -49,4 +50,3 @@ else
STDERR.print "byteback-receive failed\n"
exit 9
end
-
diff --git a/byteback-setup-client b/byteback-setup-client
index 70b8ea8..5e9389f 100755
--- a/byteback-setup-client
+++ b/byteback-setup-client
@@ -2,7 +2,8 @@
#
# Run on a client machine to set up backups for the first time
-$: << '/usr/lib/byteback'
+$LOAD_PATH.unshift("/usr/lib/byteback")
+
require 'fileutils'
require 'trollop'
require 'byteback/util'
@@ -24,7 +25,7 @@ opts = Trollop::options do
opt :hostname, "Set host name for backups",
:type => :string
- opt :destination, "Backup destination (i.e. user@host:/path)",
+ opt :destination, "Backup destination (i.e. user@host:/path)",
:type => :string
end
@@ -32,7 +33,7 @@ end
@destination = opts[:destination]
@hostname = opts[:hostname]
-_dummy, @destination_user, @destination_host, colon, @destination_path =
+_dummy, @destination_user, @destination_host, colon, @destination_path =
/^(.*)?(?:@)([^:]+)(:)(.*)?$/.match(@destination).to_a
@destination_user ||= 'byteback'
@@ -50,7 +51,7 @@ if File.readable?("/etc/byteback/key")
warn "Skipping key generation, delete /etc/byteback/key if that's wrong"
else
- error "Couldn't generate SSH key" unless
+ error "Couldn't generate SSH key" unless
system <<-KEYGEN
ssh-keygen -q -t rsa -C "byteback client key" \
-N "" -f /etc/byteback/key
@@ -63,7 +64,7 @@ key_pub = File.read("/etc/byteback/key.pub").chomp
error "Remote setup didn't work" unless
system("ssh -i /etc/byteback/key -l #{@destination_user} #{@destination_host} byteback-setup-client-receive #{@hostname} #{key_pub}")
-File.open("/etc/byteback/destination", "w") do |f|
+File.open("/etc/byteback/destination", "w") do |f|
f.print "#{@destination_user}@#{@destination_host}:#{@destination_path}"
end
diff --git a/byteback-setup-client-receive b/byteback-setup-client-receive
index 0dc850f..e17c30b 100755
--- a/byteback-setup-client-receive
+++ b/byteback-setup-client-receive
@@ -2,7 +2,8 @@
#
# Called by byteback-setup-client to set up a new byteback-setup-client
-$: << '/usr/lib/byteback'
+$LOAD_PATH.unshift("/usr/lib/byteback")
+
require 'fileutils'
require 'trollop'
require 'byteback/util'
@@ -19,7 +20,7 @@ end
@pubkey = ARGV.join(" ")
error("You must call this from byteback-setup-client on remote host") unless
- @hostname &&
+ @hostname &&
/^ssh/.match(@pubkey) &&
ENV['SSH_CONNECTION']
@@ -29,15 +30,15 @@ Dir.chdir(ENV['HOME']) # don't know why we wouldn't be here
FileUtils.mkdir_p(@hostname)
-error("Couldn't create btrfs subvolume") unless
+error("Couldn't create btrfs subvolume") unless
system("/sbin/btrfs subvolume create #{@hostname}/current")
FileUtils.mkdir_p(".ssh")
-if File.exists?(".ssh/authorized_keys") &&
+if File.exists?(".ssh/authorized_keys") &&
File.read(".ssh/authorized_keys").match(@pubkey.split(/\s+/)[1])
- warn("This key already exists in .ssh/authorized_keys on server, nothing to do!")
+ warn("This key already exists in .ssh/authorized_keys on server, nothing to do!")
else
diff --git a/byteback-snapshot b/byteback-snapshot
index d3645b5..706701c 100755
--- a/byteback-snapshot
+++ b/byteback-snapshot
@@ -1,9 +1,10 @@
#!/usr/bin/ruby
#
-# Program to create a snapshot and/or rotate a directory of backup snapshots
+# 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
@@ -30,12 +31,12 @@ snapshots = @backups.snapshots
if !snapshots.empty?
last_snapshot_time = snapshots.last.time
- fatal("Last snapshot was less than six hours ago") unless
- !last_snapshot_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
end
info "Making new snapshot"
-@backups.new_snapshot!
+@backups.new_snapshot!
info "Finished"