Skip to content

Allow excludedatabases when using file_per_database #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions manifests/backup/xtrabackup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions manifests/server/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -145,6 +148,7 @@
'compression_command' => $compression_command,
'compression_extension' => $compression_extension,
'backupmethod_package' => $backupmethod_package,
'excludedatabases' => $excludedatabases,
}
})
}
15 changes: 15 additions & 0 deletions spec/classes/mysql_backup_mysqldump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions templates/mysqlbackup.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down