Skip to content

Commit

Permalink
Fix backup/rotation with multiple excluded databases
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
BuJo committed Oct 1, 2024
1 parent ed18548 commit 7d90921
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions spec/classes/mysql_backup_mysqldump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ class { 'mysql::server': }
let(:params) do
{
'file_per_database' => true,
'excludedatabases' => ['information_schema']
'excludedatabases' => ['information_schema', 'performance_schema']
}.merge(default_params)
end

it {
expect(subject).to contain_file('mysqlbackup.sh').with_content(
%r{information_schema},
%r{information_schema\\\|performance_schema},
)
}
end
Expand Down
2 changes: 1 addition & 1 deletion templates/mysqlbackup.sh.epp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cleanup
<% 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
mysql --defaults-extra-file=$TMPFILE -s -r -N -e 'SHOW DATABASES' | grep -v '^\(<%= $excludedatabases.join('\\|') %>\)$' | while read dbname
<% } -%>
do
<%= $backupmethod %> --defaults-extra-file=$TMPFILE --opt --flush-logs --single-transaction \
Expand Down

0 comments on commit 7d90921

Please sign in to comment.