cm-backup 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +20 -0
- data/bin/backup +5 -0
- data/lib/backup.rb +144 -0
- data/lib/backup/archive.rb +170 -0
- data/lib/backup/binder.rb +22 -0
- data/lib/backup/cleaner.rb +116 -0
- data/lib/backup/cli.rb +374 -0
- data/lib/backup/cloud_io/base.rb +41 -0
- data/lib/backup/cloud_io/cloud_files.rb +298 -0
- data/lib/backup/cloud_io/s3.rb +260 -0
- data/lib/backup/compressor/base.rb +35 -0
- data/lib/backup/compressor/bzip2.rb +39 -0
- data/lib/backup/compressor/custom.rb +53 -0
- data/lib/backup/compressor/gzip.rb +74 -0
- data/lib/backup/config.rb +119 -0
- data/lib/backup/config/dsl.rb +103 -0
- data/lib/backup/config/helpers.rb +143 -0
- data/lib/backup/database/base.rb +85 -0
- data/lib/backup/database/mongodb.rb +187 -0
- data/lib/backup/database/mysql.rb +192 -0
- data/lib/backup/database/openldap.rb +95 -0
- data/lib/backup/database/postgresql.rb +133 -0
- data/lib/backup/database/redis.rb +179 -0
- data/lib/backup/database/riak.rb +82 -0
- data/lib/backup/database/sqlite.rb +57 -0
- data/lib/backup/encryptor/base.rb +29 -0
- data/lib/backup/encryptor/gpg.rb +747 -0
- data/lib/backup/encryptor/open_ssl.rb +77 -0
- data/lib/backup/errors.rb +58 -0
- data/lib/backup/logger.rb +199 -0
- data/lib/backup/logger/console.rb +51 -0
- data/lib/backup/logger/fog_adapter.rb +29 -0
- data/lib/backup/logger/logfile.rb +133 -0
- data/lib/backup/logger/syslog.rb +116 -0
- data/lib/backup/model.rb +479 -0
- data/lib/backup/notifier/base.rb +128 -0
- data/lib/backup/notifier/campfire.rb +63 -0
- data/lib/backup/notifier/command.rb +102 -0
- data/lib/backup/notifier/datadog.rb +107 -0
- data/lib/backup/notifier/flowdock.rb +103 -0
- data/lib/backup/notifier/hipchat.rb +118 -0
- data/lib/backup/notifier/http_post.rb +117 -0
- data/lib/backup/notifier/mail.rb +249 -0
- data/lib/backup/notifier/nagios.rb +69 -0
- data/lib/backup/notifier/pagerduty.rb +81 -0
- data/lib/backup/notifier/prowl.rb +68 -0
- data/lib/backup/notifier/pushover.rb +74 -0
- data/lib/backup/notifier/ses.rb +105 -0
- data/lib/backup/notifier/slack.rb +148 -0
- data/lib/backup/notifier/twitter.rb +58 -0
- data/lib/backup/notifier/zabbix.rb +63 -0
- data/lib/backup/package.rb +55 -0
- data/lib/backup/packager.rb +107 -0
- data/lib/backup/pipeline.rb +124 -0
- data/lib/backup/splitter.rb +76 -0
- data/lib/backup/storage/base.rb +69 -0
- data/lib/backup/storage/cloud_files.rb +158 -0
- data/lib/backup/storage/cycler.rb +75 -0
- data/lib/backup/storage/dropbox.rb +212 -0
- data/lib/backup/storage/ftp.rb +112 -0
- data/lib/backup/storage/local.rb +64 -0
- data/lib/backup/storage/qiniu.rb +65 -0
- data/lib/backup/storage/rsync.rb +248 -0
- data/lib/backup/storage/s3.rb +156 -0
- data/lib/backup/storage/scp.rb +67 -0
- data/lib/backup/storage/sftp.rb +82 -0
- data/lib/backup/syncer/base.rb +70 -0
- data/lib/backup/syncer/cloud/base.rb +179 -0
- data/lib/backup/syncer/cloud/cloud_files.rb +83 -0
- data/lib/backup/syncer/cloud/local_file.rb +100 -0
- data/lib/backup/syncer/cloud/s3.rb +110 -0
- data/lib/backup/syncer/rsync/base.rb +54 -0
- data/lib/backup/syncer/rsync/local.rb +31 -0
- data/lib/backup/syncer/rsync/pull.rb +51 -0
- data/lib/backup/syncer/rsync/push.rb +205 -0
- data/lib/backup/template.rb +46 -0
- data/lib/backup/utilities.rb +224 -0
- data/lib/backup/version.rb +5 -0
- data/templates/cli/archive +28 -0
- data/templates/cli/compressor/bzip2 +4 -0
- data/templates/cli/compressor/custom +7 -0
- data/templates/cli/compressor/gzip +4 -0
- data/templates/cli/config +123 -0
- data/templates/cli/databases/mongodb +15 -0
- data/templates/cli/databases/mysql +18 -0
- data/templates/cli/databases/openldap +24 -0
- data/templates/cli/databases/postgresql +16 -0
- data/templates/cli/databases/redis +16 -0
- data/templates/cli/databases/riak +17 -0
- data/templates/cli/databases/sqlite +11 -0
- data/templates/cli/encryptor/gpg +27 -0
- data/templates/cli/encryptor/openssl +9 -0
- data/templates/cli/model +26 -0
- data/templates/cli/notifier/zabbix +15 -0
- data/templates/cli/notifiers/campfire +12 -0
- data/templates/cli/notifiers/command +32 -0
- data/templates/cli/notifiers/datadog +57 -0
- data/templates/cli/notifiers/flowdock +16 -0
- data/templates/cli/notifiers/hipchat +16 -0
- data/templates/cli/notifiers/http_post +32 -0
- data/templates/cli/notifiers/mail +24 -0
- data/templates/cli/notifiers/nagios +13 -0
- data/templates/cli/notifiers/pagerduty +12 -0
- data/templates/cli/notifiers/prowl +11 -0
- data/templates/cli/notifiers/pushover +11 -0
- data/templates/cli/notifiers/ses +15 -0
- data/templates/cli/notifiers/slack +22 -0
- data/templates/cli/notifiers/twitter +13 -0
- data/templates/cli/splitter +7 -0
- data/templates/cli/storages/cloud_files +11 -0
- data/templates/cli/storages/dropbox +20 -0
- data/templates/cli/storages/ftp +13 -0
- data/templates/cli/storages/local +8 -0
- data/templates/cli/storages/qiniu +12 -0
- data/templates/cli/storages/rsync +17 -0
- data/templates/cli/storages/s3 +16 -0
- data/templates/cli/storages/scp +15 -0
- data/templates/cli/storages/sftp +15 -0
- data/templates/cli/syncers/cloud_files +22 -0
- data/templates/cli/syncers/rsync_local +20 -0
- data/templates/cli/syncers/rsync_pull +28 -0
- data/templates/cli/syncers/rsync_push +28 -0
- data/templates/cli/syncers/s3 +27 -0
- data/templates/general/links +3 -0
- data/templates/general/version.erb +2 -0
- data/templates/notifier/mail/failure.erb +16 -0
- data/templates/notifier/mail/success.erb +16 -0
- data/templates/notifier/mail/warning.erb +16 -0
- data/templates/storage/dropbox/authorization_url.erb +6 -0
- data/templates/storage/dropbox/authorized.erb +4 -0
- data/templates/storage/dropbox/cache_file_written.erb +10 -0
- metadata +1077 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e254901b4c9e89690ac27a258de68d906299b730f921237dfffcb689180fbfdc
|
4
|
+
data.tar.gz: d8ecef84eb2bf0311c8edad4c8315e41541cc8662fcc68562e7efe3c56872ca2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9f4c0ea8b57ef5a3babd672b3385f82cc8a073b9820e8d0e9ffae9c53c8b7d591efcbdc5dc96ce4ff3616fe01260d0906f1204610dae2871a2ad95e830135ee9
|
7
|
+
data.tar.gz: f4b47338bd217c35526b4e630247918e9eb111284abbb7b8f071d0a3caf4d87376110cd520bdc7ff78fb5f35880a04df0d43f0b86d5bd3242ccf4477e5d59a1b
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
cm-backup v1.x
|
2
|
+
===========
|
3
|
+
|
4
|
+
This project is forked from [backup/backup](https://github.com/backup/backup). Due to lack of help availiable we've hosted our own version on ruby-gems and will also maintain it on this repository. [The existing documentation](https://backup.github.io/backup/v4/) is already in a fantastic shape, we'll keep adding to it as needed.
|
5
|
+
|
6
|
+
__Description from source__
|
7
|
+
|
8
|
+
Backup 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. Backup 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][]
|
14
|
+
|
15
|
+
*Copyright (c) 2009-2016 [Michael van Rooijen]*
|
16
|
+
Released under the **MIT** [LICENSE](LICENSE).
|
17
|
+
|
18
|
+
[Installation]: http://backup.github.io/backup/v4/installation
|
19
|
+
[Release Notes]: http://backup.github.io/backup/v4/release-notes
|
20
|
+
[Documentation]: http://backup.github.io/backup/v4
|
data/bin/backup
ADDED
data/lib/backup.rb
ADDED
@@ -0,0 +1,144 @@
|
|
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 Backup Ruby Gem
|
25
|
+
module Backup
|
26
|
+
|
27
|
+
##
|
28
|
+
# Backup's internal paths
|
29
|
+
LIBRARY_PATH = File.join(File.dirname(__FILE__), '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 Backup 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
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Autoload Backup syncer files
|
57
|
+
module Syncer
|
58
|
+
autoload :Base, File.join(SYNCER_PATH, 'base')
|
59
|
+
module Cloud
|
60
|
+
autoload :Base, File.join(SYNCER_PATH, 'cloud', 'base')
|
61
|
+
autoload :LocalFile, File.join(SYNCER_PATH, 'cloud', 'local_file')
|
62
|
+
autoload :CloudFiles, File.join(SYNCER_PATH, 'cloud', 'cloud_files')
|
63
|
+
autoload :S3, File.join(SYNCER_PATH, 'cloud', 's3')
|
64
|
+
end
|
65
|
+
module RSync
|
66
|
+
autoload :Base, File.join(SYNCER_PATH, 'rsync', 'base')
|
67
|
+
autoload :Local, File.join(SYNCER_PATH, 'rsync', 'local')
|
68
|
+
autoload :Push, File.join(SYNCER_PATH, 'rsync', 'push')
|
69
|
+
autoload :Pull, File.join(SYNCER_PATH, 'rsync', 'pull')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Autoload Backup database files
|
75
|
+
module Database
|
76
|
+
autoload :Base, File.join(DATABASE_PATH, 'base')
|
77
|
+
autoload :MySQL, File.join(DATABASE_PATH, 'mysql')
|
78
|
+
autoload :PostgreSQL, File.join(DATABASE_PATH, 'postgresql')
|
79
|
+
autoload :MongoDB, File.join(DATABASE_PATH, 'mongodb')
|
80
|
+
autoload :Redis, File.join(DATABASE_PATH, 'redis')
|
81
|
+
autoload :Riak, File.join(DATABASE_PATH, 'riak')
|
82
|
+
autoload :OpenLDAP, File.join(DATABASE_PATH, 'openldap')
|
83
|
+
autoload :SQLite, File.join(DATABASE_PATH, 'sqlite')
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Autoload compressor files
|
88
|
+
module Compressor
|
89
|
+
autoload :Base, File.join(COMPRESSOR_PATH, 'base')
|
90
|
+
autoload :Gzip, File.join(COMPRESSOR_PATH, 'gzip')
|
91
|
+
autoload :Bzip2, File.join(COMPRESSOR_PATH, 'bzip2')
|
92
|
+
autoload :Custom, File.join(COMPRESSOR_PATH, 'custom')
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Autoload encryptor files
|
97
|
+
module Encryptor
|
98
|
+
autoload :Base, File.join(ENCRYPTOR_PATH, 'base')
|
99
|
+
autoload :OpenSSL, File.join(ENCRYPTOR_PATH, 'open_ssl')
|
100
|
+
autoload :GPG, File.join(ENCRYPTOR_PATH, 'gpg')
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Autoload notification files
|
105
|
+
module Notifier
|
106
|
+
autoload :Base, File.join(NOTIFIER_PATH, 'base')
|
107
|
+
autoload :Mail, File.join(NOTIFIER_PATH, 'mail')
|
108
|
+
autoload :Twitter, File.join(NOTIFIER_PATH, 'twitter')
|
109
|
+
autoload :Campfire, File.join(NOTIFIER_PATH, 'campfire')
|
110
|
+
autoload :Prowl, File.join(NOTIFIER_PATH, 'prowl')
|
111
|
+
autoload :Hipchat, File.join(NOTIFIER_PATH, 'hipchat')
|
112
|
+
autoload :PagerDuty, File.join(NOTIFIER_PATH, 'pagerduty')
|
113
|
+
autoload :Pushover, File.join(NOTIFIER_PATH, 'pushover')
|
114
|
+
autoload :Slack, File.join(NOTIFIER_PATH, 'slack')
|
115
|
+
autoload :HttpPost, File.join(NOTIFIER_PATH, 'http_post')
|
116
|
+
autoload :Nagios, File.join(NOTIFIER_PATH, 'nagios')
|
117
|
+
autoload :FlowDock, File.join(NOTIFIER_PATH, 'flowdock')
|
118
|
+
autoload :Zabbix, File.join(NOTIFIER_PATH, 'zabbix')
|
119
|
+
autoload :DataDog, File.join(NOTIFIER_PATH, 'datadog')
|
120
|
+
autoload :Ses, File.join(NOTIFIER_PATH, 'ses')
|
121
|
+
autoload :Command, File.join(NOTIFIER_PATH, 'command')
|
122
|
+
end
|
123
|
+
|
124
|
+
##
|
125
|
+
# Require Backup base files
|
126
|
+
%w{
|
127
|
+
errors
|
128
|
+
logger
|
129
|
+
utilities
|
130
|
+
archive
|
131
|
+
binder
|
132
|
+
cleaner
|
133
|
+
model
|
134
|
+
config
|
135
|
+
cli
|
136
|
+
package
|
137
|
+
packager
|
138
|
+
pipeline
|
139
|
+
splitter
|
140
|
+
template
|
141
|
+
version
|
142
|
+
}.each {|lib| require File.join(LIBRARY_PATH, lib) }
|
143
|
+
|
144
|
+
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
|