Skip to content

Commit 45a2a45

Browse files
committed
Fix backup/rotation with multiple excluded databases
* When using multiple excluded databases, the list of databases is filtered using `grep -v`. i.e. `grep -v '^\(information_schema|performance_schema\)$` * When using Basic vs Extended Regular Expressions, the characters `(` and `|` lose their special meaning, the backslashed versions have to be used. For the group (`()`) the escaping has been done, however the alternation is unescaped. Leading to: * All the excluded databases will be backed up. * In case a database is not backuppable (which is why it had been excluded), this leads to the cleanup not being run at all, as it depends on the backup having been successful. This MR aims to fix this issue, by revising the regular expression and specifying that behaviour in the respective class spec.
1 parent 49ebfc3 commit 45a2a45

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: spec/classes/mysql_backup_mysqldump_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ class { 'mysql::server': }
7676
let(:params) do
7777
{
7878
'file_per_database' => true,
79-
'excludedatabases' => ['information_schema']
79+
'excludedatabases' => ['information_schema', 'performance_schema']
8080
}.merge(default_params)
8181
end
8282

8383
it {
8484
expect(subject).to contain_file('mysqlbackup.sh').with_content(
85-
%r{information_schema},
85+
%r{information_schema\\\|performance_schema},
8686
)
8787
}
8888
end

Diff for: templates/mysqlbackup.sh.epp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ cleanup
8484
<% if $excludedatabases.empty { -%>
8585
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | while read dbname
8686
<%} else {-%>
87-
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= $excludedatabases.join('|') %>\)$' | while read dbname
87+
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= $excludedatabases.join('\\|') %>\)$' | while read dbname
8888
<% } -%>
8989
do
9090
<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \

0 commit comments

Comments
 (0)