diff --git a/README.md b/README.md index 8d159dcaa..56d3404d9 100644 --- a/README.md +++ b/README.md @@ -421,7 +421,7 @@ Plugins can be installed by using the `mysql_plugin` defined type. See `examples * `mysql::client::install`: Installs MySQL client. * `mysql::backup::mysqldump`: Implements mysqldump backups. * `mysql::backup::mysqlbackup`: Implements backups with Oracle MySQL Enterprise Backup. -* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona. +* `mysql::backup::xtrabackup`: Implements backups with XtraBackup from Percona or Mariabackup. ### Parameters diff --git a/REFERENCE.md b/REFERENCE.md index 45cc8627a..addb43b75 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -18,7 +18,7 @@ _Private Classes_ * `mysql::backup::mysqlbackup`: Manage the mysqlbackup client. * `mysql::backup::mysqldump`: "Provider" for mysqldump -* `mysql::backup::xtrabackup`: "Provider" for Percona XtraBackup +* `mysql::backup::xtrabackup`: "Provider" for Percona XtraBackup or MariaBackup * `mysql::bindings::client_dev`: Private class for installing client development bindings * `mysql::bindings::daemon_dev`: Private class for installing daemon development bindings * `mysql::bindings::java`: Private class for installing java language bindings. diff --git a/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index e2f1977cb..24fc99ad7 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -13,6 +13,7 @@ $backupdirgroup = $mysql::params::root_group, $backupcompress = true, $backuprotate = 30, + $backupmethod = '', $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index 7ed2a86a2..96f821831 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -12,6 +12,7 @@ $backupdirgroup = $mysql::params::root_group, $backupcompress = true, $backuprotate = 30, + $backupmethod = 'mysqldump', $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], diff --git a/manifests/backup/xtrabackup.pp b/manifests/backup/xtrabackup.pp index fc3e670d7..839dbff26 100644 --- a/manifests/backup/xtrabackup.pp +++ b/manifests/backup/xtrabackup.pp @@ -1,5 +1,5 @@ # @summary -# "Provider" for Percona XtraBackup +# "Provider" for Percona XtraBackup/MariaBackup # @api private # class mysql::backup::xtrabackup ( @@ -8,7 +8,7 @@ $backuppassword = undef, $backupdir = '', $maxallowedpacket = '1M', - $backupmethod = 'mysqldump', + $backupmethod = 'xtrabackup', $backupdirmode = '0700', $backupdirowner = 'root', $backupdirgroup = $mysql::params::root_group, @@ -26,7 +26,7 @@ $postscript = false, $execpath = '/usr/bin:/usr/sbin:/bin:/sbin', $optional_args = [], - $additional_cron_args = '' + $additional_cron_args = '--backup' ) inherits mysql::params { ensure_packages($xtrabackup_package_name) @@ -49,7 +49,7 @@ cron { 'xtrabackup-weekly': ensure => $ensure, - command => "/usr/local/sbin/xtrabackup.sh ${backupdir} ${additional_cron_args}", + command => "/usr/local/sbin/xtrabackup.sh --target-dir=${backupdir} ${additional_cron_args}", user => 'root', hour => $time[0], minute => $time[1], @@ -59,7 +59,7 @@ cron { 'xtrabackup-daily': ensure => $ensure, - command => "/usr/local/sbin/xtrabackup.sh --incremental ${backupdir} ${additional_cron_args}", + command => "/usr/local/sbin/xtrabackup.sh --incremental-basedir=${backupdir} --target-dir=${backupdir}/`date +%F_%H-%M-%S` ${additional_cron_args}", user => 'root', hour => $time[0], minute => $time[1], diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index 25bf0537a..a21eb5925 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -10,6 +10,11 @@ # backuppassword => 'mypassword', # backupdir => '/tmp/backups', # } +# class { 'mysql::server::backup': +# backupmethod => 'mariabackup', +# provider => 'xtrabackup', +# backupdir => '/tmp/backups', +# } # # @param backupuser # MySQL user with backup administrator privileges. @@ -25,6 +30,8 @@ # Group owner for the backup directory. This parameter is passed directly to the file resource. # @param backupcompress # Whether or not to compress the backup (when using the mysqldump provider) +# @param backupmethod +# The execution binary for backing up. ex. mysqldump, xtrabackup, mariabackup # @param backuprotate # Backup rotation interval in 24 hour periods. # @param ignore_events @@ -64,6 +71,7 @@ $backupdirgroup = 'root', $backupcompress = true, $backuprotate = 30, + $backupmethod = undef, $ignore_events = true, $delete_before_dump = false, $backupdatabases = [], @@ -95,6 +103,7 @@ 'backupdirgroup' => $backupdirgroup, 'backupcompress' => $backupcompress, 'backuprotate' => $backuprotate, + 'backupmethod' => $backupmethod, 'ignore_events' => $ignore_events, 'delete_before_dump' => $delete_before_dump, 'backupdatabases' => $backupdatabases, diff --git a/spec/classes/mysql_server_backup_spec.rb b/spec/classes/mysql_server_backup_spec.rb index e9d194b6a..5997883a7 100644 --- a/spec/classes/mysql_server_backup_spec.rb +++ b/spec/classes/mysql_server_backup_spec.rb @@ -363,7 +363,7 @@ class { 'mysql::server': } it 'contains the wrapper script' do is_expected.to contain_file('xtrabackup.sh').with_content( - %r{^innobackupex\s+.*?"\$@"}, + %r{(\n*^xtrabackup\s+.*\$@)}, ) end @@ -398,6 +398,18 @@ class { 'mysql::server': } ) end end + context 'with mariabackup' do + let(:params) do + default_params.merge(provider: 'xtrabackup', + backupmethod: 'mariabackup') + end + + it 'contain the mariabackup executor' do + is_expected.to contain_file('xtrabackup.sh').with_content( + %r{(\n*^mariabackup\s+.*\$@)}, + ) + end + end end end end diff --git a/templates/mysqlbackup.sh.erb b/templates/mysqlbackup.sh.erb index 0e2adafc7..77a437f2b 100755 --- a/templates/mysqlbackup.sh.erb +++ b/templates/mysqlbackup.sh.erb @@ -91,18 +91,18 @@ cleanup <% if @file_per_database -%> mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname do - mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ + <%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> done <% else -%> -mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ +<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> <% end -%> <% else -%> <% @backupdatabases.each do |db| -%> -mysqldump --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ +<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \ <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> <% end -%> diff --git a/templates/xtrabackup.sh.erb b/templates/xtrabackup.sh.erb index 85d31f13d..a8e83ce20 100644 --- a/templates/xtrabackup.sh.erb +++ b/templates/xtrabackup.sh.erb @@ -28,7 +28,7 @@ <%- end -%> <%- end -%> -innobackupex <%= _innobackupex_args %> "$@" +<%= @backupmethod -%> <%= _innobackupex_args %> $@ <% if @postscript -%> <%- [@postscript].flatten.compact.each do |script| %>