Class: Outback::DirectoryTarget
- Defined in:
- lib/outback/directory_target.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Target
Instance Method Summary collapse
-
#initialize(backup_name, path) ⇒ DirectoryTarget
constructor
A new instance of DirectoryTarget.
- #put(archives) ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from Target
Methods included from Logging
Methods included from Configurable
Constructor Details
#initialize(backup_name, path) ⇒ DirectoryTarget
6 7 8 9 |
# File 'lib/outback/directory_target.rb', line 6 def initialize(backup_name, path) super(backup_name) @path = Pathname.new(path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/outback/directory_target.rb', line 3 def path @path end |
Instance Method Details
#put(archives) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/outback/directory_target.rb', line 19 def put(archives) FileUtils.mkdir_p(path) unless path.directory? FileUtils.chmod || 0700, path size = 0 archives.each do |archive| basename = Pathname.new(archive.filename).basename if move logger.debug "moving #{archive.filename} to #{path}" FileUtils.mv archive.filename, path else logger.debug "copying #{archive.filename} to #{path}" FileUtils.cp_r archive.filename, path end archived_file = path.join(basename) logger.debug "setting permissions for #{archived_file}" FileUtils.chmod || 0600, archived_file if user && group logger.debug "setting owner #{user}, group #{group} for #{archived_file}" FileUtils.chown user, group, archived_file end size += archived_file.size end logger.info "#{move ? 'Moved' : 'Copied'} #{archives.size} archives (#{size} bytes) to #{self}" archives.size end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/outback/directory_target.rb', line 15 def to_s "directory:#{path}" end |
#valid? ⇒ Boolean
11 12 13 |
# File 'lib/outback/directory_target.rb', line 11 def valid? (user and group) or (not user and not group) end |