Module: Backup::Cleaner

Defined in:
lib/backup/cleaner.rb

Defined Under Namespace

Classes: Error

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.



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
49
50
# File 'lib/backup/cleaner.rb', line 13

def prepare(model)
  messages = []

  packaging_folder = File.join(Config.tmp_path, model.trigger)
  if File.exist?(packaging_folder)
    messages << "      The temporary packaging folder still exists!\n      '\#{ packaging_folder }'\n      It will now be removed.\n    EOS\n    FileUtils.rm_rf(packaging_folder)\n  end\n\n  package_files = package_files_for(model.trigger)\n  unless package_files.empty?\n    # the chances of the packaging folder AND\n    # the package files existing are practically nil\n    messages << ('-' * 74) unless messages.empty?\n\n    messages << <<-EOS\n      The temporary backup folder '\#{ Config.tmp_path }'\n      appears to contain the package files from the previous backup!\n      \#{ package_files.join(\"\\n\") }\n      These files will now be removed.\n    EOS\n    package_files.each {|file| FileUtils.rm_f(file) }\n  end\n\n  unless messages.empty?\n    Logger.warn Error.new(<<-EOS)\n      Cleanup Warning\n      \#{ messages.join(\"\\n\") }\n      Please check the log for messages and/or your notifications\n      concerning this backup: '\#{ model.label } (\#{ model.trigger })'\n      The temporary files which had to be removed should not have existed.\n    EOS\n  end\nend\n"

.remove_package(package) ⇒ Object

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



62
63
64
65
66
67
# File 'lib/backup/cleaner.rb', line 62

def remove_package(package)
  Logger.info "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



54
55
56
57
# File 'lib/backup/cleaner.rb', line 54

def remove_packaging(model)
  Logger.info "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



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
105
106
# File 'lib/backup/cleaner.rb', line 72

def warnings(model)
  messages = []

  packaging_folder = File.join(Config.tmp_path, model.trigger)
  if File.exist?(packaging_folder)
    messages << "      The temporary packaging folder still exists!\n      '\#{ packaging_folder }'\n      This folder may contain completed Archives and/or Database backups.\n    EOS\n  end\n\n  package_files = package_files_for(model.trigger)\n  unless package_files.empty?\n    # the chances of the packaging folder AND\n    # the package files existing are practically nil\n    messages << ('-' * 74) unless messages.empty?\n\n    messages << <<-EOS\n      The temporary backup folder '\#{ Config.tmp_path }'\n      appears to contain the backup files which were to be stored:\n      \#{ package_files.join(\"\\n\") }\n    EOS\n  end\n\n  unless messages.empty?\n    Logger.warn Error.new(<<-EOS)\n      Cleanup Warning\n      \#{ messages.join(\"\\n\") }\n      Make sure you check these files before the next scheduled backup for\n      '\#{ model.label } (\#{ model.trigger })'\n      These files will be removed at that time!\n    EOS\n  end\nend\n"