backup-ssh 4.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +24 -0
  3. data/README.md +25 -0
  4. data/bin/backup +5 -0
  5. data/lib/backup.rb +141 -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 +374 -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 +103 -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 +200 -0
  23. data/lib/backup/database/openldap.rb +95 -0
  24. data/lib/backup/database/postgresql.rb +133 -0
  25. data/lib/backup/database/redis.rb +179 -0
  26. data/lib/backup/database/riak.rb +82 -0
  27. data/lib/backup/database/sqlite.rb +57 -0
  28. data/lib/backup/encryptor/base.rb +29 -0
  29. data/lib/backup/encryptor/gpg.rb +747 -0
  30. data/lib/backup/encryptor/open_ssl.rb +77 -0
  31. data/lib/backup/errors.rb +58 -0
  32. data/lib/backup/logger.rb +199 -0
  33. data/lib/backup/logger/console.rb +51 -0
  34. data/lib/backup/logger/fog_adapter.rb +29 -0
  35. data/lib/backup/logger/logfile.rb +133 -0
  36. data/lib/backup/logger/syslog.rb +116 -0
  37. data/lib/backup/model.rb +454 -0
  38. data/lib/backup/notifier/base.rb +98 -0
  39. data/lib/backup/notifier/campfire.rb +69 -0
  40. data/lib/backup/notifier/datadog.rb +116 -0
  41. data/lib/backup/notifier/flowdock.rb +102 -0
  42. data/lib/backup/notifier/hipchat.rb +93 -0
  43. data/lib/backup/notifier/http_post.rb +122 -0
  44. data/lib/backup/notifier/mail.rb +238 -0
  45. data/lib/backup/notifier/nagios.rb +74 -0
  46. data/lib/backup/notifier/pagerduty.rb +81 -0
  47. data/lib/backup/notifier/prowl.rb +69 -0
  48. data/lib/backup/notifier/pushover.rb +80 -0
  49. data/lib/backup/notifier/ses.rb +94 -0
  50. data/lib/backup/notifier/slack.rb +154 -0
  51. data/lib/backup/notifier/twitter.rb +64 -0
  52. data/lib/backup/notifier/zabbix.rb +68 -0
  53. data/lib/backup/package.rb +51 -0
  54. data/lib/backup/packager.rb +101 -0
  55. data/lib/backup/pipeline.rb +124 -0
  56. data/lib/backup/splitter.rb +76 -0
  57. data/lib/backup/storage/base.rb +57 -0
  58. data/lib/backup/storage/cloud_files.rb +158 -0
  59. data/lib/backup/storage/cycler.rb +65 -0
  60. data/lib/backup/storage/dropbox.rb +236 -0
  61. data/lib/backup/storage/ftp.rb +98 -0
  62. data/lib/backup/storage/local.rb +64 -0
  63. data/lib/backup/storage/ninefold.rb +74 -0
  64. data/lib/backup/storage/rsync.rb +248 -0
  65. data/lib/backup/storage/s3.rb +155 -0
  66. data/lib/backup/storage/scp.rb +67 -0
  67. data/lib/backup/storage/sftp.rb +82 -0
  68. data/lib/backup/syncer/base.rb +70 -0
  69. data/lib/backup/syncer/cloud/base.rb +179 -0
  70. data/lib/backup/syncer/cloud/cloud_files.rb +83 -0
  71. data/lib/backup/syncer/cloud/local_file.rb +100 -0
  72. data/lib/backup/syncer/cloud/s3.rb +110 -0
  73. data/lib/backup/syncer/rsync/base.rb +48 -0
  74. data/lib/backup/syncer/rsync/local.rb +31 -0
  75. data/lib/backup/syncer/rsync/pull.rb +51 -0
  76. data/lib/backup/syncer/rsync/push.rb +205 -0
  77. data/lib/backup/template.rb +46 -0
  78. data/lib/backup/utilities.rb +224 -0
  79. data/lib/backup/version.rb +5 -0
  80. data/templates/cli/archive +28 -0
  81. data/templates/cli/compressor/bzip2 +4 -0
  82. data/templates/cli/compressor/custom +7 -0
  83. data/templates/cli/compressor/gzip +4 -0
  84. data/templates/cli/config +123 -0
  85. data/templates/cli/databases/mongodb +15 -0
  86. data/templates/cli/databases/mysql +18 -0
  87. data/templates/cli/databases/openldap +24 -0
  88. data/templates/cli/databases/postgresql +16 -0
  89. data/templates/cli/databases/redis +16 -0
  90. data/templates/cli/databases/riak +17 -0
  91. data/templates/cli/databases/sqlite +11 -0
  92. data/templates/cli/encryptor/gpg +27 -0
  93. data/templates/cli/encryptor/openssl +9 -0
  94. data/templates/cli/model +26 -0
  95. data/templates/cli/notifier/zabbix +15 -0
  96. data/templates/cli/notifiers/campfire +12 -0
  97. data/templates/cli/notifiers/datadog +57 -0
  98. data/templates/cli/notifiers/flowdock +16 -0
  99. data/templates/cli/notifiers/hipchat +15 -0
  100. data/templates/cli/notifiers/http_post +32 -0
  101. data/templates/cli/notifiers/mail +21 -0
  102. data/templates/cli/notifiers/nagios +13 -0
  103. data/templates/cli/notifiers/pagerduty +12 -0
  104. data/templates/cli/notifiers/prowl +11 -0
  105. data/templates/cli/notifiers/pushover +11 -0
  106. data/templates/cli/notifiers/ses +15 -0
  107. data/templates/cli/notifiers/slack +22 -0
  108. data/templates/cli/notifiers/twitter +13 -0
  109. data/templates/cli/splitter +7 -0
  110. data/templates/cli/storages/cloud_files +11 -0
  111. data/templates/cli/storages/dropbox +19 -0
  112. data/templates/cli/storages/ftp +12 -0
  113. data/templates/cli/storages/local +7 -0
  114. data/templates/cli/storages/ninefold +9 -0
  115. data/templates/cli/storages/rsync +17 -0
  116. data/templates/cli/storages/s3 +14 -0
  117. data/templates/cli/storages/scp +14 -0
  118. data/templates/cli/storages/sftp +14 -0
  119. data/templates/cli/syncers/cloud_files +22 -0
  120. data/templates/cli/syncers/rsync_local +20 -0
  121. data/templates/cli/syncers/rsync_pull +28 -0
  122. data/templates/cli/syncers/rsync_push +28 -0
  123. data/templates/cli/syncers/s3 +27 -0
  124. data/templates/general/links +3 -0
  125. data/templates/general/version.erb +2 -0
  126. data/templates/notifier/mail/failure.erb +16 -0
  127. data/templates/notifier/mail/success.erb +16 -0
  128. data/templates/notifier/mail/warning.erb +16 -0
  129. data/templates/storage/dropbox/authorization_url.erb +6 -0
  130. data/templates/storage/dropbox/authorized.erb +4 -0
  131. data/templates/storage/dropbox/cache_file_written.erb +10 -0
  132. metadata +1057 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ca21e187d62587f721654eb3ae84a84cf5e5f65
