Skip to content

Commit 62a5d64

Browse files
authored
Merge pull request #1139 from CaptTofu/mapping-update
Added an example of database and table mapping restoration
2 parents 629d7ef + ca518ff commit 62a5d64

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

Examples.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,3 +847,103 @@ The current implementation is simple and will improve in next releases.
847847
- When the `watch` command starts, it calls the `create_remote+delete command` sequence to make a `full` backup
848848
- Then it waits `watch-interval` time period and calls the `create_remote+delete` command sequence again. The type of
849849
backup will be `full` if `full-interval` expired after last full backup created and `incremental` if not.
850+
851+
## How to restore a database or table to a different name
852+
853+
This example will restore a remote backup of database, and restore it to another differently named database. As well, the example will also demonstrate restoring a backed up table restored to a different table name. NOTE: this process will also work for local backups
854+
855+
Assumptions are that s3 credentials are already set up in a file called `s3.xml`:
856+
857+
```
858+
<clickhouse>
859+
<s3>
860+
<endpoint-name>
861+
<endpoint>https://backup-bucket.s3.amazonaws.com</endpoint>
862+
<access_key_id>AKREDACTED</access_key_id>
863+
<secret_access_key>12345abcdefg</secret_access_key>
864+
</endpoint-name>
865+
</s3>
866+
</clickhouse>
867+
```
868+
869+
### Backup and restore a database to a different database name
870+
871+
A remote database backup of the database `test` is created, first for an entire database with the backup name of `test`:
872+
873+
`clickhouse-backup create test`
874+
875+
Confirmation of the backup once completed:
876+
877+
```
878+
clickhouse-backup list
879+
880+
test 21/04/2025 18:24:42 remote all:60.86MiB,data:60.70MiB,arch:60.85MiB,obj:2.50KiB,meta:0B,rbac:0B,conf:0B tar, regular
881+
```
882+
883+
The user wants to restore this table as `testnew`, using the remote backup named `test`:
884+
885+
```
886+
$ clickhouse-backup restore_remote --restore-database-mapping test:testnew test
887+
```
888+
889+
Confirmation on Clickhouse:
890+
891+
```
892+
:) show databases;
893+
894+
SHOW DATABASES
895+
896+
Query id: 5d42ae97-a521-4b60-8dc2-706b94416d78
897+
898+
┌─name───────────────┐
899+
1. │ INFORMATION_SCHEMA │
900+
2. │ default │
901+
3. │ information_schema │
902+
4. │ system │
903+
5. │ test │
904+
6. │ testnew │
905+
└────────────────────┘
906+
907+
```
908+
909+
910+
### Backup and restore a table to a different table name
911+
912+
In this example, a backup is made only of a table because in order to do this, only a table backup will work. In this example, the table name is `trips`, and is being restored using the name `trips2` to the same database the table-level backup was made, `test`,
913+
914+
First, the backup is made:
915+
916+
```$ clickhouse-backup create_remote test.trips```
917+
918+
Then confirmed:
919+
920+
```
921+
$ clickhouse-backup list
922+
923+
iB,meta:0B,rbac:0B,conf:0B tar, regular
924+
test 21/04/2025 18:24:42 remote all:60.86MiB,data:60.70MiB,arch:60.85MiB,obj:2.50KiB,meta:0B,rbac:0B,conf:0B tar, regular
925+
test.trips 21/04/2025 18:47:39 remote all:121.71MiB,data:121.41MiB,arch:121.71MiB,obj:5.81KiB,meta:0B,rbac:0B,conf:0B tar, regular
926+
```
927+
928+
Then restored using the table backup named `test.trips`:
929+
930+
```
931+
$ clickhouse-backup restore_remote --restore-table-mapping test:trips2 test.trips
932+
```
933+
934+
Then confirmed:
935+
936+
```
937+
:) show tables from test
938+
939+
SHOW TABLES FROM test
940+
941+
Query id: 9e8ed231-dc4b-499d-b02b-57a555a3d309
942+
943+
┌─name────────┐
944+
1. │ trips │
945+
2. │ trips2 │
946+
└─────────────┘
947+
948+
```
949+

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ OPTIONS:
740740
--environment-override value, --env value override any environment variable via CLI parameter
741741
--table value, --tables value, -t value Restore only database and objects which matched with table name patterns, separated by comma, allow ? and * as wildcard
742742
--restore-database-mapping value, -m value Define the rule to restore data. For the database not defined in this struct, the program will not deal with it.
743-
--restore-table-mapping value, --tm value Define the rule to restore data. For the table not defined in this struct, the program will not deal with it.
743+
--restore-table-mapping value, --tm value Define the rule to restore data. For the table not defined in this struct, the program will not deal with it. Note: only a table backup will work with this
744744
--partitions partition_id Restore backup only for selected partition names, separated by comma
745745
If PARTITION BY clause returns numeric not hashed values for partition_id field in system.parts table, then use --partitions=partition_id1,partition_id2 format
746746
If PARTITION BY clause returns hashed string values, then use --partitions=('non_numeric_field_value_for_part1'),('non_numeric_field_value_for_part2') format

0 commit comments

Comments
 (0)