Class: Outback::DirectorySource
- Defined in:
- lib/outback/directory_source.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Source
Instance Method Summary collapse
- #create_archives(timestamp, tmpdir) ⇒ Object
- #exclude(*paths) ⇒ Object
- #excludes ⇒ Object
-
#initialize(backup_name, path) ⇒ DirectorySource
constructor
A new instance of DirectorySource.
- #source_name ⇒ Object
Methods inherited from Source
Methods included from Logging
Methods included from Configurable
Constructor Details
#initialize(backup_name, path) ⇒ DirectorySource
Returns a new instance of DirectorySource.
5 6 7 8 |
# File 'lib/outback/directory_source.rb', line 5 def initialize(backup_name, path) super(backup_name) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/outback/directory_source.rb', line 3 def path @path end |
Instance Method Details
#create_archives(timestamp, tmpdir) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/outback/directory_source.rb', line 22 def create_archives(, tmpdir) source_dir = Pathname.new(path).realpath archive_name = Pathname.new(tmpdir).join("#{backup_name}_#{}_#{source_name}.tar.gz") exclude_list = Pathname.new(tmpdir).join('exclude_list.txt') File.open(exclude_list, 'w') { |f| f << excludes.map { |e| e.to_s.sub(/\A\//, '') }.join("\n") } verbose_switch = Outback.verbose? ? 'v' : '' commandline = "tar -cz#{verbose_switch}pf #{archive_name} --exclude-from=#{exclude_list} --directory=/ #{source_dir.to_s.sub(/\A\//, '')}" logger.debug "executing command: #{commandline}" result = `#{commandline}` logger.debug "result: #{result}" logger.info "Archived directory #{path}" [SourceArchive.new(archive_name)] end |
#exclude(*paths) ⇒ Object
18 19 20 |
# File 'lib/outback/directory_source.rb', line 18 def exclude(*paths) excludes.concat(paths.map(&:to_s)).uniq! end |
#excludes ⇒ Object
14 15 16 |
# File 'lib/outback/directory_source.rb', line 14 def excludes @excludes ||= [] end |
#source_name ⇒ Object
10 11 12 |
# File 'lib/outback/directory_source.rb', line 10 def source_name path.gsub(/[^A-Za-z0-9\-_.]/, '_').gsub(/(\A_|_\z)/, '') end |