This page describes the Backups page and how to restore your data.
Cockroach Labs runs full backups daily and incremental backups hourly for every CockroachCloud cluster. The full backups are retained for 30 days, while incremental backups are retained for 7 days.
The backups that Cockroach Labs runs for you can be viewed on the Backups page.
Currently, you can only restore databases and tables to the same cluster that the backup was taken from.
In the meantime, you can back up and restore data manually or back up from a self-hosted CockroachDB cluster and restore into a CockroachCloud cluster.
Backups page
A list of your full cluster backups displays on your cluster's Backups page.
For each backup, the following details display:
- The date and time the backup was taken (Data From)
- The Status of the backup
- The Type of backup
- The Size of the backup
- The remaining number of days the backup will be retained (Expires In)
The number of Databases included in the backup
To view the databases included in the backup, click the number in the Databases column.
Databases
To view the databases included in the backup, click the number in the Databases column on the cluster view of the Backups page.
For each database in the backup, the following details display:
- The Name of the database
The Size of the database data captured in the backup
Note:If the Size listed for a database in an incremental backup is 0 B, it means no changes were made in the database since the last full backup.
The number of Tables in the database
To view the tables in the database, click the number in the Tables column.
To restore a database, click Restore in the corresponding row.
If a database does not contain tables, it will not display in the Databases view.
Tables
To view the tables in a database, click the number in the Tables column on the Databases page.
For each table in the database, the following details display:
- The Name of the table
The Size of the table data captured in the backup
Note:If the Size listed for a table in an incremental backup is 0.00 B, it means no changes were made in the table since the last full backup.
The number of Rows captured in the backup
Ways to restore data
Console Admin can perform the following from the Console:
Additional ways to restore data:
- Back up a self-hosted CockroachDB cluster and restore into a CockroachCloud cluster
- Back up and restore data manually
Restore a database
To restore a database:
- Find the cluster backup containing the database you want to restore, and click the number in the corresponding Databases column.
In the Databases view, click Restore for the database you want to restore.
The Restore database module displays with backup details.
In the Restore to field, enter the name of the destination database.
Note:Resolve any naming conflicts by using
DROP
orRENAME
on the existing database. If you enter a unique name in the Restore to field, a new database will be created.Select any of the Dependency options to skip. You can:
- Skip missing foreign keys, which will remove missing foreign key constraints (i.e., when the referenced table is not in the backup or is not being restored) before restoring.
- Skip missing sequences, which will ignore sequence dependencies (i.e., the
DEFAULT
expression that uses the sequence). - Skip missing views, which will skip restoring views that cannot be restored because their dependencies are not being restored at the same time.
Click Continue
Once you have reviewed the restore details, click Restore.
When the restore job has been created successfully, you will be taken to the Restore Jobs tab, which will show you the status of your restore.
When the restore is complete, be sure to set any database-specific zone configurations and, if applicable, grant privileges.
Restore a table
To restore a table:
- Find the cluster backup containing the table you want to restore, and click the number in the corresponding Databases column.
In the Databases view, find the database containing the table you want to restore, and click the number in the corresponding Tables column.
The Tables view displays.
Click Restore for the table you want to restore.
The Restore table module displays with backup details.
In the Restore to field, enter the name of the destination database.
Note:Resolve any naming conflicts by using
DROP
orRENAME
on the existing table. If you enter a unique name in the Restore to field, a new table will be created.Select any of the Dependency options to skip. You can:
- Skip missing foreign keys, which will remove missing foreign key constraints (i.e., when the referenced table is not in the backup or is not being restored) before restoring.
- Skip missing sequences, which will ignore sequence dependencies (i.e., the
DEFAULT
expression that uses the sequence). - Skip missing views, which will skip restoring views that cannot be restored because their dependencies are not being restored at the same time.
Click Continue
Once you have reviewed the restore details, click Restore.
When the restore job has been created successfully, you will be taken to the Restore Jobs tab, which will show you the status of your restore.
Back up a self-hosted CockroachDB cluster and restore into a CockroachCloud cluster
To back up a self-hosted CockroachDB cluster into a CockroachCloud cluster:
While connected to your self-hosted CockroachDB cluster, back up your databases and/or tables to an external location:
> BACKUP DATABASE example_database TO 'gs://bucket_name/path_to_backup?AUTH=specified';
Warning:If you are backing up the data to AWS or GCP, use the
specified
option for theAUTH
parameter, as CockroachCloud will need thespecified
credentials uponRESTORE
.Connect to your CockroachCloud cluster:
$ cockroach sql \ --url='postgres://<username>:<password>@<global host>:26257/<database>?sslmode=verify-full&sslrootcert=<path to the CA certificate>'
Restore to your CockroachCloud cluster:
> RESTORE DATABASE example_database FROM 'gs://bucket_name/path_to_backup?AUTH=specified';
Back up and restore data manually
Additionally, you can back up and restore your Cockroach Cloud data manually:
Connect to your CockroachCloud cluster:
$ cockroach sql \ --url='postgres://<username>:<password>@<global host>:26257/<database>?sslmode=verify-full&sslrootcert=<path to the CA certificate>'
Back up your databases and/or tables to an external location:
> BACKUP DATABASE example_database TO 'gs://bucket_name/path_to_backup?AUTH=specified';
Warning:If you are backing up the data to AWS or GCP, use the
specified
option for theAUTH
parameter.To restore to your CockroachCloud cluster:
> RESTORE DATABASE example_database FROM 'gs://bucket_name/path_to_backup?AUTH=specified';
Troubleshooting
Resolve a database naming conflict
The databases you want to restore cannot have the same name as an existing database in the target cluster. Before you restore a database, verify that the database name is not already in use. To do this, connect to the target cluster with the CockroachDB SQL client and run the following:
> SHOW DATABASES;
If the database's name is already in use, either drop the existing database:
> DROP DATABASE example_database;
Or change the existing database's name:
> ALTER DATABASE example_database RENAME TO archived_example_database;
Resolve a table naming conflict
The table you want to restore cannot have the same name as an existing table in the target database. Before you restore a table, verify that the table name is not already in use. To do this, connect to the target cluster with the CockroachDB SQL client and run the following:
> SHOW TABLES FROM database_name;
If the table's name is already in use, either drop the existing table:
> DROP TABLE target_database.example_table;
Or change the existing table's name:
> ALTER TABLE target_database.example_table RENAME TO target_database.archived_example_table;