4
+ data.tar.gz: 359e12d0e6d1e3762207b5cc99ad9cc6584dae0c
5
+ SHA512:
6
+ metadata.gz: ed9a3a6af42428ec67c601d0ecf2a57e3f1e01031d495c7c9d1b00e282eac7e2c66ea36810434321fbb8a02807df5aa8c509df123db4234834609c996aefc9cd
7
+ data.tar.gz: c6b399157b606def1740f2108ad947140a77466adb90733564cf97650581e7be0dfe17a645e18408910468af99d04d663e4a53d884bd96719ed00eb7671dc806
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,25 @@
1
+ Backup v4.x
2
+ ===========
3
+ [![Code Climate](https://codeclimate.com/github/backup/backup.png)](https://codeclimate.com/github/backup/backup)
4
+ [![Build Status](https://travis-ci.org/backup/backup.svg?branch=master)](https://travis-ci.org/backup/backup)
5
+
6
+ Backup is a system utility for Linux and Mac OS X, distributed as a RubyGem, that allows you to easily perform backup
7
+ operations. It provides an elegant DSL in Ruby for _modeling_ your backups. Backup has built-in support for various
8
+ databases, storage protocols/services, syncers, compressors, encryptors and notifiers which you can mix and match. It
9
+ was built with modularity, extensibility and simplicity in mind.
10
+
11
+ [Installation][] · [Release Notes][] · [Documentation][] · [Issues][] · [Features][]
12
+
13
+ Please use the Backup features [issue tracker][Features] to suggest new features.
14
+ Only use the Backup gem [issue tracker][Issues] for bugs and other issues.
15
+
16
+ **Copyright (c) 2009-2015 [Michael van Rooijen][] ( [@meskyanichi][] )**
17
+ Released under the **MIT** [License](LICENSE.md).
18
+
19
+ [Installation]: http://backup.github.io/backup/v4/installation
20
+ [Release Notes]: http://backup.github.io/backup/v4/release-notes
21
+ [Documentation]: http://backup.github.io/backup/v4
22
+ [Issues]: https://github.com/backup/backup/issues
23
+ [Features]: https://github.com/meskyanichi/backup-features/issues
24
+ [Michael van Rooijen]: http://michaelvanrooijen.com
25
+ [@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,141 @@
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
+ require 'shellwords'
15
+
16
+ require 'excon'
17
+ # Include response.inspect in error messages.
18
+ Excon.defaults[:debug_response] = true
19
+ # Excon should not retry failed requests. We handle that.
20
+ Excon.defaults[:middlewares].delete(Excon::Middleware::Idempotent)
21
+
22
+ ##
23
+ # The Backup Ruby Gem
24
+ module Backup
25
+
26
+ ##
27
+ # Backup's internal paths
28
+ LIBRARY_PATH = File.join(File.dirname(__FILE__), 'backup')
29
+ STORAGE_PATH = File.join(LIBRARY_PATH, 'storage')
30
+ SYNCER_PATH = File.join(LIBRARY_PATH, 'syncer')
31
+ DATABASE_PATH = File.join(LIBRARY_PATH, 'database')
32
+ COMPRESSOR_PATH = File.join(LIBRARY_PATH, 'compressor')
33
+ ENCRYPTOR_PATH = File.join(LIBRARY_PATH, 'encryptor')
34
+ NOTIFIER_PATH = File.join(LIBRARY_PATH, 'notifier')
35
+ TEMPLATE_PATH = File.expand_path('../../templates', __FILE__)
36
+
37
+ ##
38
+ # Autoload Backup storage files
39
+ module Storage
40
+ autoload :Base, File.join(STORAGE_PATH, 'base')
41
+ autoload :Cycler, File.join(STORAGE_PATH, 'cycler')
42
+ autoload :S3, File.join(STORAGE_PATH, 's3')
43
+ autoload :CloudFiles, File.join(STORAGE_PATH, 'cloud_files')
44
+ autoload :Ninefold, File.join(STORAGE_PATH, 'ninefold')
45
+ autoload :Dropbox, File.join(STORAGE_PATH, 'dropbox')
46
+ autoload :FTP, File.join(STORAGE_PATH, 'ftp')
47
+ autoload :SFTP, File.join(STORAGE_PATH, 'sftp')
48
+ autoload :SCP, File.join(STORAGE_PATH, 'scp')
49
+ autoload :RSync, File.join(STORAGE_PATH, 'rsync')
50
+ autoload :Local, File.join(STORAGE_PATH, 'local')
51
+ end
52
+
53
+ ##
54
+ # Autoload Backup syncer files
55
+ module Syncer
56
+ autoload :Base, File.join(SYNCER_PATH, 'base')
57
+ module Cloud
58
+ autoload :Base, File.join(SYNCER_PATH, 'cloud', 'base')
59
+ autoload :LocalFile, File.join(SYNCER_PATH, 'cloud', 'local_file')
60
+ autoload :CloudFiles, File.join(SYNCER_PATH, 'cloud', 'cloud_files')
61
+ autoload :S3, File.join(SYNCER_PATH, 'cloud', 's3')
62
+ end
63
+ module RSync
64
+ autoload :Base, File.join(SYNCER_PATH, 'rsync', 'base')
65
+ autoload :Local, File.join(SYNCER_PATH, 'rsync', 'local')
66
+ autoload :Push, File.join(SYNCER_PATH, 'rsync', 'push')
67
+ autoload :Pull, File.join(SYNCER_PATH, 'rsync', 'pull')
68
+ end
69
+ end
70
+
71
+ ##
72
+ # Autoload Backup database files
73
+ module Database
74
+ autoload :Base, File.join(DATABASE_PATH, 'base')
75
+ autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
76
+ autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
77
+ autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
78
+ autoload :Redis, File.join(DATABASE_PATH, 'redis')
79
+ autoload :Riak, File.join(DATABASE_PATH, 'riak')
80
+ autoload :OpenLDAP, File.join(DATABASE_PATH, 'openldap')
81
+ autoload :SQLite, File.join(DATABASE_PATH, 'sqlite')
82
+ end
83
+
84
+ ##
85
+ # Autoload compressor files
86
+ module Compressor
87
+ autoload :Base, File.join(COMPRESSOR_PATH, 'base')
88
+ autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
89
+ autoload :Bzip2, File.join(COMPRESSOR_PATH, 'bzip2')
90
+ autoload :Custom, File.join(COMPRESSOR_PATH, 'custom')
91
+ end
92
+
93
+ ##
94
+ # Autoload encryptor files
95
+ module Encryptor
96
+ autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
97
+ autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
98
+ autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
99
+ end
100
+
101
+ ##
102
+ # Autoload notification files
103
+ module Notifier
104
+ autoload :Base, File.join(NOTIFIER_PATH, 'base')
105
+ autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
106
+ autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter')
107
+ autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
108
+ autoload :Prowl, File.join(NOTIFIER_PATH, 'prowl')
109
+ autoload :Hipchat, File.join(NOTIFIER_PATH, 'hipchat')
110
+ autoload :PagerDuty, File.join(NOTIFIER_PATH, 'pagerduty')
111
+ autoload :Pushover, File.join(NOTIFIER_PATH, 'pushover')
112
+ autoload :Slack, File.join(NOTIFIER_PATH, 'slack')
113
+ autoload :HttpPost, File.join(NOTIFIER_PATH, 'http_post')
114
+ autoload :Nagios, File.join(NOTIFIER_PATH, 'nagios')
115
+ autoload :FlowDock, File.join(NOTIFIER_PATH, 'flowdock')
116
+ autoload :Zabbix, File.join(NOTIFIER_PATH, 'zabbix')
117
+ autoload :DataDog, File.join(NOTIFIER_PATH, 'datadog')
118
+ autoload :Ses, File.join(NOTIFIER_PATH, 'ses')
119
+ end
120
+
121
+ ##
122
+ # Require Backup base files
123
+ %w{
124
+ errors
125
+ logger
126
+ utilities
127
+ archive
128
+ binder
129
+ cleaner
130
+ model
131
+ config
132
+ cli
133
+ package
134
+ packager
135
+ pipeline
136
+ splitter
137
+ template
138
+ version
139
+ }.each {|lib| require File.join(LIBRARY_PATH, lib) }
140
+
141
+ 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