nfm-backup 4.0.1a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +24 -0
  3. data/README.md +20 -0
  4. data/bin/backup +5 -0
  5. data/lib/backup.rb +133 -0
  6. data/lib/backup/archive.rb +170 -0
  7. data/lib/backup/binder.rb +22 -0
  8. data/lib/backup/cleaner.rb +116 -0
  9. data/lib/backup/cli.rb +364 -0
  10. data/lib/backup/cloud_io/base.rb +41 -0
  11. data/lib/backup/cloud_io/cloud_files.rb +298 -0
  12. data/lib/backup/cloud_io/s3.rb +260 -0
  13. data/lib/backup/compressor/base.rb +35 -0
  14. data/lib/backup/compressor/bzip2.rb +39 -0
  15. data/lib/backup/compressor/custom.rb +53 -0
  16. data/lib/backup/compressor/gzip.rb +74 -0
  17. data/lib/backup/config.rb +119 -0
  18. data/lib/backup/config/dsl.rb +102 -0
  19. data/lib/backup/config/helpers.rb +143 -0
  20. data/lib/backup/database/base.rb +85 -0
  21. data/lib/backup/database/mongodb.rb +186 -0
  22. data/lib/backup/database/mysql.rb +123 -0
  23. data/lib/backup/database/postgresql.rb +133 -0
  24. data/lib/backup/database/redis.rb +179 -0
  25. data/lib/backup/database/riak.rb +82 -0
  26. data/lib/backup/encryptor/base.rb +29 -0
  27. data/lib/backup/encryptor/gpg.rb +747 -0
  28. data/lib/backup/encryptor/open_ssl.rb +72 -0
  29. data/lib/backup/errors.rb +58 -0
  30. data/lib/backup/logger.rb +199 -0
  31. data/lib/backup/logger/console.rb +51 -0
  32. data/lib/backup/logger/fog_adapter.rb +29 -0
  33. data/lib/backup/logger/logfile.rb +119 -0
  34. data/lib/backup/logger/syslog.rb +116 -0
  35. data/lib/backup/model.rb +454 -0
  36. data/lib/backup/notifier/base.rb +98 -0
  37. data/lib/backup/notifier/campfire.rb +69 -0
  38. data/lib/backup/notifier/hipchat.rb +93 -0
  39. data/lib/backup/notifier/http_post.rb +122 -0
  40. data/lib/backup/notifier/mail.rb +238 -0
  41. data/lib/backup/notifier/nagios.rb +69 -0
  42. data/lib/backup/notifier/prowl.rb +69 -0
  43. data/lib/backup/notifier/pushover.rb +80 -0
  44. data/lib/backup/notifier/slack.rb +149 -0
  45. data/lib/backup/notifier/twitter.rb +65 -0
  46. data/lib/backup/package.rb +51 -0
  47. data/lib/backup/packager.rb +101 -0
  48. data/lib/backup/pipeline.rb +124 -0
  49. data/lib/backup/splitter.rb +76 -0
  50. data/lib/backup/storage/base.rb +57 -0
  51. data/lib/backup/storage/cloud_files.rb +158 -0
  52. data/lib/backup/storage/cycler.rb +65 -0
  53. data/lib/backup/storage/dropbox.rb +236 -0
  54. data/lib/backup/storage/ftp.rb +98 -0
  55. data/lib/backup/storage/local.rb +64 -0
  56. data/lib/backup/storage/ninefold.rb +74 -0
  57. data/lib/backup/storage/rsync.rb +248 -0
  58. data/lib/backup/storage/s3.rb +154 -0
  59. data/lib/backup/storage/scp.rb +67 -0
  60. data/lib/backup/storage/sftp.rb +82 -0
  61. data/lib/backup/syncer/base.rb +70 -0
  62. data/lib/backup/syncer/cloud/base.rb +179 -0
  63. data/lib/backup/syncer/cloud/cloud_files.rb +83 -0
  64. data/lib/backup/syncer/cloud/local_file.rb +100 -0
  65. data/lib/backup/syncer/cloud/s3.rb +110 -0
  66. data/lib/backup/syncer/rsync/base.rb +48 -0
  67. data/lib/backup/syncer/rsync/local.rb +31 -0
  68. data/lib/backup/syncer/rsync/pull.rb +51 -0
  69. data/lib/backup/syncer/rsync/push.rb +205 -0
  70. data/lib/backup/template.rb +46 -0
  71. data/lib/backup/utilities.rb +221 -0
  72. data/lib/backup/version.rb +5 -0
  73. data/templates/cli/archive +28 -0
  74. data/templates/cli/compressor/bzip2 +4 -0
  75. data/templates/cli/compressor/custom +7 -0
  76. data/templates/cli/compressor/gzip +4 -0
  77. data/templates/cli/config +123 -0
  78. data/templates/cli/databases/mongodb +15 -0
  79. data/templates/cli/databases/mysql +18 -0
  80. data/templates/cli/databases/postgresql +16 -0
  81. data/templates/cli/databases/redis +16 -0
  82. data/templates/cli/databases/riak +17 -0
  83. data/templates/cli/encryptor/gpg +27 -0
  84. data/templates/cli/encryptor/openssl +9 -0
  85. data/templates/cli/model +26 -0
  86. data/templates/cli/notifiers/campfire +12 -0
  87. data/templates/cli/notifiers/hipchat +15 -0
  88. data/templates/cli/notifiers/http_post +32 -0
  89. data/templates/cli/notifiers/mail +21 -0
  90. data/templates/cli/notifiers/nagios +13 -0
  91. data/templates/cli/notifiers/prowl +11 -0
  92. data/templates/cli/notifiers/pushover +11 -0
  93. data/templates/cli/notifiers/twitter +13 -0
  94. data/templates/cli/splitter +7 -0
  95. data/templates/cli/storages/cloud_files +11 -0
  96. data/templates/cli/storages/dropbox +19 -0
  97. data/templates/cli/storages/ftp +12 -0
  98. data/templates/cli/storages/local +7 -0
  99. data/templates/cli/storages/ninefold +9 -0
  100. data/templates/cli/storages/rsync +17 -0
  101. data/templates/cli/storages/s3 +14 -0
  102. data/templates/cli/storages/scp +14 -0
  103. data/templates/cli/storages/sftp +14 -0
  104. data/templates/cli/syncers/cloud_files +22 -0
  105. data/templates/cli/syncers/rsync_local +20 -0
  106. data/templates/cli/syncers/rsync_pull +28 -0
  107. data/templates/cli/syncers/rsync_push +28 -0
  108. data/templates/cli/syncers/s3 +27 -0
  109. data/templates/general/links +3 -0
  110. data/templates/general/version.erb +2 -0
  111. data/templates/notifier/mail/failure.erb +16 -0
  112. data/templates/notifier/mail/success.erb +16 -0
  113. data/templates/notifier/mail/warning.erb +16 -0
  114. data/templates/storage/dropbox/authorization_url.erb +6 -0
  115. data/templates/storage/dropbox/authorized.erb +4 -0
  116. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  117. metadata +688 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be055bf625d8f4ee4bf1255bc6a45d8b82c5193b
