# RESTORE SNAPSHOT into new table name

**URL:** https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167
**Category:** CrateDB
**Created:** [March 9, 2019, 1:21pm UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167 "2019-03-09T13:21:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![web64](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/web64/32/85_2.png) [@web64](https://community.cratedb.com/u/web64)
#### Post date: [March 9, 2019, 1:21pm UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167/1 "2019-03-09T13:21:27Z")

</div>

I’m moving a table from an old cluster to a new one.

In the new cluster, I have already created a new version of the table with updated fields indexes etc.

I would like to restore a backed up version of the table into something like “tablename\_bak”, then copy the relevant fields over to the new table.

Is it possible to specify the table name you want to restore the table into, or can it only be restored into the original table name, and restore would fail if a table of that name already exists.

Would it be possible to do something like this:

```sql
RESTORE SNAPSHOT s3_crate_snaps."snapshot1" TABLE schemaname.tablename AS tablename_bak WITH (wait_for_completion=true); 

```

---

<div class="post-metadata">

### Author: ![Baur](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/baur/32/284_2.png) [@Baur](https://community.cratedb.com/u/Baur)
#### Post date: [January 30, 2024, 4:23pm UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167/2 "2024-01-30T16:23:00Z")

</div>

Hi, this feature is available starting from CrateDB 5.6

See docs for options `schema_rename_pattern`, `schema_rename_replacement`, `table_rename_pattern` and `table_rename_replacement` in

> **[RESTORE SNAPSHOT](https://cratedb.com/docs/crate/reference/en/5.6/sql/statements/restore-snapshot.html#with)**
>
> Restore a snapshot into the cluster. Table of contents Synopsis, Description, Parameters, Clauses- PARTITION, WITH.. Synopsis: where data\_section: Description: Restore one or more tables, partitions, or metadata from an existing snapshot into the...

---

<div class="post-metadata">

### Author: ![cocoa](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/cocoa/32/783_2.png) [@cocoa](https://community.cratedb.com/u/cocoa)
#### Post date: [February 18, 2024, 5:35pm UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167/3 "2024-02-18T17:35:17Z")

</div>

Hi,

Would it be possible to have a practical example with the related SQL code?

For example, in S3 I have the snapshot of the ‘Alpha’ table.

I would like to do a restore but in a different table, called ‘Beta’.

Could you give me the correct RESTORE SNAPSHOT command to do this?

Thank you.  
Luca

---

<div class="post-metadata">

### Author: ![proddata](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/proddata/32/1379_2.png) [@proddata](https://community.cratedb.com/u/proddata)
#### Post date: [February 18, 2024, 6:35pm UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167/4 "2024-02-18T18:35:08Z")

</div>

Not sure if you can directly change the name. You could try  
`"table_rename_replacement" = 'Beta'`

otherwise use a prefix, e.g.:

```sql
RESTORE SNAPSHOT my_repo.my_snap
TABLE my_schema.my_table
WITH ("table_rename_replacement" = 'copy_$1');

```

→ `my_schema.copy_my_table`

and rename later

```sql
ALTER TABLE RENAME copy_my_table TO "Beta";

```

---

<div class="post-metadata">

### Author: ![Baur](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/baur/32/284_2.png) [@Baur](https://community.cratedb.com/u/Baur)
#### Post date: [February 19, 2024, 9:36am UTC](https://community.cratedb.com/t/restore-snapshot-into-new-table-name/167/5 "2024-02-19T09:36:04Z")

</div>

Hi, yes, you can restore into completely different table.

As @proddata mentioned above

> You could try  
> `"table_rename_replacement" = 'Beta'`

would do the trick

```auto
RESTORE SNAPSHOT my_repo.my_snap
TABLE my_schema.Alpha
WITH ("table_rename_replacement" = 'Beta');

```

Please note, that schema won’t be affected:  
Alpha → Beta (doc is implicit but fqn is doc.Alpha → doc.Beta)  
my\_schema.Alpha → my\_schema.Beta

If you want to change both schema and name, you can combine schema/table rename parameters.
