Skip to content

Commit

Permalink
Enhancements to xtrabackup backup provider (#902)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fraenki authored and bmjen committed Dec 6, 2016
1 parent c840a35 commit 757e936
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -596,6 +596,10 @@ Sets the server backup implementation. Valid values are:

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

##### `optional_args`

Specifies an array of optional arguments which should be passed through to the backup tool. (Currently only supported by the xtrabackup provider.)

#### mysql::server::monitor

##### `mysql_monitor_username`
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqlbackup.pp
Expand Up @@ -20,6 +20,7 @@
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {

mysql_user { "${backupuser}@localhost":
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqldump.pp
Expand Up @@ -20,6 +20,7 @@
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {

ensure_packages(['bzip2'])
Expand Down
17 changes: 17 additions & 0 deletions manifests/backup/xtrabackup.pp
Expand Up @@ -22,12 +22,29 @@
$prescript = false,
$postscript = false,
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$optional_args = [],
) inherits mysql::params {

package{ $xtrabackup_package_name:
ensure => $ensure,
}

if $backupuser and $backuppassword {
mysql_user { "${backupuser}@localhost":
ensure => $ensure,
password_hash => mysql_password($backuppassword),
require => Class['mysql::server::root_password'],
}

mysql_grant { "${backupuser}@localhost/*.*":
ensure => $ensure,
user => "${backupuser}@localhost",
table => '*.*',
privileges => [ 'RELOAD', 'LOCK TABLES', 'REPLICATION CLIENT' ],
require => Mysql_user["${backupuser}@localhost"],
}
}

cron { 'xtrabackup-weekly':
ensure => $ensure,
command => "/usr/local/sbin/xtrabackup.sh ${backupdir}",
Expand Down
2 changes: 2 additions & 0 deletions manifests/server/backup.pp
Expand Up @@ -21,6 +21,7 @@
$execpath = '/usr/bin:/usr/sbin:/bin:/sbin',
$provider = 'mysqldump',
$maxallowedpacket = '1M',
$optional_args = [],
) {

if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
Expand Down Expand Up @@ -49,6 +50,7 @@
'postscript' => $postscript,
'execpath' => $execpath,
'maxallowedpacket' => $maxallowedpacket,
'optional_args' => $optional_args,
}
})

Expand Down
2 changes: 1 addition & 1 deletion spec/classes/mysql_server_backup_spec.rb
Expand Up @@ -362,7 +362,7 @@

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

Expand Down
18 changes: 17 additions & 1 deletion templates/xtrabackup.sh.erb
Expand Up @@ -12,7 +12,23 @@
<%- end -%>
<% end -%>
innobackupex "$@"
<%- _innobackupex_args = '' -%>
<%- if @backupuser and @backuppassword -%>
<%- _innobackupex_args = '--user="' + @backupuser + '" --password="' + @backuppassword + '"' -%>
<%- end -%>
<%- if @backupdatabases and @backupdatabases.is_a?(Array) and !@backupdatabases.empty? -%>
<%- _innobackupex_args = _innobackupex_args + ' --databases="' + @backupdatabases.join(' ') + '"' -%>
<%- end -%>
<%- if @optional_args and @optional_args.is_a?(Array) -%>
<%- @optional_args.each do |arg| -%>
<%- _innobackupex_args = _innobackupex_args + ' ' + arg -%>
<%- end -%>
<%- end -%>

innobackupex <%= _innobackupex_args %> "$@"

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

0 comments on commit 757e936

Please sign in to comment.