siba 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +18 -0
  4. data/LICENSE +22 -0
  5. data/README.md +47 -0
  6. data/Rakefile +27 -0
  7. data/bin/siba +5 -0
  8. data/lib/siba.rb +27 -0
  9. data/lib/siba/backup.rb +31 -0
  10. data/lib/siba/console.rb +196 -0
  11. data/lib/siba/errors.rb +8 -0
  12. data/lib/siba/generator.rb +115 -0
  13. data/lib/siba/globals.rb +19 -0
  14. data/lib/siba/helpers/encoding_helper.rb +38 -0
  15. data/lib/siba/helpers/file_helper.rb +89 -0
  16. data/lib/siba/helpers/gem_helper.rb +22 -0
  17. data/lib/siba/helpers/password_strength.rb +94 -0
  18. data/lib/siba/helpers/security_helper.rb +30 -0
  19. data/lib/siba/helpers/string_helper.rb +32 -0
  20. data/lib/siba/helpers/test/extend_test.rb +114 -0
  21. data/lib/siba/helpers/test/file_mock.rb +38 -0
  22. data/lib/siba/helpers/test/helper.rb +55 -0
  23. data/lib/siba/helpers/test/kernel_mock.rb +44 -0
  24. data/lib/siba/helpers/test/removable_constants.rb +18 -0
  25. data/lib/siba/helpers/test/require.rb +12 -0
  26. data/lib/siba/logger_plug.rb +36 -0
  27. data/lib/siba/options_backup.rb +37 -0
  28. data/lib/siba/options_loader.rb +38 -0
  29. data/lib/siba/plugins/archive/tar/archive.rb +117 -0
  30. data/lib/siba/plugins/archive/tar/init.rb +38 -0
  31. data/lib/siba/plugins/archive/tar/options.yml +1 -0
  32. data/lib/siba/plugins/destination/dir/dest_dir.rb +77 -0
  33. data/lib/siba/plugins/destination/dir/init.rb +31 -0
  34. data/lib/siba/plugins/destination/dir/options.yml +2 -0
  35. data/lib/siba/plugins/encryption/gpg/encryption.rb +140 -0
  36. data/lib/siba/plugins/encryption/gpg/init.rb +45 -0
  37. data/lib/siba/plugins/encryption/gpg/options.yml +2 -0
  38. data/lib/siba/plugins/installed_plugins.rb +77 -0
  39. data/lib/siba/plugins/plugin_loader.rb +100 -0
  40. data/lib/siba/plugins/plugins.rb +57 -0
  41. data/lib/siba/plugins/plugins.yml +9 -0
  42. data/lib/siba/plugins/source/files/files.rb +166 -0
  43. data/lib/siba/plugins/source/files/init.rb +33 -0
  44. data/lib/siba/plugins/source/files/options.yml +11 -0
  45. data/lib/siba/restore.rb +113 -0
  46. data/lib/siba/scaffold.rb +166 -0
  47. data/lib/siba/siba_check.rb +75 -0
  48. data/lib/siba/siba_file.rb +89 -0
  49. data/lib/siba/siba_kernel.rb +37 -0
  50. data/lib/siba/siba_logger.rb +172 -0
  51. data/lib/siba/tasks/siba_task.rb +42 -0
  52. data/lib/siba/tasks/siba_tasks.rb +120 -0
  53. data/lib/siba/test_files.rb +76 -0
  54. data/lib/siba/test_files/a_file +1 -0
  55. data/lib/siba/test_files/files_and_dirs/.hidden +1 -0
  56. data/lib/siba/test_files/files_and_dirs/.hidden_dir/file10 +1 -0
  57. data/lib/siba/test_files/files_and_dirs/File With Spaces +1 -0
  58. data/lib/siba/test_files/files_and_dirs/dir1/file10 +1 -0
  59. data/lib/siba/test_files/files_and_dirs/dir1/sub-dir/file111.txt +1 -0
  60. data/lib/siba/test_files/files_and_dirs/file1 +1 -0
  61. data/lib/siba/test_files/files_and_dirs/file2.txt +1 -0
  62. data/lib/siba/tmp_dir.rb +94 -0
  63. data/lib/siba/version.rb +5 -0
  64. data/scaffolds/archive.rb +26 -0
  65. data/scaffolds/destination.rb +20 -0
  66. data/scaffolds/encryption.rb +26 -0
  67. data/scaffolds/project/.gitignore +5 -0
  68. data/scaffolds/project/Gemfile +4 -0
  69. data/scaffolds/project/Guardfile +9 -0
  70. data/scaffolds/project/LICENSE +22 -0
  71. data/scaffolds/project/README.md +33 -0
  72. data/scaffolds/project/Rakefile +28 -0
  73. data/scaffolds/project/lib/siba-c6y-demo.rb +11 -0
  74. data/scaffolds/project/lib/siba-c6y-demo/options.yml +2 -0
  75. data/scaffolds/project/lib/siba-c6y-demo/version.rb +9 -0
  76. data/scaffolds/project/siba-c6y-demo.gemspec +26 -0
  77. data/scaffolds/project/test/helper/require_integration.rb +5 -0
  78. data/scaffolds/project/test/helper/require_unit.rb +4 -0
  79. data/scaffolds/project/test/integration/i9n_init.rb +35 -0
  80. data/scaffolds/project/test/unit/test_init.rb +43 -0
  81. data/scaffolds/project/test/unit/yml/valid.yml +8 -0
  82. data/scaffolds/shared/examples.rb +47 -0
  83. data/scaffolds/shared/init_example.rb +13 -0
  84. data/scaffolds/source.rb +25 -0
  85. data/siba.gemspec +30 -0
  86. data/test/helper/require_integration.rb +4 -0
  87. data/test/helper/require_unit.rb +4 -0
  88. data/test/integration/helpers/i9n_file_helper.rb +50 -0
  89. data/test/integration/i9n_backup.rb +53 -0
  90. data/test/integration/i9n_console.rb +16 -0
  91. data/test/integration/i9n_generator.rb +29 -0
  92. data/test/integration/i9n_options_backup.rb +22 -0
  93. data/test/integration/i9n_scaffold.rb +27 -0
  94. data/test/integration/i9n_siba_file.rb +30 -0
  95. data/test/integration/i9n_test_unicode_files.rb +40 -0
  96. data/test/integration/i9n_tmp_dir.rb +44 -0
  97. data/test/integration/plugins/archive/tar/i9n_archive.rb +18 -0
  98. data/test/integration/plugins/destination/dir/i9n_dest_dir.rb +52 -0
  99. data/test/integration/plugins/encryption/gpg/i9n_encryption.rb +87 -0
  100. data/test/integration/plugins/i9n_installed_plugins.rb +13 -0
  101. data/test/integration/plugins/source/files/i9n_files.rb +146 -0
  102. data/test/integration/tasks/i9n_siba_tasks.rb +30 -0
  103. data/test/integration/yml/valid.yml +16 -0
  104. data/test/unit/helpers/test_encoding_helper.rb +17 -0
  105. data/test/unit/helpers/test_gem_helper.rb +17 -0
  106. data/test/unit/helpers/test_security_helper.rb +21 -0
  107. data/test/unit/helpers/test_string_helper.rb +35 -0
  108. data/test/unit/plugins/archive/tar/test_archive.rb +41 -0
  109. data/test/unit/plugins/archive/tar/test_init.rb +36 -0
  110. data/test/unit/plugins/archive/tar/yml/archive/check_installed.yml +2 -0
  111. data/test/unit/plugins/archive/tar/yml/init/default_compression.yml +1 -0
  112. data/test/unit/plugins/archive/tar/yml/init/invalid_compression.yml +2 -0
  113. data/test/unit/plugins/archive/tar/yml/init/valid.yml +2 -0
  114. data/test/unit/plugins/destination/dir/test_dest_dir.rb +41 -0
  115. data/test/unit/plugins/destination/dir/test_init.rb +36 -0
  116. data/test/unit/plugins/destination/dir/yml/init/valid.yml +2 -0
  117. data/test/unit/plugins/encryption/gpg/test_encryption.rb +70 -0
  118. data/test/unit/plugins/encryption/gpg/test_init.rb +47 -0
  119. data/test/unit/plugins/source/files/test_files.rb +44 -0
  120. data/test/unit/plugins/source/files/test_init.rb +48 -0
  121. data/test/unit/plugins/source/files/test_path_match.rb +140 -0
  122. data/test/unit/plugins/source/files/yml/ignore_list.yml +8 -0
  123. data/test/unit/plugins/source/files/yml/ignore_not_array.yml +5 -0
  124. data/test/unit/plugins/source/files/yml/include_not_array.yml +3 -0
  125. data/test/unit/plugins/source/files/yml/include_subdirs_false.yml +6 -0
  126. data/test/unit/plugins/source/files/yml/include_subdirs_missing.yml +5 -0
  127. data/test/unit/plugins/source/files/yml/no_ignore.yml +4 -0
  128. data/test/unit/plugins/source/files/yml/no_include.yml +1 -0
  129. data/test/unit/plugins/source/files/yml/valid.yml +9 -0
  130. data/test/unit/plugins/test_installed_plugins.rb +32 -0
  131. data/test/unit/plugins/test_plugin_loader.rb +27 -0
  132. data/test/unit/plugins/test_plugins.rb +44 -0
  133. data/test/unit/tasks/test_siba_task.rb +30 -0
  134. data/test/unit/tasks/test_siba_tasks.rb +84 -0
  135. data/test/unit/tasks/yml/task/invalid.yml +4 -0
  136. data/test/unit/tasks/yml/task/valid.yml +7 -0
  137. data/test/unit/test_backup.rb +18 -0
  138. data/test/unit/test_console.rb +166 -0
  139. data/test/unit/test_generator.rb +21 -0
  140. data/test/unit/test_globals.rb +34 -0
  141. data/test/unit/test_log_message.rb +26 -0
  142. data/test/unit/test_logger_plug.rb +49 -0
  143. data/test/unit/test_options_backup.rb +21 -0
  144. data/test/unit/test_options_loader.rb +72 -0
  145. data/test/unit/test_password_strength.rb +76 -0
  146. data/test/unit/test_restore.rb +18 -0
  147. data/test/unit/test_scaffold.rb +26 -0
  148. data/test/unit/test_siba_check.rb +118 -0
  149. data/test/unit/test_siba_logger.rb +174 -0
  150. data/test/unit/test_tmp_dir.rb +21 -0
  151. data/test/unit/yml/options_loader/array.yml +2 -0
  152. data/test/unit/yml/options_loader/empty.yml +0 -0
  153. data/test/unit/yml/options_loader/invalid.yml +4 -0
  154. data/test/unit/yml/options_loader/string.yml +1 -0
  155. data/test/unit/yml/options_loader/utf8_with_bom.yml +2 -0
  156. data/test/unit/yml/options_loader/valid.yml +12 -0
  157. data/test/unit/yml/siba_options_backup.yml +20 -0
  158. data/test/unit/yml/valid.yml +18 -0
  159. metadata +240 -0
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+
3
+ module SibaTest
4
+ # mocks all Siba::SibaFile methods
5
+ class FileMock
6
+ def method_missing(meth, *args, &block)
7
+ if FileMock.method_defined? meth
8
+ # do nothing
9
+ else
10
+ super
11
+ end
12
+ end
13
+
14
+ def respond_to?(meth)
15
+ if FileMock.method_defined? meth
16
+ true
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def self.mock_all_methods
23
+ Siba::FilePlug.siba_file = SibaTest::FileMock.new
24
+ end
25
+
26
+ def file_expand_path(file_name)
27
+ file_name
28
+ end
29
+
30
+ private
31
+
32
+ def self.method_defined?(method_name)
33
+ file_class, method = Siba::SibaFile.get_file_class(method_name)
34
+ return true if !file_class.nil? && file_class.respond_to?(method)
35
+ Siba::SibaFile.instance_methods(false).include? method_name.to_sym
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: UTF-8
2
+
3
+ module SibaTest
4
+ IS_WINDOWS = !(RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/).nil?
5
+ UNICODE_FILE_NAME = "алиен学"
6
+ TmpDirMocked = "/tmp"
7
+
8
+ class << self
9
+ include Siba::TmpDirPlug
10
+
11
+ def init
12
+ require 'minitest/pride' unless SibaTest::IS_WINDOWS
13
+
14
+ @loaded_options = {}
15
+ @current_dir = siba_file.file_utils_pwd
16
+
17
+ MiniTest::Unit::TestCase.add_setup_hook do
18
+ Siba::SibaLogger.quiet = true
19
+ Siba::SibaLogger.no_log = true
20
+ Siba::LoggerPlug.create "Test", nil
21
+ Siba::SibaLogger.messages = []
22
+ Siba.settings = {}
23
+ Siba.current_dir = @current_dir
24
+ Siba.backup_name = "siba"
25
+ SibaTest::KernelMock.mock_all_methods # prevents tests from accessing Kernel methods
26
+ end
27
+
28
+ MiniTest::Unit::TestCase.add_teardown_hook do
29
+ Siba::LoggerPlug.close
30
+ end
31
+ end
32
+
33
+ def init_unit
34
+ init
35
+ MiniTest::Unit::TestCase.add_setup_hook do
36
+ SibaTest::FileMock.mock_all_methods # prevents tests from doing file operations
37
+ Siba.class_eval {@tmp_dir = SibaTest::TmpDirMocked}
38
+ end
39
+ end
40
+
41
+ def init_integration
42
+ init
43
+ MiniTest::Unit::TestCase.add_teardown_hook do
44
+ # cleanup after each integration test
45
+ Siba.current_dir = @current_dir
46
+ Siba.cleanup_tmp_dir
47
+ SibaTest.cleanup_tmp_dir
48
+ end
49
+ end
50
+
51
+ def load_options(path_to_yml)
52
+ @loaded_options[path_to_yml] ||= Siba::OptionsLoader.load_yml(path_to_yml)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ module SibaTest
4
+ # mocks all Siba::SibaKernel methods
5
+ class KernelMock
6
+ undef_method :puts
7
+ def method_missing(meth, *args, &block)
8
+ if KernelMock.method_defined? meth
9
+ # do nothing
10
+ else
11
+ super
12
+ end
13
+ end
14
+
15
+ def respond_to?(meth)
16
+ if KernelMock.method_defined? meth
17
+ true
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+
24
+ class << self
25
+ # the valud 'siba_kernel.gets' method will return
26
+ attr_accessor :gets_return_value
27
+
28
+ def mock_all_methods
29
+ Siba::KernelPlug.siba_kernel = SibaTest::KernelMock.new
30
+ SibaTest::KernelMock.gets_return_value = nil
31
+ end
32
+ end
33
+
34
+ def gets(*args)
35
+ SibaTest::KernelMock.gets_return_value
36
+ end
37
+
38
+ private
39
+
40
+ def self.method_defined?(method_name)
41
+ return Kernel.respond_to? method_name
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ # Helper used to re-init constants
4
+ # Based on http://stackoverflow.com/questions/3375360/how-to-redefine-a-ruby-constant-without-warning
5
+ module SibaTest
6
+ module RemovableConstants
7
+ class << self
8
+ def def_if_not_defined(cls, const, value)
9
+ cls.const_set(const, value) unless cls.const_defined?(const)
10
+ end
11
+
12
+ def redef_without_warning(cls, const, value)
13
+ cls.send(:remove_const, const) if cls.const_defined?(const)
14
+ cls.const_set(const, value)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ gem 'minitest' # loads minitest from gem, not the included one
5
+ require 'minitest/autorun'
6
+
7
+ require 'siba'
8
+ require 'siba/helpers/test/file_mock'
9
+ require 'siba/helpers/test/kernel_mock'
10
+ require 'siba/helpers/test/extend_test'
11
+ require 'siba/helpers/test/removable_constants'
12
+ require 'siba/helpers/test/helper'
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'siba/siba_logger'
4
+
5
+ module Siba
6
+ # Used to inject "logger" to classes that include this module
7
+ module LoggerPlug
8
+ def logger
9
+ LoggerPlug.logger
10
+ end
11
+
12
+ class << self
13
+ def logger
14
+ raise Siba::Error, "Log is not created" unless LoggerPlug.opened?
15
+ @logger
16
+ end
17
+
18
+ def create(name, path_to_log_file, show_start_message = true)
19
+ raise Siba::Error, "Log is already created" if LoggerPlug.opened?
20
+ @logger = SibaLogger.new name, path_to_log_file, show_start_message
21
+ end
22
+
23
+ def close
24
+ @logger.close if LoggerPlug.opened?
25
+ @logger = nil
26
+ SibaLogger.quiet = false
27
+ SibaLogger.verbose = false
28
+ SibaLogger.no_log = false
29
+ end
30
+
31
+ def opened?
32
+ !@logger.nil?
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+
3
+ module Siba
4
+ class OptionsBackup
5
+ OPTIONS_BACKUP_FILE_NAME = "siba_options_backup.yml"
6
+
7
+ class << self
8
+ include Siba::FilePlug
9
+ include Siba::LoggerPlug
10
+
11
+ def save_options_backup(path_to_options, to_dir)
12
+ data = Siba::FileHelper.read path_to_options
13
+ data << "\n\ncurrent_dir: \"#{Siba::StringHelper.escape_for_yaml(Siba.current_dir)}\""
14
+ options_backup_path = File.join to_dir, OPTIONS_BACKUP_FILE_NAME
15
+ siba_file.run_this do
16
+ Siba::FileHelper.write options_backup_path, data
17
+ end
18
+ end
19
+
20
+ def load_source_from_backup(dir)
21
+ path_to_options_backup = File.join dir, OPTIONS_BACKUP_FILE_NAME
22
+ options_backup = Siba::OptionsLoader.load_yml path_to_options_backup
23
+ Siba.current_dir = SibaCheck.options_string options_backup, "current_dir"
24
+ unless siba_file.file_directory? Siba.current_dir
25
+ begin
26
+ siba_file.file_utils_mkpath Siba.current_dir
27
+ rescue Exception
28
+ logger.error "Can not access the backup current directory #{Siba.current_dir}"
29
+ raise
30
+ end
31
+ end
32
+ SibaTask.new options_backup, "source"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'erb'
4
+ require 'yaml'
5
+
6
+ module Siba
7
+ module OptionsLoader
8
+ class << self
9
+ include Siba::LoggerPlug
10
+ def load_yml(path_to_yml)
11
+ logger.debug "Loading options from #{path_to_yml}"
12
+ raise Siba::Error, "Options file must have .yml extension: #{path_to_yml}" unless path_to_yml =~ /\.yml$/
13
+
14
+ unless File.exists? path_to_yml
15
+ raise Siba::Error, "Could not read the options file #{path_to_yml}.
16
+ Make sure the file exists and you have read access to it."
17
+ end
18
+
19
+ begin
20
+ hash = load_hash_from_yml path_to_yml
21
+ raise Siba::Error, "invalid format" unless hash.is_a? Hash
22
+ return hash
23
+ rescue Exception => e
24
+ raise Siba::Error, "Error loading options file #{path_to_yml}: " + e.message
25
+ end
26
+ end
27
+
28
+ def load_hash_from_yml(path_to_yml)
29
+ YAML.load(load_erb path_to_yml)
30
+ end
31
+
32
+ def load_erb(path_to_file)
33
+ data = Siba::FileHelper.read path_to_file
34
+ ERB.new(data).result
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,117 @@
1
+ # encoding: UTF-8
2
+
3
+ module Siba::Archive
4
+ module Tar
5
+ class Archive
6
+ include Siba::FilePlug
7
+ include Siba::LoggerPlug
8
+ attr_accessor :compression
9
+
10
+ def initialize(compression)
11
+ @compression = compression
12
+ check_installed
13
+ end
14
+
15
+ # Returns the archive name
16
+ def archive(sources_dir, dest_dir, dest_file_name)
17
+ Siba::Archive::Tar::Archive.check_compression_type compression
18
+
19
+ options = get_tar_option
20
+ extension = Archive.get_tar_extension compression
21
+
22
+ archive_name = "#{dest_file_name}.tar#{extension}"
23
+ archive_path = File.join(dest_dir, archive_name)
24
+ siba_file.run_this do
25
+ raise Siba::Error, "Archive file already exists: #{archive_path}" if siba_file.file_file?(archive_path) || siba_file.file_directory?(archive_path)
26
+
27
+ siba_file.file_utils_cd dest_dir
28
+ command_text = %(tar c#{options}f #{archive_name} -C "#{sources_dir}" .)
29
+ # Using -C 'change directory' option to make it work on Windows
30
+ # because Windows will not understand absolute path to tar: "tar cf c:\dir\file.tar ."
31
+ siba_file.run_shell command_text, "Failed to archive: #{command_text}"
32
+ raise Siba::Error, "Failed to create archive: #{command_text}" unless siba_file.file_file?(archive_path)
33
+ end
34
+ archive_name
35
+ end
36
+
37
+ def extract(archive_path, destination_dir)
38
+ options = get_tar_option
39
+ archive_name = File.basename archive_path
40
+ archive_dir = File.dirname archive_path
41
+ siba_file.file_utils_cd archive_dir
42
+ command_text = %(tar x#{options}f #{archive_name} -C "#{destination_dir}")
43
+ # Using -C 'change directory' option to make it work on Windows
44
+ # because Windows will not understand absolute path to tar: "tar xf c:\dir\file.tar"
45
+
46
+ siba_file.run_this do
47
+ unless siba_file.shell_ok? command_text
48
+ raise Siba::Error, "Failed to extract archive: #{command_text}"
49
+ end
50
+ end
51
+ end
52
+
53
+ # Making sure tar is installed and works: tars and un-tars a test file
54
+ def check_installed
55
+ siba_file.run_this("test installed") do
56
+ siba_file.run_shell("tar --help", "'tar' utility is not found. Please install it.")
57
+
58
+ begin
59
+ test_archive_and_extract
60
+ rescue Exception
61
+ logger.error "'tar' utility does not work correctly. Try reinstalling it."
62
+ raise
63
+ end
64
+ logger.debug "TAR archiver is verified"
65
+ end
66
+ end
67
+
68
+ def test_archive_and_extract
69
+ # archive
70
+ src_dir = Siba::TestFiles.prepare_test_dir "tar-archive-src"
71
+ dest_dir = Siba::TestFiles.mkdir_in_tmp_dir "tar-archive-dest"
72
+ file_name = "myname"
73
+ archive src_dir, dest_dir, file_name
74
+ path_to_file = File.join(dest_dir,"#{file_name}.tar#{Archive.get_tar_extension(compression)}")
75
+ raise unless siba_file.file_file? path_to_file
76
+
77
+ # extract
78
+ extracted_dir = Siba::TestFiles.mkdir_in_tmp_dir "tar-archive-extracted"
79
+ extract path_to_file, extracted_dir
80
+
81
+ # compare
82
+ Siba::FileHelper.dirs_same? src_dir, extracted_dir
83
+ end
84
+
85
+ def self.check_compression_type(compression)
86
+ raise Siba::CheckError, "'Compression' should be one of the following: #{CompressionTypes.join(', ')}" unless CompressionTypes.include?(compression)
87
+ end
88
+
89
+ protected
90
+ def self.get_tar_extension(compression)
91
+ case compression
92
+ when "none"
93
+ ""
94
+ when "gzip"
95
+ ".gz"
96
+ when "bzip2"
97
+ ".bz2"
98
+ else
99
+ raise
100
+ end
101
+ end
102
+
103
+ def get_tar_option
104
+ case compression
105
+ when "none"
106
+ ""
107
+ when "gzip"
108
+ "z"
109
+ when "bzip2"
110
+ "j"
111
+ else
112
+ raise
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'siba/plugins/archive/tar/archive'
4
+
5
+ module Siba::Archive
6
+ module Tar
7
+ DefaultCompression = "gzip"
8
+ CompressionTypes = ["gzip", "bzip2", "none"]
9
+
10
+ class Init
11
+ include Siba::LoggerPlug
12
+
13
+ attr_accessor :archive
14
+
15
+ def initialize(options)
16
+ options = options
17
+ compression = Siba::SibaCheck.options_string options, "compression", true, DefaultCompression
18
+ Archive.check_compression_type compression
19
+ @archive = Archive.new compression
20
+ end
21
+
22
+ # Archive the contents of sources_dir and put it to dest_dir.
23
+ # Return the archive file name. It must start with dest_file_name
24
+ # and its ending must not vary with time.
25
+ def backup(sources_dir, dest_dir, dest_file_name)
26
+ logger.info "Archiving with 'tar', compression: '#{archive.compression}'"
27
+ @archive.archive sources_dir, dest_dir, dest_file_name
28
+ end
29
+
30
+ # Extract archive file (path_to_archive) to_dir
31
+ # No return value is expected.
32
+ def restore(path_to_archive, to_dir)
33
+ logger.info "Extracting 'tar' archive, compression: '#{archive.compression}'"
34
+ @archive.extract path_to_archive, to_dir
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ compression: gzip # bgip2 or none