backup 3.0.20 → 3.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -5
- data/Gemfile.lock +46 -50
- data/README.md +54 -27
- data/lib/backup.rb +16 -39
- data/lib/backup/archive.rb +42 -18
- data/lib/backup/cleaner.rb +110 -25
- data/lib/backup/cli/helpers.rb +17 -32
- data/lib/backup/cli/utility.rb +46 -107
- data/lib/backup/compressor/base.rb +14 -2
- data/lib/backup/compressor/bzip2.rb +10 -24
- data/lib/backup/compressor/gzip.rb +10 -24
- data/lib/backup/compressor/lzma.rb +10 -23
- data/lib/backup/compressor/pbzip2.rb +12 -32
- data/lib/backup/config.rb +171 -0
- data/lib/backup/configuration/compressor/base.rb +1 -2
- data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
- data/lib/backup/configuration/database/base.rb +2 -1
- data/lib/backup/configuration/database/mongodb.rb +8 -0
- data/lib/backup/configuration/database/mysql.rb +4 -0
- data/lib/backup/configuration/database/postgresql.rb +4 -0
- data/lib/backup/configuration/database/redis.rb +4 -0
- data/lib/backup/configuration/database/riak.rb +5 -1
- data/lib/backup/configuration/encryptor/base.rb +1 -2
- data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
- data/lib/backup/configuration/helpers.rb +7 -2
- data/lib/backup/configuration/notifier/base.rb +4 -28
- data/lib/backup/configuration/storage/base.rb +1 -1
- data/lib/backup/configuration/storage/dropbox.rb +14 -4
- data/lib/backup/configuration/syncer/base.rb +10 -0
- data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
- data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
- data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
- data/lib/backup/configuration/syncer/s3.rb +0 -4
- data/lib/backup/database/base.rb +25 -7
- data/lib/backup/database/mongodb.rb +112 -75
- data/lib/backup/database/mysql.rb +54 -29
- data/lib/backup/database/postgresql.rb +60 -42
- data/lib/backup/database/redis.rb +61 -39
- data/lib/backup/database/riak.rb +35 -11
- data/lib/backup/dependency.rb +4 -5
- data/lib/backup/encryptor/base.rb +13 -1
- data/lib/backup/encryptor/gpg.rb +39 -39
- data/lib/backup/encryptor/open_ssl.rb +28 -38
- data/lib/backup/logger.rb +20 -11
- data/lib/backup/model.rb +206 -163
- data/lib/backup/notifier/base.rb +27 -25
- data/lib/backup/notifier/campfire.rb +7 -13
- data/lib/backup/notifier/hipchat.rb +28 -28
- data/lib/backup/notifier/mail.rb +24 -26
- data/lib/backup/notifier/presently.rb +10 -18
- data/lib/backup/notifier/prowl.rb +9 -17
- data/lib/backup/notifier/twitter.rb +11 -18
- data/lib/backup/package.rb +47 -0
- data/lib/backup/packager.rb +81 -16
- data/lib/backup/splitter.rb +48 -35
- data/lib/backup/storage/base.rb +44 -172
- data/lib/backup/storage/cloudfiles.rb +31 -46
- data/lib/backup/storage/cycler.rb +117 -0
- data/lib/backup/storage/dropbox.rb +92 -76
- data/lib/backup/storage/ftp.rb +30 -40
- data/lib/backup/storage/local.rb +44 -45
- data/lib/backup/storage/ninefold.rb +55 -49
- data/lib/backup/storage/rsync.rb +49 -56
- data/lib/backup/storage/s3.rb +33 -44
- data/lib/backup/storage/scp.rb +21 -48
- data/lib/backup/storage/sftp.rb +26 -40
- data/lib/backup/syncer/base.rb +7 -0
- data/lib/backup/syncer/rsync/base.rb +78 -0
- data/lib/backup/syncer/rsync/local.rb +53 -0
- data/lib/backup/syncer/rsync/pull.rb +38 -0
- data/lib/backup/syncer/rsync/push.rb +113 -0
- data/lib/backup/syncer/s3.rb +42 -32
- data/lib/backup/version.rb +1 -1
- data/spec/archive_spec.rb +235 -69
- data/spec/cleaner_spec.rb +304 -0
- data/spec/cli/helpers_spec.rb +142 -1
- data/spec/cli/utility_spec.rb +338 -13
- data/spec/compressor/base_spec.rb +31 -0
- data/spec/compressor/bzip2_spec.rb +60 -35
- data/spec/compressor/gzip_spec.rb +60 -35
- data/spec/compressor/lzma_spec.rb +60 -35
- data/spec/compressor/pbzip2_spec.rb +98 -37
- data/spec/config_spec.rb +321 -0
- data/spec/configuration/base_spec.rb +4 -4
- data/spec/configuration/compressor/bzip2_spec.rb +1 -0
- data/spec/configuration/compressor/gzip_spec.rb +1 -0
- data/spec/configuration/compressor/lzma_spec.rb +1 -0
- data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
- data/spec/configuration/database/base_spec.rb +2 -1
- data/spec/configuration/database/mongodb_spec.rb +26 -16
- data/spec/configuration/database/mysql_spec.rb +4 -0
- data/spec/configuration/database/postgresql_spec.rb +4 -0
- data/spec/configuration/database/redis_spec.rb +4 -0
- data/spec/configuration/database/riak_spec.rb +4 -0
- data/spec/configuration/encryptor/gpg_spec.rb +1 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
- data/spec/configuration/notifier/base_spec.rb +32 -0
- data/spec/configuration/notifier/campfire_spec.rb +1 -0
- data/spec/configuration/notifier/hipchat_spec.rb +1 -0
- data/spec/configuration/notifier/mail_spec.rb +1 -0
- data/spec/configuration/notifier/presently_spec.rb +1 -0
- data/spec/configuration/notifier/prowl_spec.rb +1 -0
- data/spec/configuration/notifier/twitter_spec.rb +1 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
- data/spec/configuration/storage/dropbox_spec.rb +4 -3
- data/spec/configuration/storage/ftp_spec.rb +1 -0
- data/spec/configuration/storage/local_spec.rb +1 -0
- data/spec/configuration/storage/ninefold_spec.rb +1 -0
- data/spec/configuration/storage/rsync_spec.rb +3 -1
- data/spec/configuration/storage/s3_spec.rb +1 -0
- data/spec/configuration/storage/scp_spec.rb +1 -0
- data/spec/configuration/storage/sftp_spec.rb +1 -0
- data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
- data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
- data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
- data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
- data/spec/configuration/syncer/s3_spec.rb +2 -3
- data/spec/database/base_spec.rb +35 -20
- data/spec/database/mongodb_spec.rb +298 -119
- data/spec/database/mysql_spec.rb +147 -72
- data/spec/database/postgresql_spec.rb +155 -100
- data/spec/database/redis_spec.rb +200 -97
- data/spec/database/riak_spec.rb +82 -24
- data/spec/dependency_spec.rb +49 -0
- data/spec/encryptor/base_spec.rb +30 -0
- data/spec/encryptor/gpg_spec.rb +105 -28
- data/spec/encryptor/open_ssl_spec.rb +85 -114
- data/spec/logger_spec.rb +74 -8
- data/spec/model_spec.rb +528 -220
- data/spec/notifier/base_spec.rb +89 -0
- data/spec/notifier/campfire_spec.rb +147 -119
- data/spec/notifier/hipchat_spec.rb +140 -145
- data/spec/notifier/mail_spec.rb +190 -248
- data/spec/notifier/presently_spec.rb +147 -282
- data/spec/notifier/prowl_spec.rb +79 -111
- data/spec/notifier/twitter_spec.rb +87 -106
- data/spec/package_spec.rb +61 -0
- data/spec/packager_spec.rb +154 -0
- data/spec/spec_helper.rb +36 -13
- data/spec/splitter_spec.rb +90 -41
- data/spec/storage/base_spec.rb +95 -239
- data/spec/storage/cloudfiles_spec.rb +185 -75
- data/spec/storage/cycler_spec.rb +239 -0
- data/spec/storage/dropbox_spec.rb +318 -87
- data/spec/storage/ftp_spec.rb +165 -152
- data/spec/storage/local_spec.rb +206 -54
- data/spec/storage/ninefold_spec.rb +264 -128
- data/spec/storage/rsync_spec.rb +244 -163
- data/spec/storage/s3_spec.rb +175 -64
- data/spec/storage/scp_spec.rb +156 -150
- data/spec/storage/sftp_spec.rb +153 -135
- data/spec/syncer/base_spec.rb +22 -0
- data/spec/syncer/rsync/base_spec.rb +118 -0
- data/spec/syncer/rsync/local_spec.rb +121 -0
- data/spec/syncer/rsync/pull_spec.rb +90 -0
- data/spec/syncer/rsync/push_spec.rb +327 -0
- data/spec/syncer/s3_spec.rb +180 -91
- data/templates/cli/utility/config +1 -1
- data/templates/cli/utility/database/mongodb +4 -0
- data/templates/cli/utility/database/mysql +3 -0
- data/templates/cli/utility/database/postgresql +3 -0
- data/templates/cli/utility/database/redis +3 -0
- data/templates/cli/utility/database/riak +3 -0
- data/templates/cli/utility/storage/dropbox +4 -1
- data/templates/cli/utility/syncer/rsync_local +12 -0
- data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
- data/templates/cli/utility/syncer/rsync_push +17 -0
- data/templates/storage/dropbox/authorization_url.erb +1 -1
- metadata +42 -17
- data/lib/backup/configuration/syncer/rsync.rb +0 -45
- data/lib/backup/finder.rb +0 -87
- data/lib/backup/storage/object.rb +0 -47
- data/lib/backup/syncer/rsync.rb +0 -152
- data/spec/backup_spec.rb +0 -11
- data/spec/finder_spec.rb +0 -91
- data/spec/storage/object_spec.rb +0 -74
- data/spec/syncer/rsync_spec.rb +0 -195
@@ -28,32 +28,57 @@ module Backup
|
|
28
28
|
# Additional "mysqldump" options
|
29
29
|
attr_accessor :additional_options
|
30
30
|
|
31
|
+
##
|
32
|
+
# Path to mysqldump utility (optional)
|
33
|
+
attr_accessor :mysqldump_utility
|
34
|
+
|
31
35
|
##
|
32
36
|
# Creates a new instance of the MySQL adapter object
|
33
|
-
def initialize(&block)
|
34
|
-
|
37
|
+
def initialize(model, &block)
|
38
|
+
super(model)
|
35
39
|
|
36
40
|
@skip_tables ||= Array.new
|
37
41
|
@only_tables ||= Array.new
|
38
42
|
@additional_options ||= Array.new
|
39
43
|
|
40
|
-
instance_eval(&block)
|
44
|
+
instance_eval(&block) if block_given?
|
45
|
+
|
46
|
+
if @utility_path
|
47
|
+
Logger.warn "[DEPRECATED] " +
|
48
|
+
"Database::MySQL#utility_path has been deprecated.\n" +
|
49
|
+
" Use Database::MySQL#mysqldump_utility instead."
|
50
|
+
@mysqldump_utility ||= @utility_path
|
51
|
+
end
|
52
|
+
@mysqldump_utility ||= utility(:mysqldump)
|
41
53
|
end
|
42
54
|
|
43
55
|
##
|
44
|
-
#
|
45
|
-
#
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
# Performs the mysqldump command and outputs the
|
57
|
+
# data to the specified path based on the 'trigger'
|
58
|
+
def perform!
|
59
|
+
super
|
60
|
+
|
61
|
+
dump_ext = 'sql'
|
62
|
+
dump_cmd = "#{ mysqldump }"
|
63
|
+
|
64
|
+
if @model.compressor
|
65
|
+
@model.compressor.compress_with do |command, ext|
|
66
|
+
dump_cmd << " | #{command}"
|
67
|
+
dump_ext << ext
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
dump_cmd << " > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"
|
72
|
+
run(dump_cmd)
|
50
73
|
end
|
51
74
|
|
75
|
+
private
|
76
|
+
|
52
77
|
##
|
53
|
-
# Builds the
|
54
|
-
|
55
|
-
|
56
|
-
|
78
|
+
# Builds the full mysqldump string based on all attributes
|
79
|
+
def mysqldump
|
80
|
+
"#{ mysqldump_utility } #{ credential_options } #{ connectivity_options } " +
|
81
|
+
"#{ user_options } #{ name } #{ tables_to_dump } #{ tables_to_skip }"
|
57
82
|
end
|
58
83
|
|
59
84
|
##
|
@@ -61,9 +86,9 @@ module Backup
|
|
61
86
|
# to perform the database dumping process
|
62
87
|
def credential_options
|
63
88
|
%w[username password].map do |option|
|
64
|
-
next if send(option).
|
89
|
+
next if send(option).to_s.empty?
|
65
90
|
"--#{option}='#{send(option)}'".gsub('--username', '--user')
|
66
|
-
end.compact.join(
|
91
|
+
end.compact.join(' ')
|
67
92
|
end
|
68
93
|
|
69
94
|
##
|
@@ -71,32 +96,32 @@ module Backup
|
|
71
96
|
# to perform the database dumping process
|
72
97
|
def connectivity_options
|
73
98
|
%w[host port socket].map do |option|
|
74
|
-
next if send(option).
|
99
|
+
next if send(option).to_s.empty?
|
75
100
|
"--#{option}='#{send(option)}'"
|
76
|
-
end.compact.join(
|
101
|
+
end.compact.join(' ')
|
77
102
|
end
|
78
103
|
|
79
104
|
##
|
80
105
|
# Builds a MySQL compatible string for the additional options
|
81
106
|
# specified by the user
|
82
|
-
def
|
83
|
-
additional_options.join(
|
107
|
+
def user_options
|
108
|
+
additional_options.join(' ')
|
84
109
|
end
|
85
110
|
|
86
111
|
##
|
87
|
-
# Builds the
|
88
|
-
|
89
|
-
|
90
|
-
|
112
|
+
# Builds the MySQL syntax for specifying which tables to dump
|
113
|
+
# during the dumping of the database
|
114
|
+
def tables_to_dump
|
115
|
+
only_tables.join(' ')
|
91
116
|
end
|
92
117
|
|
93
118
|
##
|
94
|
-
#
|
95
|
-
#
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
119
|
+
# Builds the MySQL syntax for specifying which tables to skip
|
120
|
+
# during the dumping of the database
|
121
|
+
def tables_to_skip
|
122
|
+
skip_tables.map do |table|
|
123
|
+
"--ignore-table='#{name}.#{table}'"
|
124
|
+
end.join(' ')
|
100
125
|
end
|
101
126
|
|
102
127
|
end
|
@@ -28,53 +28,72 @@ module Backup
|
|
28
28
|
# Additional "pg_dump" options
|
29
29
|
attr_accessor :additional_options
|
30
30
|
|
31
|
+
##
|
32
|
+
# Path to pg_dump utility (optional)
|
33
|
+
attr_accessor :pg_dump_utility
|
34
|
+
|
31
35
|
##
|
32
36
|
# Creates a new instance of the PostgreSQL adapter object
|
33
37
|
# Sets the PGPASSWORD environment variable to the password
|
34
38
|
# so it doesn't prompt and hang in the process
|
35
|
-
def initialize(&block)
|
36
|
-
|
39
|
+
def initialize(model, &block)
|
40
|
+
super(model)
|
37
41
|
|
38
42
|
@skip_tables ||= Array.new
|
39
43
|
@only_tables ||= Array.new
|
40
44
|
@additional_options ||= Array.new
|
41
45
|
|
42
|
-
instance_eval(&block)
|
43
|
-
ENV['PGPASSWORD'] = password
|
44
|
-
end
|
46
|
+
instance_eval(&block) if block_given?
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
if @utility_path
|
49
|
+
Logger.warn "[DEPRECATED] " +
|
50
|
+
"Database::PostgreSQL#utility_path has been deprecated.\n" +
|
51
|
+
" Use Database::PostgreSQL#pg_dump_utility instead."
|
52
|
+
@pg_dump_utility ||= @utility_path
|
53
|
+
end
|
54
|
+
@pg_dump_utility ||= utility(:pg_dump)
|
53
55
|
end
|
54
56
|
|
55
57
|
##
|
56
|
-
#
|
57
|
-
#
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
# Performs the pgdump command and outputs the
|
59
|
+
# data to the specified path based on the 'trigger'
|
60
|
+
def perform!
|
61
|
+
super
|
62
|
+
|
63
|
+
dump_ext = 'sql'
|
64
|
+
dump_cmd = "#{ pgdump }"
|
65
|
+
|
66
|
+
if @model.compressor
|
67
|
+
@model.compressor.compress_with do |command, ext|
|
68
|
+
dump_cmd << " | #{command}"
|
69
|
+
dump_ext << ext
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
dump_cmd << " > '#{ File.join(@dump_path, name) }.#{ dump_ext }'"
|
74
|
+
run(dump_cmd)
|
62
75
|
end
|
63
76
|
|
64
77
|
##
|
65
|
-
# Builds the
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
"
|
78
|
+
# Builds the full pgdump string based on all attributes
|
79
|
+
def pgdump
|
80
|
+
"#{password_options}" +
|
81
|
+
"#{ pg_dump_utility } #{ username_options } #{ connectivity_options } " +
|
82
|
+
"#{ user_options } #{ tables_to_dump } #{ tables_to_skip } #{ name }"
|
70
83
|
end
|
71
84
|
|
72
85
|
##
|
73
86
|
# Builds the password syntax PostgreSQL uses to authenticate the user
|
74
87
|
# to perform database dumping
|
75
88
|
def password_options
|
76
|
-
|
77
|
-
|
89
|
+
password.to_s.empty? ? '' : "PGPASSWORD='#{password}' "
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Builds the credentials PostgreSQL syntax to authenticate the user
|
94
|
+
# to perform the database dumping process
|
95
|
+
def username_options
|
96
|
+
username.to_s.empty? ? '' : "--username='#{username}'"
|
78
97
|
end
|
79
98
|
|
80
99
|
##
|
@@ -84,35 +103,34 @@ module Backup
|
|
84
103
|
# both the host and the socket are specified, the socket will take priority over the host
|
85
104
|
def connectivity_options
|
86
105
|
%w[host port socket].map do |option|
|
87
|
-
next if send(option).
|
106
|
+
next if send(option).to_s.empty?
|
88
107
|
"--#{option}='#{send(option)}'".gsub('--socket=', '--host=')
|
89
|
-
end.compact.join(
|
108
|
+
end.compact.join(' ')
|
90
109
|
end
|
91
110
|
|
92
111
|
##
|
93
112
|
# Builds a PostgreSQL compatible string for the additional options
|
94
113
|
# specified by the user
|
95
|
-
def
|
96
|
-
additional_options.join(
|
114
|
+
def user_options
|
115
|
+
additional_options.join(' ')
|
97
116
|
end
|
98
117
|
|
99
118
|
##
|
100
|
-
# Builds the
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
119
|
+
# Builds the PostgreSQL syntax for specifying which tables to dump
|
120
|
+
# during the dumping of the database
|
121
|
+
def tables_to_dump
|
122
|
+
only_tables.map do |table|
|
123
|
+
"--table='#{table}'"
|
124
|
+
end.join(' ')
|
105
125
|
end
|
106
126
|
|
107
127
|
##
|
108
|
-
#
|
109
|
-
#
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
run("#{pgdump} > '#{File.join(dump_path, name)}.sql'")
|
115
|
-
ENV['PGPASSWORD'] = nil
|
128
|
+
# Builds the PostgreSQL syntax for specifying which tables to skip
|
129
|
+
# during the dumping of the database
|
130
|
+
def tables_to_skip
|
131
|
+
skip_tables.map do |table|
|
132
|
+
"--exclude-table='#{table}'"
|
133
|
+
end.join(' ')
|
116
134
|
end
|
117
135
|
|
118
136
|
end
|
@@ -26,43 +26,28 @@ module Backup
|
|
26
26
|
# Additional "redis-cli" options
|
27
27
|
attr_accessor :additional_options
|
28
28
|
|
29
|
+
##
|
30
|
+
# Path to the redis-cli utility (optional)
|
31
|
+
attr_accessor :redis_cli_utility
|
32
|
+
|
29
33
|
##
|
30
34
|
# Creates a new instance of the Redis database object
|
31
|
-
def initialize(&block)
|
32
|
-
|
35
|
+
def initialize(model, &block)
|
36
|
+
super(model)
|
33
37
|
|
34
38
|
@additional_options ||= Array.new
|
35
39
|
|
36
|
-
instance_eval(&block)
|
37
|
-
end
|
38
|
-
|
39
|
-
##
|
40
|
-
# Builds the Redis credentials syntax to authenticate the user
|
41
|
-
# to perform the database dumping process
|
42
|
-
def credential_options
|
43
|
-
return "-a '#{password}'" if password; String.new
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# Builds the Redis connectivity options syntax to connect the user
|
48
|
-
# to perform the database dumping process
|
49
|
-
def connectivity_options
|
50
|
-
%w[host port socket].map do |option|
|
51
|
-
next if send(option).nil?; "-#{option[0,1]} '#{send(option)}'"
|
52
|
-
end.compact.join("\s")
|
53
|
-
end
|
40
|
+
instance_eval(&block) if block_given?
|
54
41
|
|
55
|
-
|
56
|
-
# Builds a Redis compatible string for the
|
57
|
-
# additional options specified by the user
|
58
|
-
def additional_options
|
59
|
-
@additional_options.join("\s")
|
60
|
-
end
|
42
|
+
@name ||= 'dump'
|
61
43
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
44
|
+
if @utility_path
|
45
|
+
Logger.warn "[DEPRECATED] " +
|
46
|
+
"Database::Redis#utility_path has been deprecated.\n" +
|
47
|
+
" Use Database::Redis#redis_cli_utility instead."
|
48
|
+
@redis_cli_utility ||= @utility_path
|
49
|
+
end
|
50
|
+
@redis_cli_utility ||= utility('redis-cli')
|
66
51
|
end
|
67
52
|
|
68
53
|
##
|
@@ -78,12 +63,14 @@ module Backup
|
|
78
63
|
copy!
|
79
64
|
end
|
80
65
|
|
66
|
+
private
|
67
|
+
|
81
68
|
##
|
82
69
|
# Tells Redis to persist the current state of the
|
83
70
|
# in-memory database to the persisted dump file
|
84
71
|
def invoke_save!
|
85
|
-
response = run("#{
|
86
|
-
"#{ connectivity_options } #{
|
72
|
+
response = run("#{ redis_cli_utility } #{ credential_options } " +
|
73
|
+
"#{ connectivity_options } #{ user_options } SAVE")
|
87
74
|
unless response =~ /OK/
|
88
75
|
raise Errors::Database::Redis::CommandError, <<-EOS
|
89
76
|
Could not invoke the Redis SAVE command.
|
@@ -99,19 +86,54 @@ module Backup
|
|
99
86
|
##
|
100
87
|
# Performs the copy command to copy over the Redis dump file to the Backup archive
|
101
88
|
def copy!
|
102
|
-
|
89
|
+
src_path = File.join(path, database)
|
90
|
+
unless File.exist?(src_path)
|
103
91
|
raise Errors::Database::Redis::NotFoundError, <<-EOS
|
104
92
|
Redis database dump not found
|
105
|
-
File path was #{
|
93
|
+
File path was #{ src_path }
|
106
94
|
EOS
|
107
95
|
end
|
108
96
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
97
|
+
dst_path = File.join(@dump_path, database)
|
98
|
+
if @model.compressor
|
99
|
+
@model.compressor.compress_with do |command, ext|
|
100
|
+
run("#{ command } -c #{ src_path } > #{ dst_path + ext }")
|
101
|
+
end
|
102
|
+
else
|
103
|
+
FileUtils.cp(src_path, dst_path)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Returns the Redis database file name
|
109
|
+
def database
|
110
|
+
"#{ name }.rdb"
|
111
|
+
end
|
112
|
+
|
113
|
+
##
|
114
|
+
# Builds the Redis credentials syntax to authenticate the user
|
115
|
+
# to perform the database dumping process
|
116
|
+
def credential_options
|
117
|
+
password.to_s.empty? ? '' : "-a '#{password}'"
|
114
118
|
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Builds the Redis connectivity options syntax to connect the user
|
122
|
+
# to perform the database dumping process
|
123
|
+
def connectivity_options
|
124
|
+
%w[host port socket].map do |option|
|
125
|
+
next if send(option).to_s.empty?
|
126
|
+
"-#{option[0,1]} '#{send(option)}'"
|
127
|
+
end.compact.join(' ')
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Builds a Redis compatible string for the
|
132
|
+
# additional options specified by the user
|
133
|
+
def user_options
|
134
|
+
@additional_options.join(' ')
|
135
|
+
end
|
136
|
+
|
115
137
|
end
|
116
138
|
end
|
117
139
|
end
|
data/lib/backup/database/riak.rb
CHANGED
@@ -16,18 +16,24 @@ module Backup
|
|
16
16
|
# Cookie is the Erlang cookie/shared secret used to connect to the node.
|
17
17
|
attr_accessor :cookie
|
18
18
|
|
19
|
+
##
|
20
|
+
# Path to riak-admin utility (optional)
|
21
|
+
attr_accessor :riak_admin_utility
|
22
|
+
|
19
23
|
##
|
20
24
|
# Creates a new instance of the Riak adapter object
|
21
|
-
def initialize(&block)
|
22
|
-
|
25
|
+
def initialize(model, &block)
|
26
|
+
super(model)
|
23
27
|
|
24
|
-
instance_eval(&block)
|
25
|
-
end
|
28
|
+
instance_eval(&block) if block_given?
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
if @utility_path
|
31
|
+
Logger.warn "[DEPRECATED] " +
|
32
|
+
"Database::Riak#utility_path has been deprecated.\n" +
|
33
|
+
" Use Database::Riak#riak_admin_utility instead."
|
34
|
+
@riak_admin_utility ||= @utility_path
|
35
|
+
end
|
36
|
+
@riak_admin_utility ||= utility('riak-admin')
|
31
37
|
end
|
32
38
|
|
33
39
|
##
|
@@ -35,9 +41,27 @@ module Backup
|
|
35
41
|
# data to the specified path based on the 'trigger'
|
36
42
|
def perform!
|
37
43
|
super
|
38
|
-
# have to make riak the owner since the riak-admin tool runs
|
39
|
-
|
40
|
-
|
44
|
+
# have to make riak the owner since the riak-admin tool runs
|
45
|
+
# as the riak user in a default setup.
|
46
|
+
FileUtils.chown_R('riak', 'riak', @dump_path)
|
47
|
+
|
48
|
+
backup_file = File.join(@dump_path, name)
|
49
|
+
run("#{ riakadmin } #{ backup_file } node")
|
50
|
+
|
51
|
+
if @model.compressor
|
52
|
+
@model.compressor.compress_with do |command, ext|
|
53
|
+
run("#{ command } -c #{ backup_file } > #{ backup_file + ext }")
|
54
|
+
FileUtils.rm_f(backup_file)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
##
|
62
|
+
# Builds the full riak-admin string based on all attributes
|
63
|
+
def riakadmin
|
64
|
+
"#{ riak_admin_utility } backup #{ node } #{ cookie }"
|
41
65
|
end
|
42
66
|
|
43
67
|
end
|