'Using CockroachDB's RESTORE command, how can I restore a database into another database name?

I have a backup of a CockroachDB database named foo, and I would like to restore it on my cluster but have the database name be bar. When I try RESTORE DATABASE foo ... WITH into_db=bar, I get an error cannot use "into_db" option when restoring database(s). What's the right way to do this, then?



Solution 1:[1]

into_db can only be applied at the table level, but there's a simple workaround--apply it to the wildcard expansion of all tables:

RESTORE TABLE foo.* ... WITH into_db=bar

is valid and will do what you want.

In the upcoming 22.1 release, you'll instead be able to do

RESTORE DATABASE foo ... WITH new_db_name=bar -- 22.1+ only

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1