Skip to content

Commit e42c884

Browse files
committed
Add excludedatabases when using file_per_database
Fixes #449 #461
1 parent 506563b commit e42c884

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

manifests/backup/mysqldump.pp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
$compression_command = 'bzcat -zc',
3434
$compression_extension = '.bz2',
3535
$backupmethod_package = undef,
36+
Array[String] $excludedatabases = [],
3637
) inherits mysql::params {
3738
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
3839
$backuppassword.unwrap

manifests/backup/xtrabackup.pp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
$compression_command = undef,
3434
$compression_extension = undef,
3535
$backupmethod_package = $mysql::params::xtrabackup_package_name,
36+
Array[String] $excludedatabases = [],
3637
) inherits mysql::params {
3738
ensure_packages($backupmethod_package)
3839

manifests/server/backup.pp

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
# Configure the file extension for the compressed backup (when using the mysqldump provider)
8181
# @param backupmethod_package
8282
# The package which provides the binary specified by the backupmethod parameter.
83+
# @param excludedatabases
84+
# Give a list of excluded databases when using file_per_database, e.g.: [ 'information_schema', 'performance_schema' ]
8385
class mysql::server::backup (
8486
$backupuser = undef,
8587
Optional[Variant[String, Sensitive[String]]] $backuppassword = undef,
@@ -110,6 +112,7 @@
110112
$compression_command = undef,
111113
$compression_extension = undef,
112114
$backupmethod_package = $mysql::params::xtrabackup_package_name,
115+
Array[String] $excludedatabases = [],
113116
) inherits mysql::params {
114117
if $prescript and $provider =~ /(mysqldump|mysqlbackup)/ {
115118
warning("The 'prescript' option is not currently implemented for the ${provider} backup provider.")
@@ -145,6 +148,7 @@
145148
'compression_command' => $compression_command,
146149
'compression_extension' => $compression_extension,
147150
'backupmethod_package' => $backupmethod_package,
151+
'excludedatabases' => $excludedatabases,
148152
}
149153
})
150154
}

spec/classes/mysql_backup_mysqldump_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ class { 'mysql::server': }
7171
is_expected.not_to contain_package('bzip2')
7272
}
7373
end
74+
75+
context 'with file_per_database and excludedatabases' do
76+
let(:params) do
77+
{
78+
'file_per_database' => true,
79+
'excludedatabases' => [ 'information_schema' ],
80+
}.merge(default_params)
81+
end
82+
83+
it {
84+
is_expected.to contain_file('mysqlbackup.sh').with_content(
85+
%r{information_schema},
86+
)
87+
}
88+
end
7489
end
7590
end
7691
# rubocop:enable RSpec/NestedGroups

templates/mysqlbackup.sh.erb

+4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ cleanup
8181
<% end -%>
8282
<% if @backupdatabases.empty? -%>
8383
<% if @file_per_database -%>
84+
<% if @excludedatabases.empty? -%>
8485
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname
86+
<% else -%>
87+
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= @excludedatabases.join('|') %>\)$' | while read dbname
88+
<% end -%>
8589
do
8690
<%= @backupmethod -%> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
8791
${ADDITIONAL_OPTIONS} \

0 commit comments

Comments
 (0)