How TiDB Implements PITR (Point-in-Time Recovery)

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

Original topic: TiDB 如何实现 PITR (按时间点恢复)

| username: TiDBer_rdb3y58G

It seems that TIDB does not have binlog, so how can point-in-time recovery be achieved? Is there any related process documentation?

| username: TIDB-Learner | Original post link

TiDB has binlog logs, check the official documentation.

| username: 这里介绍不了我 | Original post link

Take a look here:
TiDB Log Backup and PITR Architecture | PingCAP Documentation Center
TiDB Log Backup and PITR User Guide | PingCAP Documentation Center

| username: Daniel-W | Original post link

There is binlog, and you can also use BR.

| username: zhaokede | Original post link

There is binlog.

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

Use <br> then.

| username: zhanggame1 | Original post link

BR+log backup doesn’t have very high real-time performance; in extreme cases, it may lose more than 2 minutes of data.

| username: 濱崎悟空 | Original post link

BR tool

| username: 希希希望啊 | Original post link

Implement it using the BR tool.

| username: YuchongXU | Original post link

BR backup and restore tool

| username: 呢莫不爱吃鱼 | Original post link

Use <br> instead.

| username: Jellybean | Original post link

For the point-in-time recovery feature, it is recommended to use TiDB Binlog before v6.5, and BR’s PITR feature for versions v6.5 and later. From the usage scenario perspective, PITR is typically used to restore the cluster’s data to a specified point in time when the cluster has completely stopped service or the data is corrupted and cannot be recovered using other methods. When using PITR, you need to complete the data recovery through a new cluster.

You can refer to the article: 专栏 - 坚如磐石:TiDB 基于时间点的恢复(PiTR)特性优化之路丨6.5 新特性解析 | TiDB 社区

Additionally, for real-time master-slave synchronization scenarios, there is a similar situation. It is recommended to use TiDB Binlog before v6.5, and TiCDC tool for versions v6.5 and later.

| username: 我是吉米哥 | Original post link

Perform PITR. If restoring to a different machine, there’s no need to stop log backups. If restoring to the same machine, log backups need to be stopped.

PITR only supports restoring to a brand new empty cluster.
PITR only supports cluster-level restoration and does not support restoring individual databases or tables.
PITR does not support restoring user tables and permission tables in system tables.
During a PITR data restoration task, log backup tasks cannot run simultaneously, nor can data be synchronized to downstream clusters via TiCDC.

If restoring to the same machine, delete the databases before restoration:
drop database lightning_task_info;
drop database dm_meta;
drop database test;

Perform the restoration:
tiup br restore point --pd xx.xx.xx.xx:2379 --storage=‘local:///backup/brbak/tidb-test/logbackup’ --full-backup-storage=‘local:///backup/brbak/tidb-test/fullbackup-20240702’ --restored-ts ‘2024-07-02 08:42:00+0800’

Clean up log backups prior to the last full backup

FULL_BACKUP_TS=tiup br validate decode --field="end-version" --storage "local:///backup/brbak/tidb-test/fullbackup-20240702"| tail -n1
tiup br log truncate --until=${FULL_BACKUP_TS} --storage “local:///backup/brbak/tidb-test/logbackup”

| username: xuqiang76 | Original post link

br tool

| username: TiDBer_7S8XqKfl | Original post link

TiDB is compatible with MySQL and has binlog logs.

| username: 洪七表哥 | Original post link

Use br

| username: YuchongXU | Original post link

BR backup tool

| username: yulei7633 | Original post link

Point can only restore to an empty database (that is, the database must be empty to proceed).
tiup br restore point xxx

| username: TiDBer_7S8XqKfl-1158 | Original post link

TiDB itself does not use traditional binary logs (binlog) for data persistence and replication but instead employs its own data replication mechanism. In the early versions of TiDB, TiDB Binlog could be used to achieve functionality similar to traditional database binlogs. However, starting from TiDB version 7.5.0, the data synchronization feature of TiDB Binlog is no longer technically supported, and TiCDC is recommended as an alternative for data synchronization.

| username: TiDBer_tvqzG8Dk | Original post link

There is binlog, and you can also use BR.