From 7d90921b15c59c322a625e340f95595c5247e0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Buch Date: Mon, 11 Dec 2023 10:56:11 +0100 Subject: [PATCH] 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. --- spec/classes/mysql_backup_mysqldump_spec.rb | 4 ++-- templates/mysqlbackup.sh.epp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/classes/mysql_backup_mysqldump_spec.rb b/spec/classes/mysql_backup_mysqldump_spec.rb index 6389e580a..b44c2b7ce 100644 --- a/spec/classes/mysql_backup_mysqldump_spec.rb +++ b/spec/classes/mysql_backup_mysqldump_spec.rb @@ -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 diff --git a/templates/mysqlbackup.sh.epp b/templates/mysqlbackup.sh.epp index f1301043b..3111296c3 100644 --- a/templates/mysqlbackup.sh.epp +++ b/templates/mysqlbackup.sh.epp @@ -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 \