Skip to content

Commit a4486ec

Browse files
authored
Merge 179be64 into a6070b7
2 parents a6070b7 + 179be64 commit a4486ec

File tree

6 files changed

+307
-7
lines changed

6 files changed

+307
-7
lines changed

ydb/docs/en/core/reference/ydb-cli/export-import/_includes/file_structure.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,33 @@ Each database directory has a corresponding directory in the file structure. Eac
4343

4444
## Tables {#tables}
4545

46-
For each table in the database, there's a same-name directory in the file structure's directory hierarchy that includes:
46+
For each table in the database, there is a same-named directory in the file structure of the backup that includes:
4747

4848
- The `scheme.pb` file describing the table structure and parameters in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
49-
- The `permissions.pb` file describes the table ACL and owner in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
49+
- The `permissions.pb` file specifying the table owner and ACL in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
5050
- One or more `data_XX.csv` files with the table data in `csv` format, where `XX` is the file's sequence number. The export starts with the `data_00.csv` file, with a next file created whenever the current file exceeds 100 MB
5151
- Directories describing the [changefeeds](https://ydb.tech/docs/en/concepts/cdc). Directory names match the names of the changefeeds. Each directory contains the following files:
5252
- The `changefeed_description.pb` file describing the changefeed in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
5353
- The `topic_description.pb` file describing the underlying topic in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
5454

5555

56-
## Files with data {#datafiles}
56+
### Files with data {#datafiles}
5757

5858
The format of data files is `.csv`, where each row corresponds to a record in the table (except the row with column headings). The urlencoded format is used for rows. For example, the file row for the table with the uint64 and utf8 columns that includes the number 1 and the Russian string "Привет" (translates to English as "Hi"), would look like this:
5959

6060
```text
6161
1,"%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82"
6262
```
6363

64+
## Views {#views}
65+
66+
For each [view](../../../../concepts/datamodel/view.md) in the database, there is a same-named directory in the file structure of the backup that includes:
67+
68+
- The `create_view.sql` file containing the view's definition in plain-text YQL format (as a [CREATE VIEW](../../../../yql/reference/syntax/create-view.md) query)
69+
- The `permissions.pb` file specifying the view owner and ACL in the [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format) format
70+
71+
The relative positioning of views and the objects they reference is preserved during restoration. For more details, see the article [{#T}](../view-backup.md).
72+
6473
## Checksums {#checksums}
6574

6675
{% note info %}

ydb/docs/en/core/reference/ydb-cli/export-import/toc_i.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
items:
2-
- name: File structure of data export
2+
- name: File structure of an export
33
href: file-structure.md
44
- name: Exporting data to the file system
55
href: tools-dump.md
@@ -12,4 +12,6 @@ items:
1212
- name: Importing data from S3
1313
href: import-s3.md
1414
- name: Importing data from a file to an existing table
15-
href: import-file.md
15+
href: import-file.md
16+
- name: Considerations for restoring views
17+
href: view-backup.md
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Considerations for restoring views from backups
2+
3+
During the restoration of [views](../../../concepts/datamodel/view.md) from a backup, the system may automatically adjust the underlying query to ensure object references remain valid. Restored views will reference the restored tables rather than the previously existing tables in the target environment, preserving the relative positioning between views and their referenced objects as they existed at backup time.
4+
5+
## Examples
6+
7+
### Restoring the database root to the same path
8+
9+
Let's consider the following scenario:
10+
11+
1. A view is created using the following query:
12+
13+
```sql
14+
CREATE VIEW root_view WITH security_invoker = TRUE AS
15+
SELECT * FROM root_table;
16+
```
17+
18+
2. The database is backed up:
19+
20+
```bash
21+
ydb tools dump --path . --output ./my_backup
22+
```
23+
24+
3. The database is cleared:
25+
26+
```bash
27+
ydb scheme rmdir --force --recursive .
28+
```
29+
30+
4. The database is restored:
31+
32+
```bash
33+
ydb tools dump --path . --input ./my_backup
34+
```
35+
36+
As the result of the steps described above, the `root_view` view is restored and selects from the `root_table` table:
37+
38+
```bash
39+
ydb sql --script 'select * from root_view' --explain
40+
```
41+
42+
The output of the command includes: `TableFullScan (Table: root_table, ...`
43+
44+
### Restoring the database root to a subfolder
45+
46+
Let's consider the following scenario:
47+
48+
1. A view is created using the following query:
49+
50+
```sql
51+
CREATE VIEW my_view WITH security_invoker = TRUE AS
52+
SELECT * FROM my_table;
53+
```
54+
55+
2. The database is backed up:
56+
57+
```bash
58+
ydb tools dump --path . --output ./my_backup
59+
```
60+
61+
3. The database is restored to the `a/b/c` subfolder:
62+
63+
```bash
64+
ydb tools restore --path a/b/c --input ./my_backup
65+
```
66+
67+
As the result of the steps described above, the `a/b/c/my_view` view is restored and selects from the `a/b/c/my_table` table:
68+
69+
```bash
70+
ydb sql --script 'select * from `a/b/c/my_view`' --explain
71+
```
72+
73+
The output of the command includes: `TableFullScan (Table: a/b/c/my_table, ...`
74+
75+
### Restoring a subfolder to the database root
76+
77+
Let's consider the following scenario:
78+
79+
1. The steps 1 to 3 of the previous scenario [{#T}](#restoring-the-database-root-to-a-subfolder) are repeated.
80+
2. The `a/b/c` subfolder of the database is backed up:
81+
82+
```bash
83+
ydb tools dump --path a/b/c --output ./subfolder_backup
84+
```
85+
86+
3. The database is cleared:
87+
88+
```bash
89+
ydb scheme rmdir --force --recursive .
90+
```
91+
92+
4. The subfolder backup is restored to the root of the database:
93+
94+
```bash
95+
ydb tools restore --path . --input ./subfolder_backup
96+
```
97+
98+
As the result of the steps described above, the `my_view` view is restored and selects from the `my_table` table:
99+
100+
```bash
101+
ydb sql --script 'select * from my_view' --explain
102+
```
103+
104+
The output of the command includes: `TableFullScan (Table: my_table, ...`
105+
106+
### Restoring the database root to the root of a different database
107+
108+
Let's consider the following scenario:
109+
110+
1. A view is created using the following query:
111+
112+
```sql
113+
CREATE VIEW root_view WITH security_invoker = TRUE AS
114+
SELECT * FROM root_table;
115+
```
116+
117+
2. The database is backed up:
118+
119+
```bash
120+
ydb --endpoint <endpoint> --database /my_database tools dump --path . --output ./my_backup
121+
```
122+
123+
Note the `--database /my_database` option in the connection string.
124+
125+
3. The database backup is restored to a different database:
126+
127+
```bash
128+
ydb --endpoint <endpoint> --database /restored_database tools dump --path . --input ./my_backup
129+
```
130+
131+
Note the `--database /restored_database` option in the connection string.
132+
133+
As the result of the steps described above, the `root_view` view is restored and selects from the `root_table` table located in the `/restored_database`:
134+
135+
```bash
136+
ydb --endpoint <endpoint> --database /restored_database sql --script 'select * from root_view' --explain
137+
```
138+
139+
The output of the command includes: `TableFullScan (Table: root_table, ...`

ydb/docs/ru/core/reference/ydb-cli/export-import/_includes/file-structure.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
## Таблицы {#tables}
4545

46-
Каждой таблице в базе данных также соответствует одноименная директория в иерархии директорий файловой структуры, в которой находятся:
46+
Каждой таблице в базе данных соответствует одноимённая директория в файловой структуре, в которой находятся:
4747

4848
- Файл `scheme.pb`, содержащий информацию о структуре таблицы и её параметрах в формате [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format)
4949
- Файл `permissions.pb`, содержащий информацию об ACL таблицы и её владельце в формате [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format)
@@ -52,14 +52,23 @@
5252
- Файл `changefeed_description.pb`, содержащий информацию о потоке изменений в формате [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format)
5353
- Файл `topic_description.pb`, содержащий информацию о нижележащем топике в формате [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format)
5454

55-
## Файлы с данными {#datafiles}
55+
### Файлы с данными {#datafiles}
5656

5757
Формат файлов с данными - `.csv`, одна строка соответствует одной записи в таблице, без строки с заголовками колонок. Для строк применяется представление в urlencoded формате. Например, строка файла для таблицы с колонками uint64 и utf8, содержащая число 1 и строку "Привет" соответственно, выглядит таким образом:
5858

5959
```text
6060
1,"%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82"
6161
```
6262

63+
## Представления (views) {#views}
64+
65+
Каждому [представлению](../../../../concepts/datamodel/view.md) в базе данных соответствует одноимённая директория в файловой структуре, в которой находятся:
66+
67+
- Файл `create_view.sql`, содержащий определение представления в виде текста YQL-запроса [CREATE VIEW](../../../../yql/reference/syntax/create-view.md)
68+
- Файл `permissions.pb`, содержащий информацию об ACL представления и его владельце в формате [text protobuf](https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format)
69+
70+
Взаимное расположение представлений и объектов, на которые они ссылаются, сохраняется при восстановлении. Подробнее читайте в статье [{#T}](../view-backup.md).
71+
6372
## Контрольные суммы {#checksums}
6473

6574
{% note info %}

ydb/docs/ru/core/reference/ydb-cli/export-import/toc_i.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ items:
1313
href: import-s3.md
1414
- name: Импорт данных из файла в существующую таблицу
1515
href: import-file.md
16+
- name: Особенности восстановления представлений
17+
href: view-backup.md
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Особенности восстановления представлений из резервных копий
2+
3+
При восстановлении [представлений](../../../concepts/datamodel/view.md) из резервной копии запрос представления может быть автоматически изменён для сохранения корректности ссылок на объекты схемы. Восстановленные из резервной копии представления будут ссылаться на восстановленные таблицы, а не на ранее существовавшие в целевой базе таблицы. Взаимное расположение представлений и объектов, на которые они ссылаются, сохраняется таким, каким оно было во время создания резервной копии.
4+
5+
## Примеры
6+
7+
### Восстановление корня базы данных по тому же пути {#example-root-root}
8+
9+
Рассмотрим следующий сценарий:
10+
11+
1. Создаётся представление:
12+
13+
```sql
14+
CREATE VIEW root_view WITH security_invoker = TRUE AS
15+
SELECT * FROM root_table;
16+
```
17+
18+
2. Создаётся резервная копия базы:
19+
20+
```bash
21+
ydb tools dump --path . --output ./my_backup
22+
```
23+
24+
3. Выполняется очистка базы данных:
25+
26+
```bash
27+
ydb scheme rmdir --force --recursive .
28+
```
29+
30+
4. База данных восстанавливается:
31+
32+
```bash
33+
ydb tools dump --path . --input ./my_backup
34+
```
35+
36+
В результате описанных выше шагов представление `root_view` восстанавливается и читает из таблицы `root_table`:
37+
38+
```bash
39+
ydb sql --script 'select * from root_view' --explain
40+
```
41+
42+
В выводе выполненной команды отображается: `TableFullScan (Table: root_table, ...`
43+
44+
### Восстановление корня базы данных в подпапку {#example-root-subfolder}
45+
46+
Рассмотрим следующий сценарий:
47+
48+
1. Создаётся представление:
49+
50+
```sql
51+
CREATE VIEW my_view WITH security_invoker = TRUE AS
52+
SELECT * FROM my_table;
53+
```
54+
55+
2. Создаётся резервная копия базы:
56+
57+
```bash
58+
ydb tools dump --path . --output ./my_backup
59+
```
60+
61+
3. База данных восстанавливается в подпапку `a/b/c`:
62+
63+
```bash
64+
ydb tools restore --path a/b/c --input ./my_backup
65+
```
66+
67+
В результате описанных выше шагов представление `a/b/c/my_view` восстанавливается и читает из таблицы `a/b/c/my_table`:
68+
69+
```bash
70+
ydb sql --script 'select * from `a/b/c/my_view`' --explain
71+
```
72+
73+
В выводе выполненной команды отображается: `TableFullScan (Table: a/b/c/my_table, ...`
74+
75+
### Восстановление подпапки в корень базы данных {#example-subfolder-root}
76+
77+
Рассмотрим следующий сценарий:
78+
79+
1. Повторяются шаги 1-3 предыдущего сценария [{#T}](#example-root-subfolder).
80+
2. Создаётся резервная копия подпапки `a/b/c` базы данных:
81+
82+
```bash
83+
ydb tools dump --path a/b/c --output ./subfolder_backup
84+
```
85+
86+
3. Выполняется очистка базы данных:
87+
88+
```bash
89+
ydb scheme rmdir --force --recursive .
90+
```
91+
92+
4. Резервная копия подпапки восстанавливается в корень базы данных:
93+
94+
```bash
95+
ydb tools restore --path . --input ./subfolder_backup
96+
```
97+
98+
В результате описанных выше шагов представление `my_view` восстанавливается и читает из таблицы `my_table`:
99+
100+
```bash
101+
ydb sql --script 'select * from my_view' --explain
102+
```
103+
104+
В выводе выполненной команды отображается: `TableFullScan (Table: my_table, ...`
105+
106+
### Восстановление корня базы данных в корень другой базы данных {#example-root-different-root}
107+
108+
Рассмотрим следующий сценарий:
109+
110+
1. Создаётся представление:
111+
112+
```sql
113+
CREATE VIEW root_view WITH security_invoker = TRUE AS
114+
SELECT * FROM root_table;
115+
```
116+
117+
2. Создаётся резервная копия базы:
118+
119+
```bash
120+
ydb --endpoint <endpoint> --database /my_database tools dump --path . --output ./my_backup
121+
```
122+
123+
Обратите внимание на `--database /my_database` в строке подключения.
124+
125+
3. Резервная копия базы данных восстанавливается в другую базу данных:
126+
127+
```bash
128+
ydb --endpoint <endpoint> --database /restored_database tools dump --path . --input ./my_backup
129+
```
130+
131+
Обратите внимание на `--database /restored_database` в строке подключения.
132+
133+
В результате описанных выше шагов представление `root_view` восстанавливается и читает из таблицы `root_table`, расположенной в `/restored_database`:
134+
135+
```bash
136+
ydb --endpoint <endpoint> --database /restored_database sql --script 'select * from root_view' --explain
137+
```
138+
139+
В выводе выполненной команды отображается: `TableFullScan (Table: root_table, ...`

0 commit comments

Comments
 (0)