diff --git a/manifests/backup/mysqldump.pp b/manifests/backup/mysqldump.pp index eeaa672c6..1e9fd3559 100644 --- a/manifests/backup/mysqldump.pp +++ b/manifests/backup/mysqldump.pp @@ -33,6 +33,7 @@ $compression_command = 'bzcat -zc', $compression_extension = '.bz2', $backupmethod_package = undef, + Array[String] $excludedatabases = [], ) inherits mysql::params { $backuppassword_unsensitive = if $backuppassword =~ Sensitive { $backuppassword.unwrap diff --git a/manifests/backup/xtrabackup.pp b/manifests/backup/xtrabackup.pp index 0847aff59..c0ad9373a 100644 --- a/manifests/backup/xtrabackup.pp +++ b/manifests/backup/xtrabackup.pp @@ -33,6 +33,7 @@ $compression_command = undef, $compression_extension = undef, $backupmethod_package = $mysql::params::xtrabackup_package_name, + Array[String] $excludedatabases = [], ) inherits mysql::params { ensure_packages($backupmethod_package) diff --git a/manifests/server/backup.pp b/manifests/server/backup.pp index b2af984b7..9aa7d3e56 100644 --- a/manifests/server/backup.pp +++ b/manifests/server/backup.pp @@ -80,6 +80,8 @@ # Configure the file extension for the compressed backup (when using the mysqldump provider) # @param backupmethod_package # The package which provides the binary specified by the backupmethod parameter. +# @param excludedatabases +# Give a list of excluded databases when using file_per_database, e.g.: [ 'information_schema', 'performance_schema' ] class mysql::server::backup ( $backupuser = undef, Optional[Variant[String, Sensitive[String]]] $backuppassword = undef, @@ -110,6 +112,7 @@ $compression_command = undef, $compression_extension = undef, $backupmethod_package = $mysql::params::xtrabackup_package_name, + Array[String] $excludedatabases = [], ) inherits mysql::params { if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ { warning("The 'prescript' option is not currently implemented for the ${provider} backup provider.") @@ -145,6 +148,7 @@ 'compression_command' => $compression_command, 'compression_extension' => $compression_extension, 'backupmethod_package' => $backupmethod_package, + 'excludedatabases' => $excludedatabases, } }) } diff --git a/spec/classes/mysql_backup_mysqldump_spec.rb b/spec/classes/mysql_backup_mysqldump_spec.rb index 4afe8b34c..6fa75697d 100644 --- a/spec/classes/mysql_backup_mysqldump_spec.rb +++ b/spec/classes/mysql_backup_mysqldump_spec.rb @@ -71,6 +71,21 @@ class { 'mysql::server': } is_expected.not_to contain_package('bzip2') } end + + context 'with file_per_database and excludedatabases' do + let(:params) do + { + 'file_per_database' => true, + 'excludedatabases' => [ 'information_schema' ], + }.merge(default_params) + end + + it { + is_expected.to contain_file('mysqlbackup.sh').with_content( + %r{information_schema}, + ) + } + end end end # rubocop:enable RSpec/NestedGroups diff --git a/templates/mysqlbackup.sh.erb b/templates/mysqlbackup.sh.erb index 12ed05273..1fccc981f 100755 --- a/templates/mysqlbackup.sh.erb +++ b/templates/mysqlbackup.sh.erb @@ -81,7 +81,11 @@ cleanup <% end -%> <% if @backupdatabases.empty? -%> <% if @file_per_database -%> +<% if @excludedatabases.empty? -%> mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname +<% else -%> +mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= @excludedatabases.join('|') %>\)$' | while read dbname +<% end -%> do <%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \ ${ADDITIONAL_OPTIONS} \