Module: Backup::Cleaner

Defined in:
lib/backup/cleaner.rb

Class Method Summary collapse

Class Method Details

.prepare(model) ⇒ Object

Logs warnings if any temporary files still exist from the last time this model/trigger was run, then removes the files.



11
12
13
14
15
16
17
18
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
44
45
46
47
48
# File 'lib/backup/cleaner.rb', line 11

def prepare(model)
  @model = model

  messages = []
  if packaging_folder_dirty?
    messages << <<-EOS
      The temporary backup folder still contains files!
      '#{ File.join(Config.tmp_path, @model.trigger) }'
      These files will now be removed.
    EOS
    FileUtils.rm_rf(File.join(Config.tmp_path, @model.trigger))
  end

  package_files = tmp_path_package_files
  unless package_files.empty?
    # the chances that tmp_path would be dirty
    # AND package files exist are practically nil
    messages << ('-' * 74) unless messages.empty?

    messages << <<-EOS
      The temporary backup folder '#{ Config.tmp_path }'
      appears to contain the package files from the previous backup!
      #{ package_files.join("\n") }
      These files will now be removed.
    EOS
    package_files.each {|file| FileUtils.rm_f(file) }
  end

  unless messages.empty?
    Logger.warn Errors::CleanerError.new(<<-EOS)
      Cleanup Warning
      #{ messages.join("\n") }
      Please check the log for messages and/or your notifications
      concerning this backup: '#{ @model.label } (#{ @model.trigger })'
      The temporary files which had to be removed should not have existed.
    EOS
  end
end

.remove_package(package) ⇒ Object

Remove the final package files from tmp_path Note: ‘force’ is used, since a Local Storage may move these files.



60
61
62
63
64
65
# File 'lib/backup/cleaner.rb', line 60

def remove_package(package)
  Logger.message "Cleaning up the package files..."
  package.filenames.each do |file|
    FileUtils.rm_f(File.join(Config.tmp_path, file))
  end
end

.remove_packaging(model) ⇒ Object

Remove the temporary folder used during packaging



52
53
54
55
# File 'lib/backup/cleaner.rb', line 52

def remove_packaging(model)
  Logger.message "Cleaning up the temporary files..."
  FileUtils.rm_rf(File.join(Config.tmp_path, model.trigger))
end

.warnings(model) ⇒ Object

Logs warnings if any temporary files still exist when errors occur during the backup



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/backup/cleaner.rb', line 70

def warnings(model)
  @model = model

  messages = []
  if packaging_folder_dirty?
    messages << <<-EOS
      The temporary backup folder still contains files!
      '#{ File.join(Config.tmp_path, @model.trigger) }'
      This folder may contain completed Archives and/or Database backups.
    EOS
  end

  package_files = tmp_path_package_files
  unless package_files.empty?
    # the chances that tmp_path would be dirty
    # AND package files exist are practically nil
    messages << ('-' * 74) unless messages.empty?

    messages << <<-EOS
      The temporary backup folder '#{ Config.tmp_path }'
      appears to contain the backup files which were to be stored:
      #{ package_files.join("\n") }
    EOS
  end

  unless messages.empty?
    Logger.warn Errors::CleanerError.new(<<-EOS)
      Cleanup Warning
      #{ messages.join("\n") }
      Make sure you check these files before the next scheduled backup for
      '#{ @model.label } (#{ @model.trigger })'
      These files will be removed at that time!
    EOS
  end
end