[MDEV-13310] Preparing an incremental backup twice can corrupt data Created: 2017-07-13  Updated: 2017-10-10  Resolved: 2017-10-10

Status: Closed
Project: MariaDB Server
Component/s: Backup
Affects Version/s: 10.2.7
Fix Version/s: 10.1.29, 10.2.10

Type: Bug Priority: Critical
Reporter: Andrii Nikitin (Inactive) Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-13822 Mariabackup --prepare --incremental s... Closed

 Description   

Preparing already prepared incremental backup does show error message below in percona-xtrabackup as well mariabackup 10.1.25 (to protect users from incorrect action).

xtrabackup: This target seems to be already prepared.
xtrabackup: error: applying incremental backup needs target prepared with --apply-log-only.

test below passes in 10.1.25 (mariabackup exits with error code 1), but fails in 10.2.7 (mariabackup exits without error):

call mtr.add_suppression("InnoDB: New log files created");
 
let $basedir=$MYSQLTEST_VARDIR/tmp/backup;
let $incremental_dir1=$MYSQLTEST_VARDIR/tmp/backup_inc1;
let $incremental_dir2=$MYSQLTEST_VARDIR/tmp/backup_inc2;
 
CREATE TABLE t(i INT) ENGINE INNODB;
INSERT INTO t VALUES(1);
 
echo # Create full backup , modify table, then create incremental/differential backup;
--disable_result_log
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf  --backup --target-dir=$basedir;
--enable_result_log
INSERT INTO t VALUES(2);
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf  --backup --target-dir=$incremental_dir1 --incremental-basedir=$basedir;
 
INSERT INTO t VALUES(3);
exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf  --backup --target-dir=$incremental_dir2 --incremental-basedir=$basedir;
 
echo # Prepare full backup, apply incremental one;
exec $XTRABACKUP --prepare --apply-log-only --target-dir=$basedir;
exec $XTRABACKUP --prepare --apply-log-only --target-dir=$basedir --incremental-dir=$incremental_dir1 ;
 
echo # This time should succeed;
exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir2 ;
 
# this returns an error according to test pxb170.sh
--error 1
exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir2 ;
 
# Cleanup
drop table t;
rmdir $basedir;
rmdir $incremental_dir1;
rmdir $incremental_dir2;

10.1.25:
Completed: All 1 tests were successful.
10.2.7:
mysqltest: At line 35: command "$XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir2 " succeeded - should have failed with errno 1...



 Comments   
Comment by Marko Mäkelä [ 2017-08-10 ]

First, preparing a full backup should be safe to do repeatedly in Mariabackup 10.2. It should even be safe to kill the process and rerun the prepare.

When it comes to preparing incremental backups, we must guarantee that .delta files cannot overwrite data files on which redo log has already been applied. Currently this is not the case!

So, it is possible that the .delta files will corrupt data files by writing older data than what was applied from the redo log on the previous invocation. Because the redo log file ib_logfile0 was deleted by the first (successful) invocation of

exec $XTRABACKUP --prepare --target-dir=$basedir --incremental-dir=$incremental_dir2 ;

re-applying the .delta files by repeating the invocation can cause unrecoverable corruption.

My suggested fix is to remove each .delta files after applying them.

Generated at Thu Feb 08 08:04:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.