4
+ data.tar.gz: cd0112efba753c2211d4f221ffe7adf7d6a257cb
5
+ SHA512:
6
+ metadata.gz: bc2a9ca5bb09cd0f72c2edf6e9a7f6ba95544345163fff91d4a007a10a45f50df735b2e66217b6f0253ee0b7c9dde9ad297e6b0ac5afe81f8000d786cf0a3b4c
7
+ data.tar.gz: bd6321216f79c5b3574821ebbbcb12ef8e226989cf07cd145024adbb3df8e6da264d7293c7a153fdb04f6521f2f3f309125b8dc15c0c256dca0de1dd11382c78
data/LICENSE.md ADDED
@@ -0,0 +1,24 @@
1
+
2
+ Copyright (c) 2009-2013 Michael van Rooijen ( [@meskyanichi](http://twitter.com/#!/meskyanichi) )
3
+ =================================================================================================
4
+
5
+ The "Backup" RubyGem is released under the **MIT LICENSE**
6
+ ----------------------------------------------------------
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Backup v4.x
2
+ ===========
3
+
4
+ This repo is a fork of Michael van Rooijen's backup gem (https://github.com/meskyanichi/backup). You probably don't want this version.
5
+
6
+ Changes from original version:
7
+
8
+ * Add paracycle's Slack notifier (pull #527)
9
+
10
+ [Installation][] · [Release Notes][] · [Documentation][]
11
+
12
+
13
+ **Copyright (c) 2009-2014 [Michael van Rooijen][] ( [@meskyanichi][] )**
14
+ Released under the **MIT** [License](LICENSE.md).
15
+
16
+ [Installation]: http://meskyanichi.github.io/backup/v4/installation
17
+ [Release Notes]: http://meskyanichi.github.io/backup/v4/release-notes
18
+ [Documentation]: http://meskyanichi.github.io/backup/v4
19
+ [Michael van Rooijen]: http://michaelvanrooijen.com
20
+ [@meskyanichi]: http://twitter.com/#!/meskyanichi
data/bin/backup ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require File.expand_path("../../lib/backup", __FILE__)
5
+ Backup::CLI.start
data/lib/backup.rb ADDED
@@ -0,0 +1,133 @@
1
+ # encoding: utf-8
2
+
3
+ # Load Ruby Core Libraries
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+ require 'syslog'
7
+ require 'yaml'
8
+ require 'etc'
9
+ require 'forwardable'
10
+ require 'thread'
11
+
12
+ require 'open4'
13
+ require 'thor'
14
+
15
+ require 'excon'
16
+ # Include response.inspect in error messages.
17
+ Excon.defaults[:debug_response] = true
18
+ # Excon should not retry failed requests. We handle that.
19
+ Excon.defaults[:middlewares].delete(Excon::Middleware::Idempotent)
20
+
21
+ ##
22
+ # The Backup Ruby Gem
23
+ module Backup
24
+
25
+ ##
26
+ # Backup's internal paths
27
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
28
+ STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
29
+ SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
30
+ DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
31
+ COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
32
+ ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
33
+ NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
34
+ TEMPLATE_PATH = File.expand_path('../../templates', __FILE__)
35
+
36
+ ##
37
+ # Autoload Backup storage files
38
+ module Storage
39
+ autoload :Base, File.join(STORAGE_PATH, 'base')
40
+ autoload :Cycler, File.join(STORAGE_PATH, 'cycler')
41
+ autoload :S3, File.join(STORAGE_PATH, 's3')
42
+ autoload :CloudFiles, File.join(STORAGE_PATH, 'cloud_files')
43
+ autoload :Ninefold, File.join(STORAGE_PATH, 'ninefold')
44
+ autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
45
+ autoload :FTP, File.join(STORAGE_PATH, 'ftp')
46
+ autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
47
+ autoload :SCP, File.join(STORAGE_PATH, 'scp')
48
+ autoload :RSync, File.join(STORAGE_PATH, 'rsync')
49
+ autoload :Local, File.join(STORAGE_PATH, 'local')
50
+ end
51
+
52
+ ##
53
+ # Autoload Backup syncer files
54
+ module Syncer
55
+ autoload :Base, File.join(SYNCER_PATH, 'base')
56
+ module Cloud
57
+ autoload :Base, File.join(SYNCER_PATH, 'cloud', 'base')
58
+ autoload :LocalFile, File.join(SYNCER_PATH, 'cloud', 'local_file')
59
+ autoload :CloudFiles, File.join(SYNCER_PATH, 'cloud', 'cloud_files')
60
+ autoload :S3, File.join(SYNCER_PATH, 'cloud', 's3')
61
+ end
62
+ module RSync
63
+ autoload :Base, File.join(SYNCER_PATH, 'rsync', 'base')
64
+ autoload :Local, File.join(SYNCER_PATH, 'rsync', 'local')
65
+ autoload :Push, File.join(SYNCER_PATH, 'rsync', 'push')
66
+ autoload :Pull, File.join(SYNCER_PATH, 'rsync', 'pull')
67
+ end
68
+ end
69
+
70
+ ##
71
+ # Autoload Backup database files
72
+ module Database
73
+ autoload :Base, File.join(DATABASE_PATH, 'base')
74
+ autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
75
+ autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
76
+ autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
77
+ autoload :Redis, File.join(DATABASE_PATH, 'redis')
78
+ autoload :Riak, File.join(DATABASE_PATH, 'riak')
79
+ end
80
+
81
+ ##
82
+ # Autoload compressor files
83
+ module Compressor
84
+ autoload :Base, File.join(COMPRESSOR_PATH, 'base')
85
+ autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
86
+ autoload :Bzip2, File.join(COMPRESSOR_PATH, 'bzip2')
87
+ autoload :Custom, File.join(COMPRESSOR_PATH, 'custom')
88
+ end
89
+
90
+ ##
91
+ # Autoload encryptor files
92
+ module Encryptor
93
+ autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
94
+ autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
95
+ autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
96
+ end
97
+
98
+ ##
99
+ # Autoload notification files
100
+ module Notifier
101
+ autoload :Base, File.join(NOTIFIER_PATH, 'base')
102
+ autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
103
+ autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter')
104
+ autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
105
+ autoload :Prowl, File.join(NOTIFIER_PATH, 'prowl')
106
+ autoload :Hipchat, File.join(NOTIFIER_PATH, 'hipchat')
107
+ autoload :Pushover, File.join(NOTIFIER_PATH, 'pushover')
108
+ autoload :Slack, File.join(NOTIFIER_PATH, 'slack')
109
+ autoload :HttpPost, File.join(NOTIFIER_PATH, 'http_post')
110
+ autoload :Nagios, File.join(NOTIFIER_PATH, 'nagios')
111
+ end
112
+
113
+ ##
114
+ # Require Backup base files
115
+ %w{
116
+ errors
117
+ logger
118
+ utilities
119
+ archive
120
+ binder
121
+ cleaner
122
+ model
123
+ config
124
+ cli
125
+ package
126
+ packager
127
+ pipeline
128
+ splitter
129
+ template
130
+ version
131
+ }.each {|lib| require File.join(LIBRARY_PATH, lib) }
132
+
133
+ end
@@ -0,0 +1,170 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ class Archive
5
+ class Error < Backup::Error; end
6
+
7
+ include Utilities::Helpers
8
+ attr_reader :name, :options
9
+
10
+ ##
11
+ # Adds a new Archive to a Backup Model.
12
+ #
13
+ # Backup::Model.new(:my_backup, 'My Backup') do
14
+ # archive :my_archive do |archive|
15
+ # archive.add 'path/to/archive'
16
+ # archive.add '/another/path/to/archive'
17
+ # archive.exclude 'path/to/exclude'
18
+ # archive.exclude '/another/path/to/exclude'
19
+ # end
20
+ # end
21
+ #
22
+ # All paths added using `add` or `exclude` will be expanded to their
23
+ # full paths from the root of the filesystem. Files will be added to
24
+ # the tar archive using these full paths, and their leading `/` will
25
+ # be preserved (using tar's `-P` option).
26
+ #
27
+ # /path/to/pwd/path/to/archive/...
28
+ # /another/path/to/archive/...
29
+ #
30
+ # When a `root` path is given, paths to add/exclude are taken as
31
+ # relative to the `root` path, unless given as absolute paths.
32
+ #
33
+ # Backup::Model.new(:my_backup, 'My Backup') do
34
+ # archive :my_archive do |archive|
35
+ # archive.root '~/my_data'
36
+ # archive.add 'path/to/archive'
37
+ # archive.add '/another/path/to/archive'
38
+ # archive.exclude 'path/to/exclude'
39
+ # archive.exclude '/another/path/to/exclude'
40
+ # end
41
+ # end
42
+ #
43
+ # This directs `tar` to change directories to the `root` path to create
44
+ # the archive. Unless paths were given as absolute, the paths within the
45
+ # archive will be relative to the `root` path.
46
+ #
47
+ # path/to/archive/...
48
+ # /another/path/to/archive/...
49
+ #
50
+ # For absolute paths added to this archive, the leading `/` will be
51
+ # preserved. Take note that when archives are extracted, leading `/` are
52
+ # stripped by default, so care must be taken when extracting archives with
53
+ # mixed relative/absolute paths.
54
+ def initialize(model, name, &block)
55
+ @model = model
56
+ @name = name.to_s
57
+ @options = {
58
+ :sudo => false,
59
+ :root => false,
60
+ :paths => [],
61
+ :excludes => [],
62
+ :tar_options => ''
63
+ }
64
+ DSL.new(@options).instance_eval(&block)
65
+ end
66
+
67
+ def perform!
68
+ Logger.info "Creating Archive '#{ name }'..."
69
+
70
+ path = File.join(Config.tmp_path, @model.trigger, 'archives')
71
+ FileUtils.mkdir_p(path)
72
+
73
+ pipeline = Pipeline.new
74
+ with_files_from(paths_to_package) do |files_from|
75
+ pipeline.add(
76
+ "#{ tar_command } #{ tar_options } -cPf -#{ tar_root } " +
77
+ "#{ paths_to_exclude } #{ files_from }",
78
+ tar_success_codes
79
+ )
80
+
81
+ extension = 'tar'
82
+ @model.compressor.compress_with do |command, ext|
83
+ pipeline << command
84
+ extension << ext
85
+ end if @model.compressor
86
+
87
+ pipeline << "#{ utility(:cat) } > " +
88
+ "'#{ File.join(path, "#{ name }.#{ extension }") }'"
89
+ pipeline.run
90
+ end
91
+
92
+ if pipeline.success?
93
+ Logger.info "Archive '#{ name }' Complete!"
94
+ else
95
+ raise Error, "Failed to Create Archive '#{ name }'\n" +
96
+ pipeline.error_messages
97
+ end
98
+ end
99
+
100
+ private
101
+
102
+ def tar_command
103
+ tar = utility(:tar)
104
+ options[:sudo] ? "#{ utility(:sudo) } -n #{ tar }" : tar
105
+ end
106
+
107
+ def tar_root
108
+ options[:root] ? " -C '#{ File.expand_path(options[:root]) }'" : ''
109
+ end
110
+
111
+ def paths_to_package
112
+ options[:paths].map {|path| prepare_path(path) }
113
+ end
114
+
115
+ def with_files_from(paths)
116
+ tmpfile = Tempfile.new('backup-archive-paths')
117
+ paths.each {|path| tmpfile.puts path }
118
+ tmpfile.close
119
+ yield "-T '#{ tmpfile.path }'"
120
+ ensure
121
+ tmpfile.delete
122
+ end
123
+
124
+ def paths_to_exclude
125
+ options[:excludes].map {|path|
126
+ "--exclude='#{ prepare_path(path) }'"
127
+ }.join(' ')
128
+ end
129
+
130
+ def prepare_path(path)
131
+ options[:root] ? path : File.expand_path(path)
132
+ end
133
+
134
+ def tar_options
135
+ args = options[:tar_options]
136
+ gnu_tar? ? "--ignore-failed-read #{ args }".strip : args
137
+ end
138
+
139
+ def tar_success_codes
140
+ gnu_tar? ? [0, 1] : [0]
141
+ end
142
+
143
+ class DSL
144
+ def initialize(options)
145
+ @options = options
146
+ end
147
+
148
+ def use_sudo(val = true)
149
+ @options[:sudo] = val
150
+ end
151
+
152
+ def root(path)
153
+ @options[:root] = path
154
+ end
155
+
156
+ def add(path)
157
+ @options[:paths] << path
158
+ end
159
+
160
+ def exclude(path)
161
+ @options[:excludes] << path
162
+ end
163
+
164
+ def tar_options(opts)
165
+ @options[:tar_options] = opts
166
+ end
167
+ end
168
+
169
+ end
170
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ class Binder
5
+
6
+ ##
7
+ # Creates a new Backup::Notifier::Binder instance. Loops through the provided
8
+ # Hash to set instance variables
9
+ def initialize(key_and_values)
10
+ key_and_values.each do |key, value|
11
+ instance_variable_set("@#{ key }", value)
12
+ end
13
+ end
14
+
15
+ ##
16
+ # Returns the binding (needs a wrapper method because #binding is a private method)
17
+ def get_binding
18
+ binding
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+
3
+ module Backup
4
+ module Cleaner
5
+ class Error < Backup::Error; end
6
+
7
+ class << self
8
+
9
+ ##
10
+ # Logs warnings if any temporary files still exist
11
+ # from the last time this model/trigger was run,
12
+ # then removes the files.
13
+ def prepare(model)
14
+ messages = []
15
+
16
+ packaging_folder = File.join(Config.tmp_path, model.trigger)
17
+ if File.exist?(packaging_folder)
18
+ messages << <<-EOS
19
+ The temporary packaging folder still exists!
20
+ '#{ packaging_folder }'
21
+ It will now be removed.
22
+ EOS
23
+ FileUtils.rm_rf(packaging_folder)
24
+ end
25
+
26
+ package_files = package_files_for(model.trigger)
27
+ unless package_files.empty?
28
+ # the chances of the packaging folder AND
29
+ # the package files existing are practically nil
30
+ messages << ('-' * 74) unless messages.empty?
31
+
32
+ messages << <<-EOS
33
+ The temporary backup folder '#{ Config.tmp_path }'
34
+ appears to contain the package files from the previous backup!
35
+ #{ package_files.join("\n") }
36
+ These files will now be removed.
37
+ EOS
38
+ package_files.each {|file| FileUtils.rm_f(file) }
39
+ end
40
+
41
+ unless messages.empty?
42
+ Logger.warn Error.new(<<-EOS)
43
+ Cleanup Warning
44
+ #{ messages.join("\n") }
45
+ Please check the log for messages and/or your notifications
46
+ concerning this backup: '#{ model.label } (#{ model.trigger })'
47
+ The temporary files which had to be removed should not have existed.
48
+ EOS
49
+ end
50
+ end
51
+
52
+ ##
53
+ # Remove the temporary folder used during packaging
54
+ def remove_packaging(model)
55
+ Logger.info "Cleaning up the temporary files..."
56
+ FileUtils.rm_rf(File.join(Config.tmp_path, model.trigger))
57
+ end
58
+
59
+ ##
60
+ # Remove the final package files from tmp_path
61
+ # Note: 'force' is used, since a Local Storage may *move* these files.
62
+ def remove_package(package)
63
+ Logger.info "Cleaning up the package files..."
64
+ package.filenames.each do |file|
65
+ FileUtils.rm_f(File.join(Config.tmp_path, file))
66
+ end
67
+ end
68
+
69
+ ##
70
+ # Logs warnings if any temporary files still exist
71
+ # when errors occur during the backup
72
+ def warnings(model)
73
+ messages = []
74
+
75
+ packaging_folder = File.join(Config.tmp_path, model.trigger)
76
+ if File.exist?(packaging_folder)
77
+ messages << <<-EOS
78
+ The temporary packaging folder still exists!
79
+ '#{ packaging_folder }'
80
+ This folder may contain completed Archives and/or Database backups.
81
+ EOS
82
+ end
83
+
84
+ package_files = package_files_for(model.trigger)
85
+ unless package_files.empty?
86
+ # the chances of the packaging folder AND
87
+ # the package files existing are practically nil
88
+ messages << ('-' * 74) unless messages.empty?
89
+
90
+ messages << <<-EOS
91
+ The temporary backup folder '#{ Config.tmp_path }'
92
+ appears to contain the backup files which were to be stored:
93
+ #{ package_files.join("\n") }
94
+ EOS
95
+ end
96
+
97
+ unless messages.empty?
98
+ Logger.warn Error.new(<<-EOS)
99
+ Cleanup Warning
100
+ #{ messages.join("\n") }
101
+ Make sure you check these files before the next scheduled backup for
102
+ '#{ model.label } (#{ model.trigger })'
103
+ These files will be removed at that time!
104
+ EOS
105
+ end
106
+ end
107
+
108
+ private
109
+
110
+ def package_files_for(trigger)
111
+ Dir[File.join(Config.tmp_path,"#{ trigger }.tar{,[.-]*}")]
112
+ end
113
+
114
+ end
115
+ end
116
+ end