Skip to content

Commit 34277ac

Browse files
authored
br: add compact log backup (#20342)
1 parent 87f25f7 commit 34277ac

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

TOC.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
- [Use Overview](/br/br-use-overview.md)
243243
- [Snapshot Backup and Restore Guide](/br/br-snapshot-guide.md)
244244
- [Log Backup and PITR Guide](/br/br-pitr-guide.md)
245+
- [Compact Log Backup](/br/br-compact-log-backup.md)
245246
- [Use Cases](/br/backup-and-restore-use-cases.md)
246247
- [Backup Storages](/br/backup-and-restore-storages.md)
247248
- BR CLI Manuals

br/br-compact-log-backup.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Compact Log Backup
3+
summary: Learn how to improve Point-in-time Recovery (PITR) efficiency by compacting log backups into the SST format.
4+
---
5+
6+
# Compact Log Backup
7+
8+
This document describes how to improve the efficiency of point-in-time recovery ([PITR](/glossary.md#point-in-time-recovery-pitr)) by compacting log backups into the [SST](/glossary.md#static-sorted-table--sorted-string-table-sst) format.
9+
10+
## Overview
11+
12+
Traditional log backups store write operations in a highly unstructured manner, which can lead to the following issues:
13+
14+
- **Reduced recovery performance**: unordered data has to be written to the cluster one by one through the Raft protocol.
15+
- **Write amplification**: all writes must be compacted from L0 to the bottommost level by level.
16+
- **Dependency on full backups**: frequent full backups are required to control the amount of recovery data, which can impact application operations.
17+
18+
Starting from v9.0.0, the compact log backup feature provides offline compaction capabilities, converting unstructured log backup data into structured SST files. This results in the following improvements:
19+
20+
- SST files can be quickly imported into the cluster, **improving recovery performance**.
21+
- Redundant data is removed during compaction, **reducing storage space consumption**.
22+
- You can set longer full backup intervals while ensuring the Recovery Time Objective (RTO), **reducing the impact on applications**.
23+
24+
## Limitations
25+
26+
- Compact log backup is not a replacement for full backups. It must be used in conjunction with periodical full backups. To ensure PITR capability, the compacting process retains all MVCC versions. Failing to perform full backups for a long time can lead to excessive storage usage and might cause issues when restoring data later.
27+
- Currently, compacting backups with local encryption enabled is not supported.
28+
29+
## Use compact log backup
30+
31+
Currently, only manual compaction of log backups is supported, and the process is complex. **It is recommended to use the coming TiDB Operator solution for compacting log backups in production environments.**
32+
33+
### Manual compaction
34+
35+
This section describes the steps for manually compacting log backups.
36+
37+
#### Prerequisites
38+
39+
Manual compaction of log backups requires two tools: `tikv-ctl` and `br`.
40+
41+
#### Step 1: Encode storage to Base64
42+
43+
Execute the following encoding command:
44+
45+
```shell
46+
br operator base64ify --storage "s3://your/log/backup/storage/here" --load-creds
47+
```
48+
49+
> **Note:**
50+
>
51+
> - If the `--load-creds` option is included when you execute the preceding command, the encoded Base64 string contains credential information loaded from the current BR environment. Note to ensure proper security and access control.
52+
> - The `--storage` value matches the storage output from the `log status` command of the log backup task.
53+
54+
#### Step 2: Execute log compaction
55+
56+
With the Base64-encoded storage, you can initiate the compaction using `tikv-ctl`. Note that the default log level of `tikv-ctl` is `warning`. Use `--log-level info` to obtain more detailed information:
57+
58+
```shell
59+
tikv-ctl --log-level info compact-log-backup \
60+
--from "<start-tso>" --until "<end-tso>" \
61+
-s 'bAsE64==' -N 8
62+
```
63+
64+
Parameter descriptions:
65+
66+
- `-s`: the Base64-encoded storage string obtained earlier.
67+
- `-N`: the maximum number of concurrent log compaction tasks.
68+
- `--from`: the start timestamp for compaction.
69+
- `--until`: the end timestamp for compaction.
70+
71+
The `--from` and `--until` parameters define the time range for the compaction operation. The compaction operation handles all log files containing write operations within the specified time range, so the generated SST files might include data outside this range.
72+
73+
To obtain the timestamp for a specific point in time, execute the following command:
74+
75+
```shell
76+
echo $(( $(date --date '2004-05-06 15:02:01Z' +%s%3N) << 18 ))
77+
```
78+
79+
> **Note:**
80+
>
81+
> If you are a macOS user, you need to install `coreutils` via Homebrew and use `gdate` instead of `date`.
82+
>
83+
> ```shell
84+
> echo $(( $(gdate --date '2004-05-06 15:02:01Z' +%s%3N) << 18 ))
85+
> ```

0 commit comments

Comments
 (0)