Skip to content

Commit

Permalink
Merge pull request #1171 from danquack/mariabackup
Browse files Browse the repository at this point in the history
Add support for dynamic backupmethods/mariabackup
  • Loading branch information
david22swan authored Mar 20, 2019
2 parents 879e431 + a754e1f commit 124c9ea
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqlbackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = '',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$backupdirgroup = $mysql::params::root_group,
$backupcompress = true,
$backuprotate = 30,
$backupmethod = 'mysqldump',
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
Expand Down
10 changes: 5 additions & 5 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# @summary
# "Provider" for Percona XtraBackup
# "Provider" for Percona XtraBackup/MariaBackup
# @api private
#
class mysql::backup::xtrabackup (
Expand All @@ -8,7 +8,7 @@
$backuppassword = undef,
$backupdir = '',
$maxallowedpacket = '1M',
$backupmethod = 'mysqldump',
$backupmethod = 'xtrabackup',
$backupdirmode = '0700',
$backupdirowner = 'root',
$backupdirgroup = $mysql::params::root_group,
Expand All @@ -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)
Expand All @@ -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],
Expand All @@ -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],
Expand Down
9 changes: 9 additions & 0 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -64,6 +71,7 @@
$backupdirgroup = 'root',
$backupcompress = true,
$backuprotate = 30,
$backupmethod = undef,
$ignore_events = true,
$delete_before_dump = false,
$backupdatabases = [],
Expand Down Expand Up @@ -95,6 +103,7 @@
'backupdirgroup' => $backupdirgroup,
'backupcompress' => $backupcompress,
'backuprotate' => $backuprotate,
'backupmethod' => $backupmethod,
'ignore_events' => $ignore_events,
'delete_before_dump' => $delete_before_dump,
'backupdatabases' => $backupdatabases,
Expand Down
14 changes: 13 additions & 1 deletion spec/classes/mysql_server_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
2 changes: 1 addition & 1 deletion templates/xtrabackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%- end -%>
<%- end -%>

innobackupex <%= _innobackupex_args %> "$@"
<%= @backupmethod -%> <%= _innobackupex_args %> $@

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

0 comments on commit 124c9ea

Please sign in to comment.