mariadb/mysql-test/suite/mariabackup/innodb_force_recovery.test
Srinidhi Kaushik 5bc5ecce08 MDEV-24197: Add "innodb_force_recovery" for "mariabackup --prepare"
During the prepare phase of restoring backups, "mariabackup" does
not seem to allow (or recognize) the option "innodb_force_recovery"
for the embedded InnoDB server instance that it starts.

If page corruption observed during page recovery, the prepare step
fails. While this is indeed the correct behavior ideally, allowing
this option to be set in case of emergencies might be useful when
the current backup is the only copy available. Some error messages
during "--prepare" suggest to set "innodb_force_recovery" to 1:

  [ERROR] InnoDB: Set innodb_force_recovery=1 to ignore corruption.

For backwards compatibility, "mariabackup --innobackupex --apply-log"
should also have this option.

Signed-off-by: Srinidhi Kaushik <shrinidhi.kaushik@gmail.com>
2021-04-01 13:34:40 +03:00

138 lines
5.1 KiB
Text

# This test checks if "innodb_force_recovery" is only allowed with "--prepare"
# (for mariabackup) and "--apply-log" (for innobackupex), and is limited to
# "SRV_FORCE_IGNORE_CORRUPT" only.
# Setup.
--source include/have_innodb.inc
--let targetdir=$MYSQLTEST_VARDIR/tmp/backup
--let backuplog=$MYSQLTEST_VARDIR/tmp/backup.log
CREATE TABLE t(i INT) ENGINE INNODB;
INSERT INTO t VALUES(1);
# Check for command line arguments.
--echo # "innodb_force_recovery=1" should be allowed with "--prepare" only (mariabackup)
--disable_result_log
--error 1
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --innodb-force-recovery=1 --target-dir=$targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=should only be used with "--prepare"
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
--echo # "innodb_force_recovery=1" should be allowed with "--apply-log" only (innobackupex)
--disable_result_log
--error 1
exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp --innodb-force-recovery=1 $targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=should only be used with "--apply-log"
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
--enable_result_log
--echo # "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (mariabackup)
--disable_result_log
exec $XTRABACKUP --prepare --innodb-force-recovery=2 --target-dir=$targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
rmdir $targetdir;
--disable_result_log
exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
--enable_result_log
--echo # "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (innobackupex)
--disable_result_log
exec $XTRABACKUP --innobackupex --apply-log --innodb-force-recovery=2 $targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
rmdir $targetdir;
# Check for default file ("backup-my.cnf").
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
--enable_result_log
perl;
my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
open(my $fd, '>>', "$cfg_path");
print $fd "innodb_force_recovery=1\n";
close $fd;
EOF
--echo # "innodb_force_recovery" should be read from "backup-my.cnf" (mariabackup)
--disable_result_log
exec $XTRABACKUP --defaults-file=$targetdir/backup-my.cnf --prepare --export --target-dir=$targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
rmdir $targetdir;
--disable_result_log
exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
--enable_result_log
perl;
my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
open(my $fd, '>>', "$cfg_path");
print $fd "innodb_force_recovery=2\n";
close $fd;
EOF
--echo # "innodb_force_recovery=1" should be read from "backup-my.cnf" (innobackupex)
--disable_result_log
exec $XTRABACKUP --innobackupex --defaults-file=$targetdir/backup-my.cnf --apply-log --export $targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
rmdir $targetdir;
# Check for command line argument precedence.
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
--enable_result_log
perl;
my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
open(my $fd, '>>', "$cfg_path");
print $fd "innodb_force_recovery=1\n";
close $fd;
EOF
--echo # "innodb_force_recovery" from the command line should override "backup-my.cnf" (mariabackup)
--disable_result_log
exec $XTRABACKUP --defaults-file=$targetdir/backup-my.cnf --prepare --innodb-force-recovery=0 --target-dir=$targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
rmdir $targetdir;
--disable_result_log
exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
--enable_result_log
perl;
my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
open(my $fd, '>>', "$cfg_path");
print $fd "innodb_force_recovery=2\n";
close $fd;
EOF
--echo # "innodb_force_recovery" from the command line should override "backup-my.cnf" (innobackupex)
--disable_result_log
exec $XTRABACKUP --innobackupex --defaults-file=$targetdir/backup-my.cnf --apply-log --innodb-force-recovery=0 --export $targetdir >$backuplog;
--enable_result_log
--let SEARCH_PATTERN=innodb_force_recovery = 1
--let SEARCH_FILE=$backuplog
--source include/search_pattern_in_file.inc
--source include/restart_and_restore.inc
# Check for restore.
SELECT * FROM t;
# Clean-up.
DROP TABLE t;
--rmdir $targetdir
--remove_file $backuplog