-
Notifications
You must be signed in to change notification settings - Fork 261
Description
kubeblocsL 1.0.1
mysql: 8.0.36
source mysql:
- CREATE TABLE test;
mysql > DROP TABLE IF EXISTS test;
CREATE TABLE test (
id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
name VARCHAR(50) NOT NULL COMMENT '姓名',
age INT COMMENT '年龄',
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间(默认当前时间)',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间(默认当前时间,更新时自动刷新)'
) COMMENT '测试表';
mysql > INSERT INTO test (name, age) VALUES
('张三', 25),
('李四', 30),
('王五', 28),
('赵六', 35),
('小明', 22),
('小红', 27),
('小刚', 32),
('莉莉', 29),
('华华', 31),
('芳芳', 26);
mysql> select * from test;
+----+--------+------+---------------------+---------------------+
| id | name | age | create_time | update_time |
+----+--------+------+---------------------+---------------------+
| 1 | 张三 | 25 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 2 | 李四 | 30 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 3 | 王五 | 28 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 4 | 赵六 | 35 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 5 | 小明 | 22 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 6 | 小红 | 27 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 7 | 小刚 | 32 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 8 | 莉莉 | 29 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 9 | 华华 | 31 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
| 10 | 芳芳 | 26 | 2026-03-06 15:53:00 | 2026-03-06 15:53:00 |
+----+--------+------+---------------------+---------------------+
10 rows in set (0.00 sec)
-
truncate table test.test;
mysql > truncate table test; -
insert test data again
mysql > INSERT INTO test (name, age) VALUES
('张三', 25),
('李四', 30),
('王五', 28),
('赵六', 35),
('小明', 22),
('小红', 27),
('小刚', 32),
('莉莉', 29),
('华华', 31),
('芳芳', 26);
source mysql binlog events:
-- create table events
mysql> show binlog events in 'test-mysql-mysql-0-bin.001727' from 107015 limit 2;
+-------------------------------+--------+------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------------------+--------+------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test-mysql-mysql-0-bin.001727 | 107015 | Query | 1 | 107457 | use test; CREATE TABLE test ( id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID', name VARCHAR(50) NOT NULL COMMENT '姓名', age INT COMMENT '年龄', create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间' ) COMMENT '测试表' /* xid=70883192 */ |
| test-mysql-mysql-0-bin.001727 | 107457 | Gtid | 1 | 107536 | SET @@SESSION.GTID_NEXT= 'ac7a1db7-fcc3-11f0-9d4a-26f21a5f0ad7:3114764' |
+-------------------------------+--------+------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
-- first write_rows event
mysql> show binlog events in 'test-mysql-mysql-0-bin.001727' from 114725 limit 5;
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
| test-mysql-mysql-0-bin.001727 | 114725 | Gtid | 1 | 114804 | SET @@SESSION.GTID_NEXT= 'ac7a1db7-fcc3-11f0-9d4a-26f21a5f0ad7:3114787' |
| test-mysql-mysql-0-bin.001727 | 114804 | Query | 1 | 114887 | BEGIN |
| test-mysql-mysql-0-bin.001727 | 114887 | Table_map | 1 | 114948 | table_id: 219 (test.test) |
| test-mysql-mysql-0-bin.001727 | 114948 | Write_rows | 1 | 115243 | table_id: 219 flags: STMT_END_F |
| test-mysql-mysql-0-bin.001727 | 115243 | Xid | 1 | 115274 | COMMIT /* xid=70883722 */ |
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
5 rows in set (0.00 sec)
-- second write_rows event
mysql> show binlog events in 'test-mysql-mysql-0-bin.001727' from 173277 limit 5;
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
| test-mysql-mysql-0-bin.001727 | 173277 | Gtid | 1 | 173356 | SET @@SESSION.GTID_NEXT= 'ac7a1db7-fcc3-11f0-9d4a-26f21a5f0ad7:3114972' |
| test-mysql-mysql-0-bin.001727 | 173356 | Query | 1 | 173439 | BEGIN |
| test-mysql-mysql-0-bin.001727 | 173439 | Table_map | 1 | 173500 | table_id: 220 (test.test) |
| test-mysql-mysql-0-bin.001727 | 173500 | Write_rows | 1 | 173795 | table_id: 220 flags: STMT_END_F |
| test-mysql-mysql-0-bin.001727 | 173795 | Xid | 1 | 173826 | COMMIT /* xid=70887894 */ |
+-------------------------------+--------+------------+-----------+-------------+-------------------------------------------------------------------------+
5 rows in set (0.00 sec)
backup status:
$ kubectl get backup -n test-mysql 44b2e4cb-test-mysql-mysql-back-archive-binlog -o yaml | yq '.status.timeRange'
{
"end": "2026-03-09T06:08:22Z",
"start": "2026-03-01T05:59:36Z"
}
$ ku get backup -n test-mysql
NAME POLICY METHOD REPO STATUS TOTAL-SIZE DURATION DELETION-POLICY CREATION-TIME COMPLETION-TIME EXPIRATION-TIME
44b2e4cb-test-mysql-mysql-back-archive-binlog test-mysql-mysql-backup-policy archive-binlog s3-mysql-backuprepo Running 38357842 Delete 2026-01-29T09:04:42Z
test-mysql-xtrabackup-20260301092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24932446 16s Delete 2026-03-01T09:25:00Z 2026-03-01T09:25:15Z 2026-03-09T09:25:15Z
test-mysql-xtrabackup-20260302092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24414849 16s Delete 2026-03-02T09:25:00Z 2026-03-02T09:25:15Z 2026-03-10T09:25:15Z
test-mysql-xtrabackup-20260303092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24050402 15s Delete 2026-03-03T09:25:00Z 2026-03-03T09:25:15Z 2026-03-11T09:25:15Z
test-mysql-xtrabackup-20260304092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24824132 16s Delete 2026-03-04T09:25:00Z 2026-03-04T09:25:16Z 2026-03-12T09:25:16Z
test-mysql-xtrabackup-20260305092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24694331 11s Delete 2026-03-05T09:25:00Z 2026-03-05T09:25:11Z 2026-03-13T09:25:11Z
test-mysql-xtrabackup-20260306092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 25271716 16s Delete 2026-03-06T09:25:00Z 2026-03-06T09:25:15Z 2026-03-14T09:25:15Z
test-mysql-xtrabackup-20260307092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 21139481 15s Delete 2026-03-07T09:25:00Z 2026-03-07T09:25:15Z 2026-03-15T09:25:15Z
test-mysql-xtrabackup-20260308092500 test-mysql-mysql-backup-policy xtrabackup s3-mysql-backuprepo Completed 24132706 16s Delete 2026-03-08T09:25:00Z 2026-03-08T09:25:16Z 2026-03-16T09:25:16Z
PITR recover settings:
$ cat pitr-test-mysql.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
name: test-mysql-pitr
namespace: test-mysql
annotations:
kubeblocks.io/restore-from-backup: '{"mysql":{"name":"44b2e4cb-test-mysql-mysql-back-archive-binlog","namespace":"test-mysql","volumeRestorePolicy":"Parallel","restoreTime":"2026-03-06T07:55:00Z"}}'
spec:
clusterDef: mysql
componentSpecs:
- name: mysql
componentDef: mysql-8.0
serviceVersion: 8.0.36
disableExporter: false
replicas: 2
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "1"
memory: 2Gi
schedulingPolicy:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/instance
operator: In
values:
- test-mysql
- key: apps.kubeblocks.io/component-name
operator: In
values:
- mysql
topologyKey: kubernetes.io/hostname
nodeSelector:
node-role.kubernetes.io/pg-worker: "true"
tolerations:- effect: NoSchedule
key: node-role.kubernetes.io/pg-worker
value: "true"
volumeClaimTemplates: - name: data
spec:
accessModes:- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: dr-db-disk-nvme
services:
- ReadWriteOnce
- effect: NoSchedule
- annotations:
external-dns.alpha.kubernetes.io/hostname: test-mysql-pitr.srv.xxxx.cn
componentSelector: mysql
name: internet
roleSelector: primary
serviceName: internet
spec:
ipFamilyPolicy: PreferDualStack
ports:- name: mysql
port: 3306
protocol: TCP
targetPort: mysql
type: LoadBalancer
terminationPolicy: Delete
topology: semisync
- name: mysql
dest mysql:
mysql> select * from test;
Empty set (0.00 sec)