Skip to content

Commit 757e936

Browse files
fraenkibmjen
authored andcommitted
Enhancements to xtrabackup backup provider (#902)
* Add support for more parameters for xtrabackup provider * Add support for 'databases' parameter for xtrabackup provider * Fix unit test * Add documentation for the new optional_args parameter
1 parent c840a35 commit 757e936

File tree

7 files changed

+43
-2
lines changed

7 files changed

+43
-2
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ Sets the server backup implementation. Valid values are:
596596

597597
Defines the maximum SQL statement size for the backup dump script. The default value is 1MB, as this is the default MySQL Server value.
598598

599+
##### `optional_args`
600+
601+
Specifies an array of optional arguments which should be passed through to the backup tool. (Currently only supported by the xtrabackup provider.)
602+
599603
#### mysql::server::monitor
600604

601605
##### `mysql_monitor_username`

manifests/backup/mysqlbackup.pp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
$prescript = false,
2121
$postscript = false,
2222
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
23+
$optional_args = [],
2324
) inherits mysql::params {
2425

2526
mysql_user { "${backupuser}@localhost":

manifests/backup/mysqldump.pp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
$prescript = false,
2121
$postscript = false,
2222
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
23+
$optional_args = [],
2324
) inherits mysql::params {
2425

2526
ensure_packages(['bzip2'])

manifests/backup/xtrabackup.pp

+17
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,29 @@
2222
$prescript = false,
2323
$postscript = false,
2424
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
25+
$optional_args = [],
2526
) inherits mysql::params {
2627

2728
package{ $xtrabackup_package_name:
2829
ensure => $ensure,
2930
}
3031

32+
if $backupuser and $backuppassword {
33+
mysql_user { "${backupuser}@localhost":
34+
ensure => $ensure,
35+
password_hash => mysql_password($backuppassword),
36+
require => Class['mysql::server::root_password'],
37+
}
38+
39+
mysql_grant { "${backupuser}@localhost/*.*":
40+
ensure => $ensure,
41+
user => "${backupuser}@localhost",
42+
table => '*.*',
43+
privileges => [ 'RELOAD', 'LOCK TABLES', 'REPLICATION CLIENT' ],
44+
require => Mysql_user["${backupuser}@localhost"],
45+
}
46+
}
47+
3148
cron { 'xtrabackup-weekly':
3249
ensure => $ensure,
3350
command => "/usr/local/sbin/xtrabackup.sh ${backupdir}",

manifests/server/backup.pp

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
2222
$provider = 'mysqldump',
2323
$maxallowedpacket = '1M',
24+
$optional_args = [],
2425
) {
2526

2627
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
@@ -49,6 +50,7 @@
4950
'postscript' => $postscript,
5051
'execpath' => $execpath,
5152
'maxallowedpacket' => $maxallowedpacket,
53+
'optional_args' => $optional_args,
5254
}
5355
})
5456

spec/classes/mysql_server_backup_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362

363363
it 'should contain the wrapper script' do
364364
is_expected.to contain_file('xtrabackup.sh').with_content(
365-
/^innobackupex\s+"\$@"/
365+
/^innobackupex\s+.*?"\$@"/
366366
)
367367
end
368368

templates/xtrabackup.sh.erb

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,23 @@
1212
<%- end -%>
1313
<% end -%>
1414

15-
innobackupex "$@"
15+
<%- _innobackupex_args = '' -%>
16+
17+
<%- if @backupuser and @backuppassword -%>
18+
<%- _innobackupex_args = '--user="' + @backupuser + '" --password="' + @backuppassword + '"' -%>
19+
<%- end -%>
20+
21+
<%- if @backupdatabases and @backupdatabases.is_a?(Array) and [email protected]? -%>
22+
<%- _innobackupex_args = _innobackupex_args + ' --databases="' + @backupdatabases.join(' ') + '"' -%>
23+
<%- end -%>
24+
25+
<%- if @optional_args and @optional_args.is_a?(Array) -%>
26+
<%- @optional_args.each do |arg| -%>
27+
<%- _innobackupex_args = _innobackupex_args + ' ' + arg -%>
28+
<%- end -%>
29+
<%- end -%>
30+
31+
innobackupex <%= _innobackupex_args %> "$@"
1632

1733
<% if @postscript -%>
1834
<%- [@postscript].flatten.compact.each do |script| %>

0 commit comments

Comments
 (0)