summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitlab-ci.yml33
-rw-r--r--Makefile5
-rw-r--r--debian/control3
-rw-r--r--lib/byteback/restore.rb3
-rw-r--r--lib/byteback/restore_file.rb9
-rw-r--r--test/tc_byteback_snapshot.rb10
-rw-r--r--test/tc_restore.rb32
-rw-r--r--test/tc_restore_file.rb5
-rw-r--r--test/ts_byteback.rb7
9 files changed, 81 insertions, 26 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..b152e89
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,33 @@
+stages:
+ - test
+ - package
+ - publish
+
+test: &test
+ stage: test
+ image: $CI_REGISTRY/docker-images/layers:jessie-ruby
+ script:
+ - apt-get install attr ruby-ffi
+ - make test
+
+package: &package
+ image: $CI_REGISTRY/docker-images/layers:$DISTRO-deb
+ variables:
+ DISTRO: jessie
+ stage: package
+ script:
+ - package
+ artifacts:
+ paths:
+ - pkg/
+
+publish:
+ stage: publish
+ variables:
+ RSYNC_HOSTNAME: repo.bytemark.co.uk
+ tags:
+ - shell
+ script:
+ - publish
+
+
diff --git a/Makefile b/Makefile
index 6a0cb38..4fe136d 100644
--- a/Makefile
+++ b/Makefile
@@ -10,8 +10,11 @@ docs: man/byteback-prune.man man/byteback-restore.man man/byteback-backup.man
# To be written
# man/byteback-snapshot.man man/byteback-setup-client.man man/byteback-setup-client-receive.man man/byteback-receive.man
+test:
+ ruby test/ts_byteback.rb
+
clean:
$(RM) man/*.man
-.PHONY: clean docs all
+.PHONY: clean docs all test
diff --git a/debian/control b/debian/control
index 8623f60..238203c 100644
--- a/debian/control
+++ b/debian/control
@@ -3,7 +3,7 @@ Section: ruby
Priority: optional
Maintainer: Patrick J Cherry <patrick@bytemark.co.uk>
Uploaders: Steve Kemp <steve@bytemark.co.uk>
-Build-Depends: debhelper (>= 7.0.50~), txt2man
+Build-Depends: debhelper (>= 7.0.50~), txt2man, ruby | ruby-interpreter, ruby-ffi, attr
Standards-Version: 3.9.6
# Vcs-Git:
Vcs-Browser: https://github.com/BytemarkHosting/byteback.git
@@ -12,6 +12,7 @@ Homepage: https://github.com/BytemarkHosting/byteback
Package: byteback
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, ruby | ruby-interpreter, rsync, openssh-client, ruby-ffi | libffi-ruby
+Recommends: btrfs-progs
Description: Maintenance-free client & server backup scripts for Linux
byteback encapsulates Bytemark's "best practice" for maintenance-free backups
with easy client and server setup.
diff --git a/lib/byteback/restore.rb b/lib/byteback/restore.rb
index d313209..7055be3 100644
--- a/lib/byteback/restore.rb
+++ b/lib/byteback/restore.rb
@@ -65,11 +65,10 @@ module Byteback
@results = paths.collect do |path|
Dir.glob(File.expand_path(File.join(@byteback_root, @snapshot, path))).collect do |f|
- restore_file = Byteback::RestoreFile.new(f, @byteback_root, @now)
+ Byteback::RestoreFile.new(f, @byteback_root, @now)
end
end.flatten
-
#
# If we want an unpruned list, return it now.
#
diff --git a/lib/byteback/restore_file.rb b/lib/byteback/restore_file.rb
index 5811b0f..daceb83 100644
--- a/lib/byteback/restore_file.rb
+++ b/lib/byteback/restore_file.rb
@@ -45,10 +45,13 @@ module Byteback
#
@snapshot = full_path.sub(%r(^#{Regexp.escape @byteback_root}),'').split("/")[1]
- if @snapshot == "current"
- @snapshot_time = @now
- else
+ #
+ # If we can parse the time, use it, otherwise assume "now".
+ #
+ begin
@snapshot_time = Time.parse(@snapshot)
+ rescue ArgumentError
+ @snapshot_time = @now
end
#
diff --git a/test/tc_byteback_snapshot.rb b/test/tc_byteback_snapshot.rb
index 87b6409..71f8c39 100644
--- a/test/tc_byteback_snapshot.rb
+++ b/test/tc_byteback_snapshot.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/backup_directory'
require 'time'
@@ -58,7 +56,7 @@ class SnapshotTest < Test::Unit::TestCase
if biggest_offset.nil? or offsets.max > biggest_offset
biggest_offset = offsets.max
else
- puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
break
end
@@ -70,7 +68,7 @@ class SnapshotTest < Test::Unit::TestCase
end
#
- # This run the same test as above, execpt with 3 hosts all competeing for space
+ # This run the same test as above, execpt with 3 hosts all competing for space
#
def test_sort_by_importance_with_multiple_hosts
start = Time.now
@@ -106,7 +104,7 @@ class SnapshotTest < Test::Unit::TestCase
if biggest_offset.nil? or offsets.max > biggest_offset
biggest_offset = offsets.max
else
- puts "Oldest backup with space for #{limit} backups and 3 hosts is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups and 3 hosts is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
break
end
@@ -154,7 +152,7 @@ class SnapshotTest < Test::Unit::TestCase
day += 1
now += 86400
end
- puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}"
+ puts "Oldest backup with space for #{limit} backups is #{offsets.max} days: #{offsets.join(", ")}" if $VERBOSE
end
end
diff --git a/test/tc_restore.rb b/test/tc_restore.rb
index 426c2b1..03e98ad 100644
--- a/test/tc_restore.rb
+++ b/test/tc_restore.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/restore'
require 'tmpdir'
@@ -10,8 +8,6 @@ class RestoreTest < Test::Unit::TestCase
def setup
@byteback_root = Dir.mktmpdir
- @snapshot = Time.now.iso8601
- FileUtils.mkdir_p(File.join(@byteback_root, @snapshot))
end
def teardown
@@ -19,18 +15,36 @@ class RestoreTest < Test::Unit::TestCase
end
def test_find
+ create_snapshot_and_check_results(Time.now.iso8601.to_s)
+ end
+
+ def test_no_barf_on_non_timestamp_snapshot_name
+ create_snapshot_and_check_results("saved-hacked-do-not-delete")
+ end
+
+ def create_snapshot_and_check_results(snapshot)
+ FileUtils.mkdir_p(File.join(@byteback_root, snapshot))
files = %w(/srv/foo.com/public/htdocs/index.html
/srv/foo.com/public/htdocs/app.php)
files.each do |f|
- FileUtils.mkdir_p(File.join(@byteback_root, @snapshot, File.dirname(f)))
- FileUtils.touch(File.join(@byteback_root, @snapshot, f))
- system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, @snapshot, f)}")
+ FileUtils.mkdir_p(File.join(@byteback_root, snapshot, File.dirname(f)))
+ FileUtils.touch(File.join(@byteback_root, snapshot, f))
+ system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, snapshot, f)}")
+ assert_equal(0, $?.exitstatus)
end
r = Byteback::Restore.find(@byteback_root, "*", "/srv/foo.com/public/htdocs/*.html")
-
- r.list
+ assert(r.results.all?{|f| f.path =~ %r{/srv/foo.com/public/htdocs/.*.html}}, "Results returned did not match requested pattern")
+ assert(r.results.all?{|f| f.snapshot == snapshot}, "Results returned were not from the correct snapshot")
+
+ # Now check that we're getting the correct stuff from the rsync attr.
+ f = r.results.first
+ assert_equal(041755, f.mode, "Incorrect mode returned")
+ assert_equal(12, f.dev_major, "Incorrect dev_major returned")
+ assert_equal(34, f.dev_minor, "Incorrect dev_minor returned")
+ assert_equal(56, f.uid, "Incorrect UID returned")
+ assert_equal(78, f.gid, "Inocrrect GID returned")
end
end
diff --git a/test/tc_restore_file.rb b/test/tc_restore_file.rb
index e9544f9..8284275 100644
--- a/test/tc_restore_file.rb
+++ b/test/tc_restore_file.rb
@@ -1,5 +1,3 @@
-$: << File.dirname(__FILE__)+"/../lib"
-
require 'test/unit'
require 'byteback/restore_file'
require 'tempfile'
@@ -20,8 +18,7 @@ class BytebackFileTest < Test::Unit::TestCase
end
def test_general
- f = Tempfile.new($0, @snapshot_path)
- puts f.path
+ f = Tempfile.new("restore-file-", @snapshot_path)
system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{f.path}")
b = Byteback::RestoreFile.new(f.path, @byteback_root)
assert_equal(041755, b.mode)
diff --git a/test/ts_byteback.rb b/test/ts_byteback.rb
new file mode 100644
index 0000000..ccee796
--- /dev/null
+++ b/test/ts_byteback.rb
@@ -0,0 +1,7 @@
+
+$: << File.dirname(__FILE__)
+$: << File.dirname(__FILE__)+"/../lib"
+
+require 'tc_restore.rb'
+require 'tc_restore_file.rb'
+require 'tc_byteback_snapshot.rb'