Class: Backupsss::Tar
- Inherits:
-
Object
- Object
- Backupsss::Tar
- Defined in:
- lib/backupsss/tar.rb
Overview
The Tar class is used for creating a tar archive.
Instance Attribute Summary collapse
-
#compress_archive ⇒ Object
readonly
Returns the value of attribute compress_archive.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(src, dest, compress_archive = true) ⇒ Tar
constructor
A new instance of Tar.
- #make ⇒ Object
- #messages ⇒ Object
- #tar_command ⇒ Object
- #valid_dest? ⇒ Boolean
- #valid_exit?(status, err) ⇒ Boolean
- #valid_file? ⇒ Boolean
- #valid_src? ⇒ Boolean
Constructor Details
#initialize(src, dest, compress_archive = true) ⇒ Tar
Returns a new instance of Tar.
8 9 10 11 12 |
# File 'lib/backupsss/tar.rb', line 8 def initialize(src, dest, compress_archive = true) @src = src @dest = dest @compress_archive = compress_archive end |
Instance Attribute Details
#compress_archive ⇒ Object (readonly)
Returns the value of attribute compress_archive.
6 7 8 |
# File 'lib/backupsss/tar.rb', line 6 def compress_archive @compress_archive end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
6 7 8 |
# File 'lib/backupsss/tar.rb', line 6 def dest @dest end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
6 7 8 |
# File 'lib/backupsss/tar.rb', line 6 def src @src end |
Instance Method Details
#filename ⇒ Object
53 54 55 |
# File 'lib/backupsss/tar.rb', line 53 def filename dest.split('/').last end |
#make ⇒ Object
14 15 16 17 18 |
# File 'lib/backupsss/tar.rb', line 14 def make return unless valid_dest? && valid_src? _, err, status = Open3.capture3("#{tar_command} #{dest} #{src}") File.open(dest) if valid_exit?(status, err) && valid_file? end |
#messages ⇒ Object
38 39 40 41 42 43 |
# File 'lib/backupsss/tar.rb', line 38 def { no_file: 'ERROR: Tar destination file does not exist.', zero_byte: 'ERROR: Tar destination file is 0 bytes.' } end |
#tar_command ⇒ Object
57 58 59 |
# File 'lib/backupsss/tar.rb', line 57 def tar_command compress_archive ? 'tar -zcvf' : 'tar -cvf' end |
#valid_dest? ⇒ Boolean
45 46 47 |
# File 'lib/backupsss/tar.rb', line 45 def valid_dest? dir_exists?(dest_dir) && dest_writable? end |
#valid_exit?(status, err) ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/backupsss/tar.rb', line 20 def valid_exit?(status, err) output = [] output << "command.......#{tar_command}" output << "stderr........#{err}" unless err.empty? output << "status........#{status}" output << "exit code.....#{status.to_i}" $stdout.puts output.join("\n") return true if success_cases(status.to_i, err) raise "ERROR: #{tar_command} exited #{status.to_i}" end |
#valid_file? ⇒ Boolean
32 33 34 35 36 |
# File 'lib/backupsss/tar.rb', line 32 def valid_file? raise [:no_file] unless File.exist?(dest) raise [:zero_byte] if File.size(dest).zero? true end |
#valid_src? ⇒ Boolean
49 50 51 |
# File 'lib/backupsss/tar.rb', line 49 def valid_src? dir_exists?(src) && src_readable? end |