Class: Chef::Util::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/util/backup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_resource, path = nil) ⇒ Backup

Returns a new instance of Backup.



27
28
29
30
# File 'lib/chef/util/backup.rb', line 27

def initialize(new_resource, path = nil)
  @new_resource = new_resource
  @path = path.nil? ? new_resource.path : path
end

Instance Attribute Details

#new_resourceObject (readonly)

Returns the value of attribute new_resource.



24
25
26
# File 'lib/chef/util/backup.rb', line 24

def new_resource
  @new_resource
end

#pathObject

Returns the value of attribute path.



25
26
27
# File 'lib/chef/util/backup.rb', line 25

def path
  @path
end

Instance Method Details

#backup!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef/util/backup.rb', line 32

def backup!
  if @new_resource.backup != false && @new_resource.backup > 0 && ::TargetIO::File.exist?(path)
    do_backup
    # Clean up after the number of backups
    slice_number = @new_resource.backup
    backup_files = sorted_backup_files
    if backup_files.length >= @new_resource.backup
      remainder = backup_files.slice(slice_number..)
      remainder.each do |backup_to_delete|
        delete_backup(backup_to_delete)
      end
    end
  end
end