Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add doc of snapshot #1062

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 485 additions & 0 deletions docs/MatrixOne/Develop/snapshot/mo-backup-snapshot.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions docs/MatrixOne/Develop/snapshot/snapshot-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 快照概述
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这章节里面要补充下快照备份的原理


数据库快照是一种高效的数据库备份和恢复技术,它提供了数据库在某一特定时间点的只读静态副本,帮助数据库管理员和开发者进行各种操作,同时确保数据的一致性和完整性。

MatrixOne 目前支持租户级别的快照备份恢复。

## 应用场景

数据库快照是一种强大的工具,可以在多种场景下提高数据库的可用性和性能。以下为快照的一些应用场景:

- **数据备份与恢复**:快照可以作为数据库备份的一种方式,它允许在不停止数据库服务的情况下创建数据库的只读副本,用于数据备份和恢复。

- **报表和数据分析**:在需要数据库保持静态状态进行报表生成或数据分析时,可以使用快照来避免影响在线事务处理。

- **开发和测试**:在开发新功能或测试系统前,可以通过快照创建数据库的一个副本,以便测试可以在不影响生产环境的情况下进行。

- **数据迁移**:在数据迁移过程中,可以使用快照来确保数据的一致性,避免迁移过程中的数据变更。

- **高危操作保护**:在执行可能对数据库稳定性造成影响的操作(如数据库升级、结构变更等)之前,可以创建快照,以便在操作失败时能够快速恢复。

## MatrixOne 支持快照

MatrixOne 支持以下两种方式进行租户级别的快照备份恢复:

- [sql 语句](sql-snapshot.md)
- [mo_br 工具](mo-backup-snapshot.md)
79 changes: 79 additions & 0 deletions docs/MatrixOne/Develop/snapshot/sql-snapshot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 使用 SQL 进行快照备份恢复

MatrixOne 支持以下两种方式进行租户级别快照备份恢复:

- sql 语句
- [mo_br 工具](mo-backup-snapshot.md)

本篇文档主要介绍如何使用 sql 语句来进行快照备份恢复。

## 开始前准备

- 已完成[单机部署 MatrixOne](../../Get-Started/install-standalone-matrixone.md)。

## 示例

创建一个名为 inventory 的表,用于存储商品库存信息

```sql
CREATE TABLE inventory (
item_id INT AUTO_INCREMENT PRIMARY KEY,
item_name VARCHAR(255) NOT NULL,
quantity_in_stock INT NOT NULL
);
INSERT INTO inventory (item_name, quantity_in_stock) VALUES ('Widget', 150);
INSERT INTO inventory (item_name, quantity_in_stock) VALUES ('Gadget', 200);
INSERT INTO inventory (item_name, quantity_in_stock) VALUES ('Doohickey', 80);

mysql> select * from inventory;
+---------+-----------+-------------------+
| item_id | item_name | quantity_in_stock |
+---------+-----------+-------------------+
| 1 | Widget | 150 |
| 2 | Gadget | 200 |
| 3 | Doohickey | 80 |
+---------+-----------+-------------------+
3 rows in set (0.01 sec)
```

由于业务原因,需要进行系统升级,为了防止升级过程造成数据丢失,在升级前我们可以为租户创建快照。

```sql
create snapshot sp1 for account acc1;
```

假设在一次系统升级中,inventory 表的数据不慎丢失了。幸运的是,我们有之前创建的快照。模拟数据丢失情况并恢复数据:

```sql
truncate table inventory;

mysql> select * from inventory;
Empty set (0.01 sec)
```

这时我们可以使用快照恢复数据并验证数据的一致性。

```sql
restore account acc1 FROM snapshot sp1;

mysql> select * from inventory;
+---------+-----------+-------------------+
| item_id | item_name | quantity_in_stock |
+---------+-----------+-------------------+
| 1 | Widget | 150 |
| 2 | Gadget | 200 |
| 3 | Doohickey | 80 |
+---------+-----------+-------------------+
3 rows in set (0.00 sec)
```

