From 668b9871e64cb82ac30c8defb29d56d774f3c140 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 1 Dec 2015 22:41:06 +0000 Subject: Completely re-vamped restore command. Fixes #12403 The byteback-restore command now uses the rsync xattrs to display information about the files due to be restored. It can handle filenames with spaces (!) and other characters. --- test/tc_restore.rb | 36 ++++++++++++++++++++++++++++++++++++ test/tc_restore_file.rb | 22 ++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/tc_restore.rb create mode 100644 test/tc_restore_file.rb (limited to 'test') diff --git a/test/tc_restore.rb b/test/tc_restore.rb new file mode 100644 index 0000000..f1e8b04 --- /dev/null +++ b/test/tc_restore.rb @@ -0,0 +1,36 @@ +$: << File.dirname(__FILE__)+"/../lib" + +require 'test/unit' +require 'byteback/restore' +require 'tmpdir' +require 'time' +require 'fileutils' + +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 + FileUtils.remove_entry_secure @byteback_root + end + + def test_find + 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)}") + end + + r = Byteback::Restore.find(@byteback_root, "/srv/foo.com/public/htdocs/*.html") + + r.list + end + +end diff --git a/test/tc_restore_file.rb b/test/tc_restore_file.rb new file mode 100644 index 0000000..b0497b3 --- /dev/null +++ b/test/tc_restore_file.rb @@ -0,0 +1,22 @@ +$: << File.dirname(__FILE__)+"/../lib" + +require 'test/unit' +require 'byteback/restore_file' +require 'tempfile' + +class BytebackFileTest < Test::Unit::TestCase + + def test_general + f = Tempfile.new($0) + system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{f.path}") + b = Byteback::RestoreFile.new(f.path) + assert_equal(041755, b.mode) + assert_equal(12, b.maj) + assert_equal(34, b.min) + assert_equal(56, b.uid) + assert_equal(78, b.gid) + assert_equal("drwxr-xr-t", b.modestring) + assert_kind_of(Time, f.mtime) + end + +end -- cgit v1.2.1