Skip to content

Commit 7a6f4c4

Browse files
committed
Allow excludedatabases when using file_per_database
Fixes #449 #461
1 parent 506563b commit 7a6f4c4

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
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[Strings] $excludedatabases = [],
3637
) inherits mysql::params {
3738
$backuppassword_unsensitive = if $backuppassword =~ Sensitive {
3839
$backuppassword.unwrap

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[Strings] $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

+11
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ 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 { is_expected.to contain_file('mysqlbackup.sh').with_content(%r{grep -v.*information_schema}) }
84+
end
7485
end
7586
end
7687
# rubocop:enable RSpec/NestedGroups

templates/mysqlbackup.sh.erb

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

0 commit comments

Comments
 (0)