This page describes how to restore a Cloud SQL Postgres database from one of the automated daily backups that Nais takes of your instance.

Cloud SQL keeps the last seven daily backups by default. You can restore a backup either in-place (overwriting the current instance) or into a separate instance (to inspect the data without touching production).

Before you begin ¶

  • Install and authenticate the gcloud CLI, or use the Google Cloud Console.
  • naisdevice connected.
  • You need access to the GCP project where the instance runs. Your team has full access to view and restore backups for its own instances.

The instance name defaults to your application name. If you are unsure of the instance name or project, find them in the Cloud SQL dashboard or in your nais.yaml.

When using gcloud, set the project you are working in:

bash

Find the backup to restore ¶

List the available backups and note the ID of the one you want:

bash

Example output:

Plaintext

Go to the instance's backups page and note the backup you want to restore:

Plaintext

Restore in-place (same instance) ¶

Use this when you want to roll the production database back to an earlier state.

bash

Confirm the prompt to start the restore. The command returns once the operation is queued; you can follow its progress with:

bash
  1. Go to https://console.cloud.google.com/sql/instances/<instance-name>/backups.
  2. Find the backup you want and click Restore.
  3. In Choose restore destination, select Overwrite the source instance.
  4. Enter the instance name to confirm, then click Restore.

Start the application again once the restore completes:

bash

Verify that the application is running and that the data is as expected.

Restore into a separate instance ¶

Use this when you want to inspect or extract data from a backup without affecting the running database — for example to recover a few accidentally deleted rows.

Restore a backup taken from the source instance into an existing target instance:

bash
  1. Go to https://console.cloud.google.com/sql/instances/<source-instance-name>/backups.
  2. Find the backup you want and click Restore.
  3. In Choose restore destination, select the existing target instance.
  4. Confirm to start the restore.

Troubleshooting ¶

If a restore fails, the current data on the instance is left unchanged. Check the failed operation for the reason:

bash

Common causes are a target instance with a smaller disk or a different Postgres major version than the backup.

Further reading ¶