Class: Backup::Tasks::Directory
- Inherits:
-
Object
- Object
- Backup::Tasks::Directory
- Defined in:
- lib/backup-agent/tasks/directory.rb
Instance Method Summary collapse
- #add_extension(name) ⇒ Object
- #compression_environment ⇒ Object
-
#initialize(path, options = {}) ⇒ Directory
constructor
A new instance of Directory.
- #perform(storage) ⇒ Object
- #tar_flags ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Directory
Returns a new instance of Directory.
6 7 8 9 10 11 12 13 14 |
# File 'lib/backup-agent/tasks/directory.rb', line 6 def initialize(path, = {}) @path = path # @name = options.fetch(:name) @options = if [:compressor] @compressor = Symbol === [:compressor] ? { type: [:compressor] } : [:compressor] end end |
Instance Method Details
#add_extension(name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/backup-agent/tasks/directory.rb', line 53 def add_extension(name) case @compressor&.fetch(:type) when :xz then name + ".tar.xz" when :gzip then name + ".tar.gz" else name + ".tar" end end |
#compression_environment ⇒ Object
31 32 33 34 35 36 |
# File 'lib/backup-agent/tasks/directory.rb', line 31 def compression_environment case @compressor&.fetch(:type) when :xz then { XZ_OPT: "-#{@compressor.fetch(:level, 3)}" } when :gzip then { GZIP: "-#{@compressor.fetch(:level, 3)}" } end end |
#perform(storage) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/backup-agent/tasks/directory.rb', line 16 def perform(storage) return if !File.readable?(@path) || !File.directory?(@path) @options.fetch(:name, @path).tap do |x| @filename = add_extension(construct_filename(File.basename(x, ".*")) + File.extname(x)) end Tempfile.open do |tempfile| with compression_environment do command "tar", tar_flags, tempfile.path, "-C", @path, "." end storage.store(@filename, tempfile.path) end end |
#tar_flags ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/backup-agent/tasks/directory.rb', line 38 def tar_flags flags = ["c"] flags << "h" if @options.fetch(:symlinks, :follow) == :follow case @compressor&.fetch(:type) when :xz then flags << "J" when :gzip then flags << "z" end flags << "v" flags << "f" flags.join("") end |