backup-ssh 4.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +24 -0
- data/README.md +25 -0
- data/bin/backup +5 -0
- data/lib/backup.rb +141 -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 +186 -0
- data/lib/backup/database/mysql.rb +200 -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 +454 -0
- data/lib/backup/notifier/base.rb +98 -0
- data/lib/backup/notifier/campfire.rb +69 -0
- data/lib/backup/notifier/datadog.rb +116 -0
- data/lib/backup/notifier/flowdock.rb +102 -0
- data/lib/backup/notifier/hipchat.rb +93 -0
- data/lib/backup/notifier/http_post.rb +122 -0
- data/lib/backup/notifier/mail.rb +238 -0
- data/lib/backup/notifier/nagios.rb +74 -0
- data/lib/backup/notifier/pagerduty.rb +81 -0
- data/lib/backup/notifier/prowl.rb +69 -0
- data/lib/backup/notifier/pushover.rb +80 -0
- data/lib/backup/notifier/ses.rb +94 -0
- data/lib/backup/notifier/slack.rb +154 -0
- data/lib/backup/notifier/twitter.rb +64 -0
- data/lib/backup/notifier/zabbix.rb +68 -0
- data/lib/backup/package.rb +51 -0
- data/lib/backup/packager.rb +101 -0
- data/lib/backup/pipeline.rb +124 -0
- data/lib/backup/splitter.rb +76 -0
- data/lib/backup/storage/base.rb +57 -0
- data/lib/backup/storage/cloud_files.rb +158 -0
- data/lib/backup/storage/cycler.rb +65 -0
- data/lib/backup/storage/dropbox.rb +236 -0
- data/lib/backup/storage/ftp.rb +98 -0
- data/lib/backup/storage/local.rb +64 -0
- data/lib/backup/storage/ninefold.rb +74 -0
- data/lib/backup/storage/rsync.rb +248 -0
- data/lib/backup/storage/s3.rb +155 -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 +48 -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/datadog +57 -0
- data/templates/cli/notifiers/flowdock +16 -0
- data/templates/cli/notifiers/hipchat +15 -0
- data/templates/cli/notifiers/http_post +32 -0
- data/templates/cli/notifiers/mail +21 -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 +19 -0
- data/templates/cli/storages/ftp +12 -0
- data/templates/cli/storages/local +7 -0
- data/templates/cli/storages/ninefold +9 -0
- data/templates/cli/storages/rsync +17 -0
- data/templates/cli/storages/s3 +14 -0
- data/templates/cli/storages/scp +14 -0
- data/templates/cli/storages/sftp +14 -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 +1057 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Database
|
5
|
+
class MongoDB < Base
|
6
|
+
class Error < Backup::Error; end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Name of the database that needs to get dumped
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
##
|
13
|
+
# Credentials for the specified database
|
14
|
+
attr_accessor :username, :password
|
15
|
+
|
16
|
+
##
|
17
|
+
# Connectivity options
|
18
|
+
attr_accessor :host, :port
|
19
|
+
|
20
|
+
##
|
21
|
+
# IPv6 support (disabled by default)
|
22
|
+
attr_accessor :ipv6
|
23
|
+
|
24
|
+
##
|
25
|
+
# Collections to dump, collections that aren't specified won't get dumped
|
26
|
+
attr_accessor :only_collections
|
27
|
+
|
28
|
+
##
|
29
|
+
# Additional "mongodump" options
|
30
|
+
attr_accessor :additional_options
|
31
|
+
|
32
|
+
##
|
33
|
+
# Forces mongod to flush all pending write operations to the disk and
|
34
|
+
# locks the entire mongod instance to prevent additional writes until the
|
35
|
+
# dump is complete.
|
36
|
+
#
|
37
|
+
# Note that if Profiling is enabled, this will disable it and will not
|
38
|
+
# re-enable it after the dump is complete.
|
39
|
+
attr_accessor :lock
|
40
|
+
|
41
|
+
##
|
42
|
+
# Creates a dump of the database that includes an oplog, to create a
|
43
|
+
# point-in-time snapshot of the state of a mongod instance.
|
44
|
+
#
|
45
|
+
# If this option is used, you would not use the `lock` option.
|
46
|
+
#
|
47
|
+
# This will only work against nodes that maintain a oplog.
|
48
|
+
# This includes all members of a replica set, as well as master nodes in
|
49
|
+
# master/slave replication deployments.
|
50
|
+
attr_accessor :oplog
|
51
|
+
|
52
|
+
def initialize(model, database_id = nil, &block)
|
53
|
+
super
|
54
|
+
instance_eval(&block) if block_given?
|
55
|
+
end
|
56
|
+
|
57
|
+
def perform!
|
58
|
+
super
|
59
|
+
|
60
|
+
lock_database if @lock
|
61
|
+
dump!
|
62
|
+
package!
|
63
|
+
|
64
|
+
ensure
|
65
|
+
unlock_database if @lock
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
##
|
71
|
+
# Performs all required mongodump commands, dumping the output files
|
72
|
+
# into the +dump_packaging_path+ directory for packaging.
|
73
|
+
def dump!
|
74
|
+
FileUtils.mkdir_p dump_packaging_path
|
75
|
+
|
76
|
+
collections = Array(only_collections)
|
77
|
+
if collections.empty?
|
78
|
+
run(mongodump)
|
79
|
+
else
|
80
|
+
collections.each do |collection|
|
81
|
+
run("#{ mongodump } --collection='#{ collection }'")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Creates a tar archive of the +dump_packaging_path+ directory
|
88
|
+
# and stores it in the +dump_path+ using +dump_filename+.
|
89
|
+
#
|
90
|
+
# <trigger>/databases/MongoDB[-<database_id>].tar[.gz]
|
91
|
+
#
|
92
|
+
# If successful, +dump_packaging_path+ is removed.
|
93
|
+
def package!
|
94
|
+
pipeline = Pipeline.new
|
95
|
+
dump_ext = 'tar'
|
96
|
+
|
97
|
+
pipeline << "#{ utility(:tar) } -cf - " +
|
98
|
+
"-C '#{ dump_path }' '#{ dump_filename }'"
|
99
|
+
|
100
|
+
model.compressor.compress_with do |command, ext|
|
101
|
+
pipeline << command
|
102
|
+
dump_ext << ext
|
103
|
+
end if model.compressor
|
104
|
+
|
105
|
+
pipeline << "#{ utility(:cat) } > " +
|
106
|
+
"'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"
|
107
|
+
|
108
|
+
pipeline.run
|
109
|
+
if pipeline.success?
|
110
|
+
FileUtils.rm_rf dump_packaging_path
|
111
|
+
log!(:finished)
|
112
|
+
else
|
113
|
+
raise Error, "Dump Failed!\n" + pipeline.error_messages
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def dump_packaging_path
|
118
|
+
File.join(dump_path, dump_filename)
|
119
|
+
end
|
120
|
+
|
121
|
+
def mongodump
|
122
|
+
"#{ utility(:mongodump) } #{ name_option } #{ credential_options } " +
|
123
|
+
"#{ connectivity_options } #{ ipv6_option } #{ oplog_option } " +
|
124
|
+
"#{ user_options } --out='#{ dump_packaging_path }'"
|
125
|
+
end
|
126
|
+
|
127
|
+
def name_option
|
128
|
+
"--db='#{ name }'" if name
|
129
|
+
end
|
130
|
+
|
131
|
+
def credential_options
|
132
|
+
opts = []
|
133
|
+
opts << "--username='#{ username }'" if username
|
134
|
+
opts << "--password='#{ password }'" if password
|
135
|
+
opts.join(' ')
|
136
|
+
end
|
137
|
+
|
138
|
+
def connectivity_options
|
139
|
+
opts = []
|
140
|
+
opts << "--host='#{ host }'" if host
|
141
|
+
opts << "--port='#{ port }'" if port
|
142
|
+
opts.join(' ')
|
143
|
+
end
|
144
|
+
|
145
|
+
def ipv6_option
|
146
|
+
'--ipv6' if ipv6
|
147
|
+
end
|
148
|
+
|
149
|
+
def oplog_option
|
150
|
+
'--oplog' if oplog
|
151
|
+
end
|
152
|
+
|
153
|
+
def user_options
|
154
|
+
Array(additional_options).join(' ')
|
155
|
+
end
|
156
|
+
|
157
|
+
def lock_database
|
158
|
+
lock_command = <<-EOS.gsub(/^ +/, '')
|
159
|
+
echo 'use admin
|
160
|
+
db.setProfilingLevel(0)
|
161
|
+
db.fsyncLock()' | #{ mongo_shell }
|
162
|
+
EOS
|
163
|
+
|
164
|
+
run(lock_command)
|
165
|
+
end
|
166
|
+
|
167
|
+
def unlock_database
|
168
|
+
unlock_command = <<-EOS.gsub(/^ +/, '')
|
169
|
+
echo 'use admin
|
170
|
+
db.fsyncUnlock()' | #{ mongo_shell }
|
171
|
+
EOS
|
172
|
+
|
173
|
+
run(unlock_command)
|
174
|
+
end
|
175
|
+
|
176
|
+
def mongo_shell
|
177
|
+
cmd = "#{ utility(:mongo) } #{ connectivity_options }".rstrip
|
178
|
+
cmd << " #{ credential_options }".rstrip
|
179
|
+
cmd << " #{ ipv6_option }".rstrip
|
180
|
+
cmd << " '#{ name }'" if name
|
181
|
+
cmd
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Database
|
5
|
+
class MySQL < Base
|
6
|
+
class Error < Backup::Error; end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Name of the database that needs to get dumped
|
10
|
+
# To dump all databases, set this to `:all` or leave blank.
|
11
|
+
attr_accessor :name
|
12
|
+
|
13
|
+
##
|
14
|
+
# Credentials for the specified database
|
15
|
+
attr_accessor :username, :password
|
16
|
+
|
17
|
+
##
|
18
|
+
# SSH option
|
19
|
+
attr_accessor :ssh
|
20
|
+
|
21
|
+
##
|
22
|
+
# Connectivity options
|
23
|
+
attr_accessor :host, :port, :socket
|
24
|
+
|
25
|
+
##
|
26
|
+
# Tables to skip while dumping the database
|
27
|
+
#
|
28
|
+
# If `name` is set to :all (or not specified), these must include
|
29
|
+
# a database name. e.g. 'name.table'.
|
30
|
+
# If `name` is given, these may simply be table names.
|
31
|
+
attr_accessor :skip_tables
|
32
|
+
|
33
|
+
##
|
34
|
+
# Tables to dump. This in only valid if `name` is specified.
|
35
|
+
# If none are given, the entire database will be dumped.
|
36
|
+
attr_accessor :only_tables
|
37
|
+
|
38
|
+
##
|
39
|
+
# Additional "mysqldump" or "innobackupex (backup creation)" options
|
40
|
+
attr_accessor :additional_options
|
41
|
+
|
42
|
+
##
|
43
|
+
# Additional innobackupex log preparation phase ("apply-logs") options
|
44
|
+
attr_accessor :prepare_options
|
45
|
+
|
46
|
+
##
|
47
|
+
# Default is :mysqldump (which is built in MySQL and generates
|
48
|
+
# a textual SQL file), but can be changed to :innobackupex, which
|
49
|
+
# has more feasible restore times for large databases.
|
50
|
+
# See: http://www.percona.com/doc/percona-xtrabackup/
|
51
|
+
attr_accessor :backup_engine
|
52
|
+
|
53
|
+
##
|
54
|
+
# If true (which is the default behaviour), the backup will be prepared
|
55
|
+
# after it has been successfuly created. This option is only valid if
|
56
|
+
# :backup_engine is set to :innobackupex.
|
57
|
+
attr_accessor :prepare_backup
|
58
|
+
|
59
|
+
##
|
60
|
+
# If set the backup engine command block is executed as the given user
|
61
|
+
attr_accessor :sudo_user
|
62
|
+
|
63
|
+
##
|
64
|
+
# If set, do not suppress innobackupdb output (useful for debugging)
|
65
|
+
attr_accessor :verbose
|
66
|
+
|
67
|
+
def initialize(model, database_id = nil, &block)
|
68
|
+
super
|
69
|
+
instance_eval(&block) if block_given?
|
70
|
+
|
71
|
+
@name ||= :all
|
72
|
+
@backup_engine ||= :mysqldump
|
73
|
+
@prepare_backup = true if @prepare_backup.nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Performs the mysqldump or innobackupex command and outputs
|
78
|
+
# the dump file in the +dump_path+ using +dump_filename+.
|
79
|
+
#
|
80
|
+
# <trigger>/databases/MySQL[-<database_id>].[sql|tar][.gz]
|
81
|
+
def perform!
|
82
|
+
super
|
83
|
+
|
84
|
+
pipeline = Pipeline.new
|
85
|
+
dump_ext = sql_backup? ? 'sql' : 'tar'
|
86
|
+
|
87
|
+
pipeline << sudo_option(sql_backup? ? mysqldump : innobackupex)
|
88
|
+
|
89
|
+
model.compressor.compress_with do |command, ext|
|
90
|
+
pipeline << command
|
91
|
+
dump_ext << ext
|
92
|
+
end if model.compressor
|
93
|
+
|
94
|
+
pipeline << "#{ utility(:cat) } > " +
|
95
|
+
"'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"
|
96
|
+
|
97
|
+
pipeline.run
|
98
|
+
if pipeline.success?
|
99
|
+
log!(:finished)
|
100
|
+
else
|
101
|
+
raise Error, "Dump Failed!\n" + pipeline.error_messages
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def mysqldump
|
108
|
+
"#{ ssh_option } #{ utility(:mysqldump) } #{ credential_options } " +
|
109
|
+
"#{ connectivity_options } #{ user_options } #{ name_option } " +
|
110
|
+
"#{ tables_to_dump } #{ tables_to_skip }"
|
111
|
+
end
|
112
|
+
|
113
|
+
def ssh_option
|
114
|
+
"ssh #{ssh}" if ssh
|
115
|
+
end
|
116
|
+
|
117
|
+
def credential_options
|
118
|
+
opts = []
|
119
|
+
opts << "--user=#{ Shellwords.escape(username) }" if username
|
120
|
+
opts << "--password=#{ Shellwords.escape(password) }" if password
|
121
|
+
opts.join(' ')
|
122
|
+
end
|
123
|
+
|
124
|
+
def connectivity_options
|
125
|
+
return "--socket='#{ socket }'" if socket
|
126
|
+
|
127
|
+
opts = []
|
128
|
+
opts << "--host='#{ host }'" if host
|
129
|
+
opts << "--port='#{ port }'" if port
|
130
|
+
opts.join(' ')
|
131
|
+
end
|
132
|
+
|
133
|
+
def user_options
|
134
|
+
Array(additional_options).join(' ')
|
135
|
+
end
|
136
|
+
|
137
|
+
def user_prepare_options
|
138
|
+
Array(prepare_options).join(' ')
|
139
|
+
end
|
140
|
+
|
141
|
+
def name_option
|
142
|
+
dump_all? ? '--all-databases' : name
|
143
|
+
end
|
144
|
+
|
145
|
+
def tables_to_dump
|
146
|
+
Array(only_tables).join(' ') unless dump_all?
|
147
|
+
end
|
148
|
+
|
149
|
+
def tables_to_skip
|
150
|
+
Array(skip_tables).map do |table|
|
151
|
+
table = (dump_all? || table['.']) ? table : "#{ name }.#{ table }"
|
152
|
+
"--ignore-table='#{ table }'"
|
153
|
+
end.join(' ')
|
154
|
+
end
|
155
|
+
|
156
|
+
def dump_all?
|
157
|
+
name == :all
|
158
|
+
end
|
159
|
+
|
160
|
+
def sql_backup?
|
161
|
+
backup_engine.to_sym == :mysqldump
|
162
|
+
end
|
163
|
+
|
164
|
+
def innobackupex
|
165
|
+
# Creation phase
|
166
|
+
"#{ utility(:innobackupex) } #{ credential_options } " +
|
167
|
+
"#{ connectivity_options } #{ user_options } " +
|
168
|
+
"--no-timestamp #{ temp_dir } #{ quiet_option } && " +
|
169
|
+
innobackupex_prepare +
|
170
|
+
# Move files to tar-ed stream on stdout
|
171
|
+
"#{ utility(:tar) } --remove-files -cf - " +
|
172
|
+
"-C #{ File.dirname(temp_dir) } #{ File.basename(temp_dir) }"
|
173
|
+
end
|
174
|
+
|
175
|
+
def innobackupex_prepare
|
176
|
+
return "" unless @prepare_backup
|
177
|
+
# Log applying phase (prepare for restore)
|
178
|
+
"#{ utility(:innobackupex) } --apply-log #{ temp_dir } " +
|
179
|
+
"#{ user_prepare_options } #{ quiet_option } && "
|
180
|
+
end
|
181
|
+
|
182
|
+
def sudo_option(command_block)
|
183
|
+
return command_block unless sudo_user
|
184
|
+
|
185
|
+
"sudo -s -u #{ sudo_user } -- <<END_OF_SUDO\n" +
|
186
|
+
"#{command_block}\n" +
|
187
|
+
"END_OF_SUDO\n"
|
188
|
+
end
|
189
|
+
|
190
|
+
def quiet_option
|
191
|
+
verbose ? "" : " 2> /dev/null "
|
192
|
+
end
|
193
|
+
|
194
|
+
def temp_dir
|
195
|
+
File.join(dump_path, dump_filename + ".bkpdir")
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Backup
|
4
|
+
module Database
|
5
|
+
class OpenLDAP < Base
|
6
|
+
class Error < Backup::Error; end
|
7
|
+
|
8
|
+
##
|
9
|
+
# Name of the ldap backup
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
##
|
13
|
+
# run slapcat under sudo if needed
|
14
|
+
# make sure to set SUID on a file, to let you run the file with permissions of file owner
|
15
|
+
# eg. sudo chmod u+s /usr/sbin/slapcat
|
16
|
+
attr_accessor :use_sudo
|
17
|
+
|
18
|
+
##
|
19
|
+
# Stores the location of the slapd.conf or slapcat confdir
|
20
|
+
attr_accessor :slapcat_conf
|
21
|
+
|
22
|
+
##
|
23
|
+
# Additional slapcat options
|
24
|
+
attr_accessor :slapcat_args
|
25
|
+
|
26
|
+
##
|
27
|
+
# Path to slapcat utility (optional)
|
28
|
+
attr_accessor :slapcat_utility
|
29
|
+
|
30
|
+
##
|
31
|
+
# Takes the name of the archive and the configuration block
|
32
|
+
def initialize(model, database_id = nil, &block)
|
33
|
+
super
|
34
|
+
instance_eval(&block) if block_given?
|
35
|
+
|
36
|
+
@name ||= 'ldap_backup'
|
37
|
+
@use_sudo ||= false
|
38
|
+
@slapcat_args ||= Array.new
|
39
|
+
@slapcat_utility ||= utility(:slapcat)
|
40
|
+
@slapcat_conf ||= '/etc/ldap/slapd.d'
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Performs the slapcat command and outputs the
|
45
|
+
# data to the specified path based on the 'trigger'
|
46
|
+
def perform!
|
47
|
+
super
|
48
|
+
|
49
|
+
pipeline = Pipeline.new
|
50
|
+
dump_ext = 'ldif'
|
51
|
+
|
52
|
+
pipeline << slapcat
|
53
|
+
if @model.compressor
|
54
|
+
@model.compressor.compress_with do |command, ext|
|
55
|
+
pipeline << command
|
56
|
+
dump_ext << ext
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
pipeline << "#{ utility(:cat) } > " +
|
61
|
+
"'#{ File.join(dump_path, dump_filename) }.#{ dump_ext }'"
|
62
|
+
|
63
|
+
pipeline.run
|
64
|
+
if pipeline.success?
|
65
|
+
log!(:finished)
|
66
|
+
else
|
67
|
+
raise Error, "Dump Failed!\n" + pipeline.error_messages
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
##
|
74
|
+
# Builds the full slapcat string based on all attributes
|
75
|
+
def slapcat
|
76
|
+
command = "#{ slapcat_utility } #{ slapcat_conf_option } #{ slapcat_conf } #{ user_options }"
|
77
|
+
command.prepend("sudo ") if use_sudo
|
78
|
+
command
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Uses different slapcat switch depending on confdir or conffile set
|
83
|
+
def slapcat_conf_option
|
84
|
+
@slapcat_conf.include?(".d") ? "-F" : "-f"
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Builds a compatible string for the additional options
|
89
|
+
# specified by the user
|
90
|
+
def user_options
|
91
|
+
slapcat_args.join(' ')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|