#! /bin/bash
# Set MinIO admin account and password
export MINIO_ROOT_USER=myminio_admin
export MINIO_ROOT_PASSWORD=mJ7gm4SXFJF28UoD6T9a4W
# Set AWS access keys
export AWS_ACCESS_KEY_ID=myminio_admin
export AWS_SECRET_ACCESS_KEY=mJ7gm4SXFJF28UoD6T9a4W
# Add MinIO host alias
mc config host add tidb-test http://192.168.136.101:9000 myminio_admin mJ7gm4SXFJF28UoD6T9a4W
mc config host ls tidb_test
# Create bucket
mc mb /tidb/backup/bucket
# Generate unique bucket name
timestamp=$(date +"%Y%m%d%H%M%S")
bucket_name="backup-${timestamp}"
# Perform full backup
/usr/bin/br backup full --ratelimit 100 --pd "192.168.136.101:2379" --storage "s3://bucket/${bucket_name}" \
--send-credentials-to-tikv=true --s3.endpoint "http://192.168.136.101:9000" --log-file "/tidb/backup/backup_${timestamp}.log"
Incremental Backup:
#! /bin/bash
export MINIO_ROOT_USER=myminio_admin
export MINIO_ROOT_PASSWORD=mJ7gm4SXFJF28UoD6T9a4W
export AWS_ACCESS_KEY_ID=myminio_admin
export AWS_SECRET_ACCESS_KEY=mJ7gm4SXFJF28UoD6T9a4W
# Add MinIO host alias
mc config host add tidb-test http://192.168.136.101:9000 myminio_admin mJ7gm4SXFJF28UoD6T9a4W
mc config host ls tidb_test
# Create bucket
mc mb tidb/backup/bucket
# Generate unique bucket name
timestamp=$(date +"%Y%m%d%H%M%S")
bucket_name="backup-${timestamp}"
# Get the timestamp of the last full backup
last_backup=$(mc cat /tidb/backup/bucket/last_backup)
# Determine if a full backup is needed
if [ -z "$last_backup" ]; then
echo "$timestamp" | mc pipe /tidb/backup/bucket/last_backup
# Perform full backup
/usr/bin/br backup full --ratelimit 100 --pd "192.168.136.101:2379" --storage "s3://bucket/${bucket_name}" \
--send-credentials-to-tikv=true --s3.endpoint "http://192.168.136.101:9000" --log-file "/tidb/backup/backup_${timestamp}.log"
else
# Perform incremental backup
/usr/bin/br backup incremental --ratelimit 100 --pd "192.168.136.101:2379" --storage "s3://bucket/${bucket_name}" \
--send-credentials-to-tikv=true --s3.endpoint "http://192.168.136.101:9000" --last-backup "$last_backup" --log-file "/tidb/backup/backup_${timestamp}.log"
fi
# Update the timestamp of the last full backup
echo "$timestamp" | mc pipe /tidb/backup/bucket/last_backup
Just a reminder, OP, please be mindful of desensitizing content when posting, especially things like admin accounts and passwords, AWS access keys, etc. Try to protect such information and avoid posting it online.
Additionally, you can refer to the solution mentioned by the expert upstairs, pay attention to the naming issues, and try again after making adjustments.
What version of BR are you using? The backup command you provided is different from the official documentation. I checked the documentation for versions 6.5 and 7.5, and your command isn’t there. Here’s the link to the official documentation: TiDB 增量备份与恢复使用指南 | PingCAP 文档中心
Also, the official incremental backup is no longer maintained. It is recommended to use log backup (PITR) in the future.
No. BR requires either using shared storage like NFS or S3 for backups, or having a folder with the same path on each TiKV with the same access permissions.
You should be using S3 for storing backups, so why is it asking for a local folder? It’s likely that there’s something incorrect in the command settings. Please provide the BR command.
I looked at the logic of your script and the current method, and there is indeed a significant difference. The current br backup method is:
TiDB supports two types of backups, which one should be used? Full backups include all data at a specific point in time in the cluster, while log backups include records of data changes generated by business writes in TiDB. It is recommended to use both backup methods together:
Enable log backup: Run the br log start command to start the log backup task. The task will continuously run on each TiKV node, periodically backing up TiDB change data to the specified storage in small batches.
Regularly perform snapshot (full) backup: Run the br backup full command to back up the cluster snapshot to the backup storage, for example, performing a cluster snapshot backup at midnight every day.
The br log start log backup starts and does not stop. It does not need to be executed periodically. The br backup full snapshot backup needs to be executed regularly. Your script might be an approach from an earlier version.