module Puppet::Util::Backups
Public Instance Methods
perform_backup(file = nil)
click to toggle source
Deal with backups.
# File lib/puppet/util/backups.rb 7 def perform_backup(file = nil) 8 # if they specifically don't want a backup, then just say 9 # we're good 10 return true unless self[:backup] 11 12 # let the path be specified 13 file ||= self[:path] 14 return true unless Puppet::FileSystem.exist?(file) 15 16 return(self.bucket ? perform_backup_with_bucket(file) : perform_backup_with_backuplocal(file, self[:backup])) 17 end
Private Instance Methods
backup_file_with_filebucket(f)
click to toggle source
# File lib/puppet/util/backups.rb 82 def backup_file_with_filebucket(f) 83 sum = self.bucket.backup(f) 84 self.info _("Filebucketed %{f} to %{filebucket} with sum %{sum}") % { f: f, filebucket: self.bucket.name, sum: sum } 85 return sum 86 end
perform_backup_with_backuplocal(fileobj, backup)
click to toggle source
# File lib/puppet/util/backups.rb 35 def perform_backup_with_backuplocal(fileobj, backup) 36 file = (fileobj.class == String) ? fileobj : fileobj.name 37 newfile = file + backup 38 39 remove_backup(newfile) 40 41 begin 42 bfile = file + backup 43 44 # N.B. cp_r works on both files and directories 45 FileUtils.cp_r(file, bfile, :preserve => true) 46 return true 47 rescue => detail 48 # since they said they want a backup, let's error out 49 # if we couldn't make one 50 self.fail Puppet::Error, _("Could not back %{file} up: %{message}") % { file: file, message: detail.message }, detail 51 end 52 end
perform_backup_with_bucket(fileobj)
click to toggle source
# File lib/puppet/util/backups.rb 21 def perform_backup_with_bucket(fileobj) 22 file = (fileobj.class == String) ? fileobj : fileobj.name 23 case Puppet::FileSystem.lstat(file).ftype 24 when "directory" 25 # we don't need to backup directories when recurse is on 26 return true if self[:recurse] 27 info _("Recursively backing up to filebucket") 28 Find.find(self[:path]) { |f| backup_file_with_filebucket(f) if File.file?(f) } 29 when "file"; backup_file_with_filebucket(file) 30 when "link"; 31 end 32 true 33 end
remove_backup(newfile)
click to toggle source
# File lib/puppet/util/backups.rb 54 def remove_backup(newfile) 55 if self.class.name == :file and self[:links] != :follow 56 method = :lstat 57 else 58 method = :stat 59 end 60 61 begin 62 stat = Puppet::FileSystem.send(method, newfile) 63 rescue Errno::ENOENT 64 return 65 end 66 67 if stat.ftype == "directory" 68 raise Puppet::Error, _("Will not remove directory backup %{newfile}; use a filebucket") % { newfile: newfile } 69 end 70 71 info _("Removing old backup of type %{file_type}") % { file_type: stat.ftype } 72 73 begin 74 Puppet::FileSystem.unlink(newfile) 75 rescue => detail 76 message = _("Could not remove old backup: %{detail}") % { detail: detail } 77 self.log_exception(detail, message) 78 self.fail Puppet::Error, message, detail 79 end 80 end