diff --git a/manifests/backup/mysqlbackup.pp b/manifests/backup/mysqlbackup.pp index 549279bb7..b67139668 100644 --- a/manifests/backup/mysqlbackup.pp +++ b/manifests/backup/mysqlbackup.pp @@ -29,6 +29,8 @@ $optional_args = [], $incremental_backups = false, $install_cron = true, + $compression_command = undef, + $compression_extension = undef, ) inherits mysql::params { mysql_user { "${backupuser}@localhost": ensure => $ensure, diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index 5c57a5062..29c68d3cb 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -30,9 +30,11 @@ $mysqlbackupdir_target = undef, $incremental_backups = false, $install_cron = true, + $compression_command = 'bzcat -zc', + $compression_extension = '.bz2' ) inherits mysql::params { unless $::osfamily == 'FreeBSD' { - if $backupcompress { + if $backupcompress and $compression_command == 'bzcat -zc' { ensure_packages(['bzip2']) Package['bzip2'] -> File['mysqlbackup.sh'] } diff --git a/manifests/backup/xtrabackup.pp b/manifests/backup/xtrabackup.pp index 82c3d42ed..8d705a8c1 100644 --- a/manifests/backup/xtrabackup.pp +++ b/manifests/backup/xtrabackup.pp @@ -31,6 +31,8 @@ $additional_cron_args = '--backup', $incremental_backups = true, $install_cron = true, + $compression_command = undef, + $compression_extension = undef, ) inherits mysql::params { ensure_packages($xtrabackup_package_name) diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index f89063a7c..008859007 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -67,6 +67,11 @@ # Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.) # @param install_cron # Manage installation of cron package +# @param compression_command +# Configure the command used to compress the backup (when using the mysqldump provider). Make sure the command exists +# on the target system. Packages for it are NOT automatically installed. +# @param compression_extension +# Configure the file extension for the compressed backup (when using the mysqldump provider) class mysql::server::backup ( $backupuser = undef, $backuppassword = undef, @@ -94,6 +99,8 @@ $optional_args = [], $incremental_backups = true, $install_cron = true, + $compression_command = undef, + $compression_extension = undef ) inherits mysql::params { if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ { warning(translate("The 'prescript' option is not currently implemented for the %{provider} backup provider.", @@ -127,6 +134,8 @@ 'optional_args' => $optional_args, 'incremental_backups' => $incremental_backups, 'install_cron' => $install_cron, + 'compression_command' => $compression_command, + 'compression_extension' => $compression_extension, } }) } diff --git a/spec/classes/mysql_backup_mysqldump_spec.rb b/spec/classes/mysql_backup_mysqldump_spec.rb index b9dfbcf3c..4afe8b34c 100644 --- a/spec/classes/mysql_backup_mysqldump_spec.rb +++ b/spec/classes/mysql_backup_mysqldump_spec.rb @@ -52,6 +52,25 @@ class { 'mysql::server': } ) } end + + context 'with compression_command' do + let(:params) do + { + compression_command: 'TEST -TEST', + compression_extension: '.TEST' + }.merge(default_params) + end + + it { + is_expected.to contain_file('mysqlbackup.sh').with_content( + %r{(\| TEST -TEST)}, + ) + is_expected.to contain_file('mysqlbackup.sh').with_content( + %r{(\.TEST)}, + ) + is_expected.not_to contain_package('bzip2') + } + end end end # rubocop:enable RSpec/NestedGroups diff --git a/templates/mysqlbackup.sh.erb b/templates/mysqlbackup.sh.erb index 19706fb27..aea8cae9f 100755 --- a/templates/mysqlbackup.sh.erb +++ b/templates/mysqlbackup.sh.erb @@ -93,18 +93,18 @@ mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read d do <%= @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 %> + ${dbname} <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> done <% else -%> <%= @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 %> + --all-databases <% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> <% end -%> <% else -%> <% @backupdatabases.each do |db| -%> <%= @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 %> + <%= db %><% if @backupcompress %>| <%= @compression_command %> <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %><%= @compression_extension %><% end %> <% end -%> <% end -%>