Perform an in-place restore operation
This page describes how to restore data in a backup to a database with the same name as the source database of the backup. Before you read this page, you should be familiar with Back up and restore data.
In-place restore
An in-place restore lets you restore a database from a backup to the source database that created the backup while the original database still exists. An in-place restore helps you avoid rerouting traffic or creating a database with a different name.
A restore operation must use a destination database that doesn't already exist. You can, however, simulate an in-place restore by deleting the source database and then restoring from a backup to a new database with the same name as the source database.
Perform an in-place restore
Complete the following steps to perform an in-place restore operation:
- Identify the backup to use for the restore operation.
- Delete the existing database.
- Use the backup and the database ID of the deleted database to complete the restore operation.
This process requires downtime between the moment you delete the database and when the restore operation completes.
Once a restore operation begins, you cannot cancel the operation and must wait until the operation completes. The restore operation immediately occupies the database ID used in the operation.
Use the
gcloud alpha firestore backups list
command to identify the backup to use for the restore operation and note the resource name. The resource name uses the following format:projects/PROJECT_ID/locations/LOCATION/backups/BACKUP_ID
Use the
gcloud firestore databases delete
command to delete the existing database:gcloud firestore databases delete --database='DATABASE_ID'
Replace DATABASE_ID with the database ID.
Wait at least 5 minutes after you delete the database for the database ID to become available again. Initiate a restore operation using the
gcloud alpha firestore databases restore
command:gcloud alpha firestore databases restore \ --source-backup=projects/PROJECT_ID/locations/LOCATION/backups/BACKUP_ID \ --destination-database='DATABASE_ID'
Replace DATABASE_ID with the database ID.