backup 3.11.0 → 4.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/backup.rb +1 -4
- data/lib/backup/archive.rb +1 -1
- data/lib/backup/cli.rb +51 -107
- data/lib/backup/compressor/base.rb +2 -2
- data/lib/backup/compressor/bzip2.rb +0 -11
- data/lib/backup/compressor/gzip.rb +0 -11
- data/lib/backup/config.rb +45 -123
- data/lib/backup/config/dsl.rb +102 -0
- data/lib/backup/{configuration → config}/helpers.rb +23 -14
- data/lib/backup/database/base.rb +2 -2
- data/lib/backup/database/mongodb.rb +0 -18
- data/lib/backup/database/mysql.rb +6 -75
- data/lib/backup/database/postgresql.rb +0 -12
- data/lib/backup/database/redis.rb +85 -47
- data/lib/backup/database/riak.rb +0 -19
- data/lib/backup/encryptor/base.rb +2 -2
- data/lib/backup/encryptor/gpg.rb +1 -12
- data/lib/backup/logger/fog_adapter.rb +1 -2
- data/lib/backup/model.rb +3 -24
- data/lib/backup/notifier/base.rb +2 -17
- data/lib/backup/notifier/http_post.rb +1 -1
- data/lib/backup/notifier/mail.rb +5 -47
- data/lib/backup/notifier/prowl.rb +1 -1
- data/lib/backup/notifier/pushover.rb +1 -1
- data/lib/backup/packager.rb +1 -1
- data/lib/backup/pipeline.rb +1 -1
- data/lib/backup/splitter.rb +1 -1
- data/lib/backup/storage/base.rb +2 -14
- data/lib/backup/storage/cloud_files.rb +1 -0
- data/lib/backup/storage/cycler.rb +33 -88
- data/lib/backup/storage/dropbox.rb +19 -12
- data/lib/backup/storage/ftp.rb +1 -0
- data/lib/backup/storage/local.rb +1 -0
- data/lib/backup/storage/ninefold.rb +1 -0
- data/lib/backup/storage/rsync.rb +7 -41
- data/lib/backup/storage/s3.rb +1 -0
- data/lib/backup/storage/scp.rb +1 -0
- data/lib/backup/storage/sftp.rb +1 -0
- data/lib/backup/syncer/base.rb +2 -2
- data/lib/backup/syncer/cloud/cloud_files.rb +0 -16
- data/lib/backup/syncer/cloud/s3.rb +0 -16
- data/lib/backup/syncer/rsync/local.rb +0 -5
- data/lib/backup/syncer/rsync/pull.rb +0 -21
- data/lib/backup/syncer/rsync/push.rb +0 -21
- data/lib/backup/utilities.rb +2 -22
- data/lib/backup/version.rb +1 -1
- data/templates/cli/archive +0 -3
- data/templates/cli/compressor/custom +0 -4
- data/templates/cli/config +39 -17
- data/templates/cli/{database → databases}/mongodb +0 -0
- data/templates/cli/{database → databases}/mysql +0 -0
- data/templates/cli/{database → databases}/postgresql +0 -0
- data/templates/cli/databases/redis +16 -0
- data/templates/cli/{database → databases}/riak +0 -0
- data/templates/cli/{model.erb → model} +8 -5
- data/templates/cli/{notifier → notifiers}/campfire +0 -0
- data/templates/cli/{notifier → notifiers}/hipchat +0 -0
- data/templates/cli/{notifier → notifiers}/http_post +0 -3
- data/templates/cli/{notifier → notifiers}/mail +1 -2
- data/templates/cli/notifiers/nagios +13 -0
- data/templates/cli/{notifier → notifiers}/prowl +0 -0
- data/templates/cli/{notifier → notifiers}/pushover +0 -0
- data/templates/cli/{notifier → notifiers}/twitter +0 -0
- data/templates/cli/{storage → storages}/cloud_files +0 -2
- data/templates/cli/storages/dropbox +19 -0
- data/templates/cli/{storage → storages}/ftp +0 -0
- data/templates/cli/{storage → storages}/local +0 -0
- data/templates/cli/{storage → storages}/ninefold +0 -0
- data/templates/cli/{storage → storages}/rsync +0 -2
- data/templates/cli/{storage → storages}/s3 +0 -2
- data/templates/cli/{storage → storages}/scp +0 -0
- data/templates/cli/{storage → storages}/sftp +0 -0
- data/templates/cli/{syncer → syncers}/cloud_files +0 -2
- data/templates/cli/{syncer → syncers}/rsync_local +0 -0
- data/templates/cli/{syncer → syncers}/rsync_pull +0 -2
- data/templates/cli/{syncer → syncers}/rsync_push +0 -2
- data/templates/cli/{syncer → syncers}/s3 +0 -2
- data/templates/general/links +1 -1
- metadata +241 -69
- data/lib/backup/compressor/lzma.rb +0 -52
- data/lib/backup/compressor/pbzip2.rb +0 -59
- data/lib/backup/configuration.rb +0 -33
- data/lib/backup/configuration/store.rb +0 -24
- data/templates/cli/compressor/lzma +0 -10
- data/templates/cli/compressor/pbzip2 +0 -10
- data/templates/cli/database/redis +0 -18
- data/templates/cli/notifier/nagios +0 -13
- data/templates/cli/storage/dropbox +0 -20
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Config
|
5
|
+
# Context for loading user config.rb and model files.
|
6
|
+
class DSL
|
7
|
+
class Error < Backup::Error; end
|
8
|
+
Model = Backup::Model
|
9
|
+
|
10
|
+
class << self
|
11
|
+
private
|
12
|
+
|
13
|
+
# List the available database, storage, syncer, compressor, encryptor
|
14
|
+
# and notifier constants. These are used to define constant names within
|
15
|
+
# Backup::Config::DSL so that users may use a constant instead of a string.
|
16
|
+
# Nested namespaces are represented using Hashs. Deep nesting supported.
|
17
|
+
#
|
18
|
+
# Example, instead of:
|
19
|
+
# database "MySQL" do |mysql|
|
20
|
+
# sync_with "RSync::Local" do |rsync|
|
21
|
+
#
|
22
|
+
# You can do:
|
23
|
+
# database MySQL do |mysql|
|
24
|
+
# sync_with RSync::Local do |rsync|
|
25
|
+
#
|
26
|
+
def add_dsl_constants
|
27
|
+
create_modules(
|
28
|
+
DSL,
|
29
|
+
[ # Databases
|
30
|
+
['MySQL', 'PostgreSQL', 'MongoDB', 'Redis', 'Riak'],
|
31
|
+
# Storages
|
32
|
+
['S3', 'CloudFiles', 'Ninefold', 'Dropbox', 'FTP',
|
33
|
+
'SFTP', 'SCP', 'RSync', 'Local'],
|
34
|
+
# Compressors
|
35
|
+
['Gzip', 'Bzip2', 'Custom', 'Pbzip2', 'Lzma'],
|
36
|
+
# Encryptors
|
37
|
+
['OpenSSL', 'GPG'],
|
38
|
+
# Syncers
|
39
|
+
[
|
40
|
+
{ 'Cloud' => ['CloudFiles', 'S3'] },
|
41
|
+
{ 'RSync' => ['Push', 'Pull', 'Local'] }
|
42
|
+
],
|
43
|
+
# Notifiers
|
44
|
+
['Mail', 'Twitter', 'Campfire', 'Prowl',
|
45
|
+
'Hipchat', 'Pushover', 'HttpPost', 'Nagios']
|
46
|
+
]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_modules(scope, names)
|
51
|
+
names.flatten.each do |name|
|
52
|
+
if name.is_a?(Hash)
|
53
|
+
name.each do |key, val|
|
54
|
+
create_modules(get_or_create_empty_module(scope, key), [val])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
get_or_create_empty_module(scope, name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_or_create_empty_module(scope, const)
|
63
|
+
if scope.const_defined?(const)
|
64
|
+
scope.const_get(const)
|
65
|
+
else
|
66
|
+
scope.const_set(const, Module.new)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
add_dsl_constants # add constants on load
|
72
|
+
|
73
|
+
attr_reader :_config_options
|
74
|
+
|
75
|
+
def initialize
|
76
|
+
@_config_options = {}
|
77
|
+
end
|
78
|
+
|
79
|
+
# Allow users to set command line path options in config.rb
|
80
|
+
[:root_path, :data_path, :tmp_path].each do |name|
|
81
|
+
define_method name, lambda {|path| _config_options[name] = path }
|
82
|
+
end
|
83
|
+
|
84
|
+
# Allows users to create preconfigured models.
|
85
|
+
def preconfigure(name, &block)
|
86
|
+
unless name.is_a?(String) && name =~ /^[A-Z]/
|
87
|
+
raise Error, "Preconfigured model names must be given as a string " +
|
88
|
+
"and start with a capital letter."
|
89
|
+
end
|
90
|
+
|
91
|
+
if DSL.const_defined?(name)
|
92
|
+
raise Error, "'#{ name }' is already in use " +
|
93
|
+
"and can not be used for a preconfigured model."
|
94
|
+
end
|
95
|
+
|
96
|
+
DSL.const_set(name, Class.new(Model))
|
97
|
+
DSL.const_get(name).preconfigure(&block)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module Backup
|
4
|
-
module
|
5
|
-
class Error < Backup::Error; end
|
6
|
-
|
5
|
+
module Config
|
7
6
|
module Helpers
|
8
7
|
|
9
8
|
def self.included(klass)
|
@@ -12,20 +11,16 @@ module Backup
|
|
12
11
|
|
13
12
|
module ClassMethods
|
14
13
|
|
15
|
-
##
|
16
|
-
# Returns or yields the Configuration::Store
|
17
|
-
# for storing pre-configured defaults for the class.
|
18
14
|
def defaults
|
19
|
-
@
|
15
|
+
@defaults ||= Config::Defaults.new
|
20
16
|
|
21
17
|
if block_given?
|
22
|
-
yield @
|
18
|
+
yield @defaults
|
23
19
|
else
|
24
|
-
@
|
20
|
+
@defaults
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
|
-
##
|
29
24
|
# Used only within the specs
|
30
25
|
def clear_defaults!
|
31
26
|
defaults.reset!
|
@@ -39,7 +34,7 @@ module Backup
|
|
39
34
|
msg = "#{ self }##{ name } has been deprecated as of " +
|
40
35
|
"backup v.#{ deprecation[:version] }"
|
41
36
|
msg << "\n#{ deprecation[:message] }" if deprecation[:message]
|
42
|
-
Logger.warn Error.new(<<-EOS)
|
37
|
+
Logger.warn Config::Error.new(<<-EOS)
|
43
38
|
[DEPRECATION WARNING]
|
44
39
|
#{ msg }
|
45
40
|
EOS
|
@@ -85,9 +80,8 @@ module Backup
|
|
85
80
|
# If a default value was set for an invalid accessor,
|
86
81
|
# this will raise a NameError.
|
87
82
|
def load_defaults!
|
88
|
-
|
89
|
-
|
90
|
-
val = configuration.send(name)
|
83
|
+
self.class.defaults._attributes.each do |name|
|
84
|
+
val = self.class.defaults.send(name)
|
91
85
|
val = val.dup rescue val
|
92
86
|
send(:"#{ name }=", val)
|
93
87
|
end
|
@@ -129,6 +123,21 @@ module Backup
|
|
129
123
|
end
|
130
124
|
end
|
131
125
|
|
126
|
+
end # Helpers
|
127
|
+
|
128
|
+
# Store for pre-configured defaults.
|
129
|
+
class Defaults < OpenStruct
|
130
|
+
# Returns an Array of all attribute method names
|
131
|
+
# that default values were set for.
|
132
|
+
def _attributes
|
133
|
+
@table.keys
|
134
|
+
end
|
135
|
+
|
136
|
+
# Used only within the specs
|
137
|
+
def reset!
|
138
|
+
@table.clear
|
139
|
+
end
|
132
140
|
end
|
141
|
+
|
133
142
|
end
|
134
143
|
end
|
data/lib/backup/database/base.rb
CHANGED
@@ -181,24 +181,6 @@ module Backup
|
|
181
181
|
cmd
|
182
182
|
end
|
183
183
|
|
184
|
-
attr_deprecate :utility_path, :version => '3.0.21',
|
185
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
186
|
-
:action => lambda {|klass, val|
|
187
|
-
Utilities.configure { mongodump val }
|
188
|
-
}
|
189
|
-
|
190
|
-
attr_deprecate :mongodump_utility, :version => '3.3.0',
|
191
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
192
|
-
:action => lambda {|klass, val|
|
193
|
-
Utilities.configure { mongodump val }
|
194
|
-
}
|
195
|
-
|
196
|
-
attr_deprecate :mongo_utility, :version => '3.3.0',
|
197
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
198
|
-
:action => lambda {|klass, val|
|
199
|
-
Utilities.configure { mongo val }
|
200
|
-
}
|
201
|
-
|
202
184
|
end
|
203
185
|
end
|
204
186
|
end
|
@@ -32,48 +32,28 @@ module Backup
|
|
32
32
|
attr_accessor :only_tables
|
33
33
|
|
34
34
|
##
|
35
|
-
# Additional "mysqldump"
|
35
|
+
# Additional "mysqldump" options
|
36
36
|
attr_accessor :additional_options
|
37
37
|
|
38
|
-
##
|
39
|
-
# Additional innobackupex log preparation phase ("apply-logs") options
|
40
|
-
attr_accessor :prepare_options
|
41
|
-
|
42
|
-
##
|
43
|
-
# Default is :mysqldump (which is built in MySQL and generates
|
44
|
-
# a textual SQL file), but can be changed to :innobackupex, which
|
45
|
-
# has more feasible restore times for large databases.
|
46
|
-
# See: http://www.percona.com/doc/percona-xtrabackup/
|
47
|
-
attr_accessor :backup_engine
|
48
|
-
|
49
|
-
##
|
50
|
-
# If set the backup engine command block is executed as the given user
|
51
|
-
attr_accessor :sudo_user
|
52
|
-
|
53
|
-
##
|
54
|
-
# If set, do not suppress innobackupdb output (useful for debugging)
|
55
|
-
attr_accessor :verbose
|
56
|
-
|
57
38
|
def initialize(model, database_id = nil, &block)
|
58
39
|
super
|
59
40
|
instance_eval(&block) if block_given?
|
60
41
|
|
61
42
|
@name ||= :all
|
62
|
-
@backup_engine ||= :mysqldump
|
63
43
|
end
|
64
44
|
|
65
45
|
##
|
66
|
-
# Performs the mysqldump
|
67
|
-
#
|
46
|
+
# Performs the mysqldump command and outputs the dump file
|
47
|
+
# in the +dump_path+ using +dump_filename+.
|
68
48
|
#
|
69
|
-
# <trigger>/databases/MySQL[-<database_id>].
|
49
|
+
# <trigger>/databases/MySQL[-<database_id>].sql[.gz]
|
70
50
|
def perform!
|
71
51
|
super
|
72
52
|
|
73
53
|
pipeline = Pipeline.new
|
74
|
-
dump_ext =
|
54
|
+
dump_ext = 'sql'
|
75
55
|
|
76
|
-
pipeline <<
|
56
|
+
pipeline << mysqldump
|
77
57
|
|
78
58
|
model.compressor.compress_with do |command, ext|
|
79
59
|
pipeline << command
|
@@ -119,10 +99,6 @@ module Backup
|
|
119
99
|
Array(additional_options).join(' ')
|
120
100
|
end
|
121
101
|
|
122
|
-
def user_prepare_options
|
123
|
-
Array(prepare_options).join(' ')
|
124
|
-
end
|
125
|
-
|
126
102
|
def name_option
|
127
103
|
dump_all? ? '--all-databases' : name
|
128
104
|
end
|
@@ -142,51 +118,6 @@ module Backup
|
|
142
118
|
name == :all
|
143
119
|
end
|
144
120
|
|
145
|
-
attr_deprecate :utility_path, :version => '3.0.21',
|
146
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
147
|
-
:action => lambda {|klass, val|
|
148
|
-
Utilities.configure { mysqldump val }
|
149
|
-
}
|
150
|
-
|
151
|
-
attr_deprecate :mysqldump_utility, :version => '3.3.0',
|
152
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
153
|
-
:action => lambda {|klass, val|
|
154
|
-
Utilities.configure { mysqldump val }
|
155
|
-
}
|
156
|
-
|
157
|
-
def sql_backup?
|
158
|
-
backup_engine.to_sym == :mysqldump
|
159
|
-
end
|
160
|
-
|
161
|
-
def innobackupex
|
162
|
-
# Creation phase
|
163
|
-
"#{ utility(:innobackupex) } #{ credential_options } " +
|
164
|
-
"#{ connectivity_options } #{ user_options } " +
|
165
|
-
"--no-timestamp #{ temp_dir } #{ quiet_option } && " +
|
166
|
-
# Log applying phase (prepare for restore)
|
167
|
-
"#{ utility(:innobackupex) } --apply-log #{ temp_dir } " +
|
168
|
-
"#{ user_prepare_options } #{ quiet_option } && " +
|
169
|
-
# Move files to tar-ed stream on stdout
|
170
|
-
"#{ utility(:tar) } --remove-files -cf - " +
|
171
|
-
"-C #{ File.dirname(temp_dir) } #{ File.basename(temp_dir) }"
|
172
|
-
end
|
173
|
-
|
174
|
-
def sudo_option(command_block)
|
175
|
-
return command_block unless sudo_user
|
176
|
-
|
177
|
-
"sudo -s -u #{ sudo_user } -- <<END_OF_SUDO\n" +
|
178
|
-
"#{command_block}\n" +
|
179
|
-
"END_OF_SUDO\n"
|
180
|
-
end
|
181
|
-
|
182
|
-
def quiet_option
|
183
|
-
verbose ? "" : " 2> /dev/null "
|
184
|
-
end
|
185
|
-
|
186
|
-
def temp_dir
|
187
|
-
File.join(dump_path, dump_filename + ".bkpdir")
|
188
|
-
end
|
189
|
-
|
190
121
|
end
|
191
122
|
end
|
192
123
|
end
|
@@ -128,18 +128,6 @@ module Backup
|
|
128
128
|
name == :all
|
129
129
|
end
|
130
130
|
|
131
|
-
attr_deprecate :utility_path, :version => '3.0.21',
|
132
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
133
|
-
:action => lambda {|klass, val|
|
134
|
-
Utilities.configure { pg_dump val }
|
135
|
-
}
|
136
|
-
|
137
|
-
attr_deprecate :pg_dump_utility, :version => '3.3.0',
|
138
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
139
|
-
:action => lambda {|klass, val|
|
140
|
-
Utilities.configure { pg_dump val }
|
141
|
-
}
|
142
|
-
|
143
131
|
end
|
144
132
|
end
|
145
133
|
end
|
@@ -5,70 +5,121 @@ module Backup
|
|
5
5
|
class Redis < Base
|
6
6
|
class Error < Backup::Error; end
|
7
7
|
|
8
|
+
MODES = [:copy, :sync]
|
9
|
+
|
8
10
|
##
|
9
|
-
#
|
11
|
+
# Mode of operation.
|
12
|
+
#
|
13
|
+
# [:copy]
|
14
|
+
# Copies the redis dump file specified by {#rdb_path}.
|
15
|
+
# This data will be current as of the last RDB Snapshot
|
16
|
+
# performed by the server (per your redis.conf settings).
|
17
|
+
# You may set {#invoke_save} to +true+ to have Backup issue
|
18
|
+
# a +SAVE+ command to update the dump file with the current
|
19
|
+
# data before performing the copy.
|
20
|
+
#
|
21
|
+
# [:sync]
|
22
|
+
# Performs a dump of your redis data using +redis-cli --rdb -+.
|
23
|
+
# Redis implements this internally using a +SYNC+ command.
|
24
|
+
# The operation is analogous to requesting a +BGSAVE+, then having the
|
25
|
+
# dump returned. This mode is capable of dumping data from a local or
|
26
|
+
# remote server. Requires Redis v2.6 or better.
|
10
27
|
#
|
11
|
-
#
|
12
|
-
|
13
|
-
# Default: 'dump'
|
14
|
-
attr_accessor :name
|
28
|
+
# Defaults to +:copy+.
|
29
|
+
attr_accessor :mode
|
15
30
|
|
16
31
|
##
|
17
|
-
#
|
32
|
+
# Full path to the redis dump file.
|
18
33
|
#
|
19
|
-
#
|
20
|
-
attr_accessor :
|
34
|
+
# Required when {#mode} is +:copy+.
|
35
|
+
attr_accessor :rdb_path
|
21
36
|
|
22
37
|
##
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
38
|
+
# Perform a +SAVE+ command using the +redis-cli+ utility
|
39
|
+
# before copying the dump file specified by {#rdb_path}.
|
40
|
+
#
|
41
|
+
# Only valid when {#mode} is +:copy+.
|
42
|
+
attr_accessor :invoke_save
|
26
43
|
|
27
44
|
##
|
28
|
-
# Connectivity options for the +
|
45
|
+
# Connectivity options for the +redis-cli+ utility.
|
29
46
|
attr_accessor :host, :port, :socket
|
30
47
|
|
31
48
|
##
|
32
|
-
#
|
33
|
-
|
34
|
-
# copying the dump file specified by +path+ and +name+.
|
35
|
-
attr_accessor :invoke_save
|
49
|
+
# Password for the +redis-cli+ utility.
|
50
|
+
attr_accessor :password
|
36
51
|
|
37
52
|
##
|
38
|
-
# Additional
|
53
|
+
# Additional options for the +redis-cli+ utility.
|
39
54
|
attr_accessor :additional_options
|
40
55
|
|
41
56
|
def initialize(model, database_id = nil, &block)
|
42
57
|
super
|
43
58
|
instance_eval(&block) if block_given?
|
44
59
|
|
45
|
-
@
|
60
|
+
@mode ||= :copy
|
61
|
+
|
62
|
+
unless MODES.include?(mode)
|
63
|
+
raise Error, "'#{ mode }' is not a valid mode"
|
64
|
+
end
|
65
|
+
|
66
|
+
if mode == :copy && rdb_path.nil?
|
67
|
+
raise Error, '`rdb_path` must be set when `mode` is :copy'
|
68
|
+
end
|
46
69
|
end
|
47
70
|
|
48
71
|
##
|
49
|
-
#
|
50
|
-
# +dump_path+ using the +dump_filename+.
|
72
|
+
# Performs the dump based on {#mode} and stores the Redis dump file
|
73
|
+
# to the +dump_path+ using the +dump_filename+.
|
51
74
|
#
|
52
75
|
# <trigger>/databases/Redis[-<database_id>].rdb[.gz]
|
53
|
-
#
|
54
|
-
# If +invoke_save+ is true, `redis-cli SAVE` will be invoked.
|
55
76
|
def perform!
|
56
77
|
super
|
57
78
|
|
58
|
-
|
59
|
-
|
79
|
+
case mode
|
80
|
+
when :sync
|
81
|
+
# messages output by `redis-cli --rdb` on $stderr
|
82
|
+
Logger.configure do
|
83
|
+
ignore_warning(/Transfer finished with success/)
|
84
|
+
ignore_warning(/SYNC sent to master/)
|
85
|
+
end
|
86
|
+
sync!
|
87
|
+
when :copy
|
88
|
+
save! if invoke_save
|
89
|
+
copy!
|
90
|
+
end
|
60
91
|
|
61
92
|
log!(:finished)
|
62
93
|
end
|
63
94
|
|
64
95
|
private
|
65
96
|
|
66
|
-
def
|
67
|
-
|
97
|
+
def sync!
|
98
|
+
pipeline = Pipeline.new
|
99
|
+
dump_ext = 'rdb'
|
100
|
+
|
101
|
+
pipeline << "#{ redis_cli_cmd } --rdb -"
|
102
|
+
|
103
|
+
model.compressor.compress_with do |command, ext|
|
104
|
+
pipeline << command
|
105
|
+
dump_ext << ext
|
106
|
+
end if model.compressor
|
107
|
+
|
108
|
+
pipeline << "#{ utility(:cat) } > " +
|
109
|
+
"'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"
|
110
|
+
|
111
|
+
pipeline.run
|
112
|
+
|
113
|
+
unless pipeline.success?
|
114
|
+
raise Error, "Dump Failed!\n" + pipeline.error_messages
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def save!
|
119
|
+
resp = run("#{ redis_cli_cmd } SAVE")
|
68
120
|
unless resp =~ /OK$/
|
69
121
|
raise Error, <<-EOS
|
70
|
-
|
71
|
-
Command was: #{ redis_save_cmd }
|
122
|
+
Failed to invoke the `SAVE` command
|
72
123
|
Response was: #{ resp }
|
73
124
|
EOS
|
74
125
|
end
|
@@ -84,27 +135,26 @@ module Backup
|
|
84
135
|
end
|
85
136
|
|
86
137
|
def copy!
|
87
|
-
|
88
|
-
unless File.exist?(src_path)
|
138
|
+
unless File.exist?(rdb_path)
|
89
139
|
raise Error, <<-EOS
|
90
140
|
Redis database dump not found
|
91
|
-
|
141
|
+
`rdb_path` was '#{ rdb_path }'
|
92
142
|
EOS
|
93
143
|
end
|
94
144
|
|
95
145
|
dst_path = File.join(dump_path, dump_filename + '.rdb')
|
96
146
|
if model.compressor
|
97
147
|
model.compressor.compress_with do |command, ext|
|
98
|
-
run("#{ command } -c '#{
|
148
|
+
run("#{ command } -c '#{ rdb_path }' > '#{ dst_path + ext }'")
|
99
149
|
end
|
100
150
|
else
|
101
|
-
FileUtils.cp(
|
151
|
+
FileUtils.cp(rdb_path, dst_path)
|
102
152
|
end
|
103
153
|
end
|
104
154
|
|
105
|
-
def
|
155
|
+
def redis_cli_cmd
|
106
156
|
"#{ utility('redis-cli') } #{ password_option } " +
|
107
|
-
"#{ connectivity_options } #{ user_options }
|
157
|
+
"#{ connectivity_options } #{ user_options }"
|
108
158
|
end
|
109
159
|
|
110
160
|
def password_option
|
@@ -124,18 +174,6 @@ module Backup
|
|
124
174
|
Array(additional_options).join(' ')
|
125
175
|
end
|
126
176
|
|
127
|
-
attr_deprecate :utility_path, :version => '3.0.21',
|
128
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
129
|
-
:action => lambda {|klass, val|
|
130
|
-
Utilities.configure { redis_cli val }
|
131
|
-
}
|
132
|
-
|
133
|
-
attr_deprecate :redis_cli_utility, :version => '3.3.0',
|
134
|
-
:message => 'Use Backup::Utilities.configure instead.',
|
135
|
-
:action => lambda {|klass, val|
|
136
|
-
Utilities.configure { redis_cli val }
|
137
|
-
}
|
138
|
-
|
139
177
|
end
|
140
178
|
end
|
141
179
|
end
|