sliday_backup 0.1

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