@@ -450,25 +450,53 @@ test_system_tables() {
450450 run_sql " create schema $DB ;"
451451
452452 echo " write initial data and do snapshot backup"
453- # create and populate a user table for reference
454- run_sql " create table $DB .user_table(id int primary key);"
455- run_sql " insert into $DB .user_table values (1);"
456-
457453 # make some changes to system tables
458454 run_sql " create user 'test_user'@'%' identified by 'password';"
459455 run_sql " grant select on $DB .* to 'test_user'@'%';"
460456
461457 run_br backup full -s " local://$TEST_DIR /$TASK_NAME /full" --pd $PD_ADDR
462458
463459 echo " make more changes to system tables and wait for log backup"
464- run_sql " revoke select on $DB .* from 'test_user'@'%';"
465- run_sql " grant insert on $DB .* to 'test_user'@'%';"
460+ run_sql " create user 'post_backup_user'@'%' identified by 'otherpassword';"
466461 run_sql " alter user 'test_user'@'%' identified by 'newpassword';"
467462
468463 . " $CUR /../br_test_utils.sh" && wait_log_checkpoint_advance " $TASK_NAME "
469464
470465 restart_services || { echo " Failed to restart services" ; exit 1; }
471466
467+ echo " Test 1: Verify that default restore behavior (no filter) properly handles system tables"
468+ # restore without any filter, should only restore snapshot system tables, not log backup.
469+ # this is the current behavior as restore log backup to system table will have issue
470+ run_br --pd " $PD_ADDR " restore point -s " local://$TEST_DIR /$TASK_NAME /log" --full-backup-storage " local://$TEST_DIR /$TASK_NAME /full"
471+
472+
473+ # verify system tables are restored from snapshot only
474+ # only test_user should exist, post_backup_user should not exist
475+ users_result=$( run_sql " SELECT _tidb_rowid, user, host, authentication_string FROM mysql.user WHERE user IN ('test_user', 'post_backup_user')" )
476+
477+ test_user_count=$( echo " $users_result " | grep -c " test_user" || true)
478+
479+ # Verify there is exactly one test_user
480+ if [ " $test_user_count " -eq 0 ]; then
481+ echo " Error: test_user not found in mysql.user table"
482+ exit 1
483+ elif [ " $test_user_count " -gt 1 ]; then
484+ echo " Error: Found $test_user_count instances of test_user in mysql.user table, expected exactly 1"
485+ echo " Full query result:"
486+ echo " $users_result "
487+ exit 1
488+ fi
489+
490+ # Check that post_backup_user does not exist (was created after snapshot)
491+ if echo " $users_result " | grep -q " post_backup_user" ; then
492+ echo " Error: post_backup_user found in mysql.user table but should not be restored"
493+ echo " Full query result:"
494+ echo " $users_result "
495+ exit 1
496+ fi
497+
498+ echo " Default restore correctly restored system tables from snapshot only: verified one test_user exists"
499+
472500 echo " PiTR should error out when system tables are included with explicit filter"
473501 restore_fail=0
474502 run_br --pd " $PD_ADDR " restore point -f " *.*" -s " local://$TEST_DIR /$TASK_NAME /log" --full-backup-storage " local://$TEST_DIR /$TASK_NAME /full" || restore_fail=1
0 commit comments