可以看到,数据成功恢复。

## 参考文档

对于快照相关的更多语法说明和支持范围可参考以下文档:

- [CREATE SNAPSHOT](../../Reference/SQL-Reference/Data-Definition-Language/create-snapshot.md)
- [DROP SNAPSHOT](../../Reference/SQL-Reference/Data-Definition-Language/drop-snapshot.md)
- [SHOW SNAPSHOTS](../../Reference/SQL-Reference/Data-Definition-Language/create-snapshot.md)
- [RESTORE ACCOUNT](../../Reference/SQL-Reference/Data-Definition-Language/restore-account.md)
1 change: 1 addition & 0 deletions docs/MatrixOne/Overview/matrixone-feature-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
| 触发器 TRIGGER | N |
| 时间调度器 EVENT SCHEDULER | N |
| 自定义函数 UDF | Y |
| 快照 SNAPSHOT | Y |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是写到这的,是写到备份与恢复的地方

| 物化视图 Materialized VIEW | N |

## 流计算
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# CREATE SNAPSHOT

## 语法说明

`CREATE SNAPSHOT` 命令用于创建快照。系统租户可以给自己也可以给普通租户创建快照,但是普通租户只能给自己创建快照。租户创建的快照仅本租户可见。

## 语法结构

```sql
> CREATE SNAPSHOT snapshot_name FOR ACCOUNT account_name
```

## 示例

```sql
--在系统租户 sys 下执行
create snapshot sp1 for account sys;
create snapshot sp2 for account acc1;

mysql> show snapshots;
+---------------+----------------------------+----------------+--------------+---------------+------------+
| SNAPSHOT_NAME | TIMESTAMP | SNAPSHOT_LEVEL | ACCOUNT_NAME | DATABASE_NAME | TABLE_NAME |
+---------------+----------------------------+----------------+--------------+---------------+------------+
| sp2 | 2024-05-10 09:49:08.925908 | account | acc1 | | |
| sp1 | 2024-05-10 09:48:50.271707 | account | sys | | |
+---------------+----------------------------+----------------+--------------+---------------+------------+
2 rows in set (0.00 sec)

--在租户 acc1 下执行
mysql> create snapshot sp3 for account acc2;--普通租户只能为自己建立快照
ERROR 20101 (HY000): internal error: only sys tenant can create tenant level snapshot for other tenant

create snapshot sp3 for account acc1;

mysql> show snapshots;
+---------------+----------------------------+----------------+--------------+---------------+------------+
| SNAPSHOT_NAME | TIMESTAMP | SNAPSHOT_LEVEL | ACCOUNT_NAME | DATABASE_NAME | TABLE_NAME |
+---------------+----------------------------+----------------+--------------+---------------+------------+
| sp3 | 2024-05-10 09:53:09.948762 | account | acc1 | | |
+---------------+----------------------------+----------------+--------------+---------------+------------+
1 row in set (0.00 sec)
```

## 限制

- 目前只支持创建租户级别的快照,不支持创建集群级别、数据库级别和表级别的快照。
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# DROP SNAPSHOT

## 语法说明

`DROP SNAPSHOT` 用于删除当前租户下创建的快照。

## 语法结构

```
> DROP SNAPSHOT snapshot_name;
```

## 示例

```sql
create snapshot sp1 for account sys;

mysql> show snapshots;
+---------------+----------------------------+----------------+--------------+---------------+------------+
| SNAPSHOT_NAME | TIMESTAMP | SNAPSHOT_LEVEL | ACCOUNT_NAME | DATABASE_NAME | TABLE_NAME |
+---------------+----------------------------+----------------+--------------+---------------+------------+
| sp1 | 2024-05-10 09:55:11.601605 | account | sys | | |
+---------------+----------------------------+----------------+--------------+---------------+------------+
1 row in set (0.01 sec)

drop snapshot sp1;

mysql> show snapshots;
Empty set (0.01 sec)
```
Loading
Loading