Issues with Incremental Backup and Restore in TiDB BR Logs

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb br日志增量备份恢复问题

| username: bryanz

[TiDB Usage Environment] Production Environment
[TiDB Version] v7.1.1
[Reproduction Path] Unable to restore data from 30 minutes ago
[Encountered Problem: Problem Phenomenon and Impact] After a full BR backup, log incremental backup was enabled. Now, it is impossible to restore data from half an hour ago. Error reported: Error: it has gap between full backup ts:448487459931815937(2024-03-19 18:24:47.069 +0800 CST) and log backup ts:448487473956519937(2024-03-19 18:25:40.569 +0800 CST). :[BR:Common:ErrInvalidArgument]invalid argument
Error

[Resource Configuration]
[Attachment: Screenshot/Log/Monitoring]

| username: bryanz | Original post link

Is it only possible to restore to the point in time before the full backup, but not after the full backup?

| username: zhanggame1 | Original post link

First enable logging, then perform a full database backup. You can do the full database backup afterwards.

| username: bryanz | Original post link

Yesterday, I did a full backup. Then I enabled logging, and today I prepared to test the restore but it didn’t work.

tiup br restore point --pd "pd-01:30001" \
--storage="s3://tidb-test-backup/br/logbackup? \
--full-backup-storage="s3://tidb-test-backup/br/snapshot-202403191824 \
--restored-ts '2024-03-20 11:58:00+0800'
| username: tidb菜鸟一只 | Original post link

Is there a gap between the ts specified for your log backup and the ts during the full backup? It’s best to specify the ts at the completion of the full backup for the log backup, or start the log backup first and then proceed with the full backup.

| username: bryanz | Original post link

Thank you, master. The log backup did not specify ts.


I did a full backup first and then started the log backup.

| username: zhanggame1 | Original post link

So you got the order wrong. First, enable logging, then back up the entire database. You lost the logs for the part after the full database.

| username: bryanz | Original post link

Thank you, boss. So how should I schedule regular backups in the future? A full backup once a day, and should I keep the log backup running?

| username: 裤衩儿飞上天 | Original post link

You can refer to: TiDB Log Backup and PITR User Guide | PingCAP Documentation Center

| username: zhanggame1 | Original post link

Once you enable log backup, don’t turn it off. For full and incremental backups, you need to write a scheduled task.

| username: bryanz | Original post link

Is it necessary to turn off log backups during recovery?

| username: tidb菜鸟一只 | Original post link

Once log backup is enabled, it will continue to back up. Then you perform full backups periodically. After the full backup is completed, the previous full backup and log backups can be deleted.

| username: bryanz | Original post link

Got it, boss. One more question: Can BR log backup and restore only be done in a new environment? I just tested it and found that it can only be restored in a cluster that doesn’t already exist.

| username: tidb菜鸟一只 | Original post link

Log backups must be restored based on a full backup. For example, if you start continuous log backups from the 1st, perform a full backup on the 3rd, 5th, and 7th, and then want to restore data to the 6th, you need to first restore the full backup from the 5th and then specify the log backup to restore to the 6th.

| username: bryanz | Original post link

I tested the recovery, and it prompted that the database cannot have the same name to execute. Does this mean that the log recovery can only be done in a new environment?

| username: zhanggame1 | Original post link

Need to clear data or restore to a new environment.

| username: bryanz | Original post link

Okay, thank you.

| username: IanWong | Original post link

Before performing PITR, check the full backup point and log point.

Full backup point:

br validate decode --field="end-version" --storage "local:///backup/full" | tail -n1

Log backup point:

br log metadata --storage 'local:///backup/log/'

The logs between the full backup point and the point to be restored need to be continuous.