View a markdown version of this page

Backups and restore - AWS Amplify

Backups and restore

AWS Amplify keeps continuous automated backups of the PostgreSQL database in each backend branch of your Amplify backend. You don’t need to turn them on. You can restore the production environment’s database to any point in its restore window. A restore copies the database as it was at that time into a new backend branch, and leaves production as it is. You then copy the rows you need back into production.

Set how far back you can restore

backupRetentionDays is the number of days of backups that an environment keeps. In production, it’s also how far back a restore can go, after a deployment to production applies it. A longer value doesn’t bring back times whose backups had already expired, so the window reaches the new length as new backups accrue. A new backend starts at 1 day. You can set a value from 1 day up to your plan’s limit: 7 days on Pro and 14 days on Pro Plus. env edit returns an error for a value over your plan’s limit. A deployment with a value over the limit fails with CONFIG_RETRIEVAL_FAILED. For each plan’s limit, see Pricing and spend limits. The free plan can’t restore at all: aws amplifygen3 backend restore fails with The Amplify Basic plan does not include point-in-time restore.

Set it in the backend.database block of amplify.jsonc:

{ "name": "my-app", "backend": { "database": { "backupRetentionDays": 7 } // every environment }, "env": { "production": { "backend": { "database": { "backupRetentionDays": 14 } // production only } } } }

To store the value on an environment instead, run the following command:

aws amplifygen3 env edit --env production --backup-retention-days 14

The next deployment to the environment applies the value. A deployment uses the first value it finds, in this order: the environment’s block, the root block, then the value that env edit stored. The deployment waits in its Migration step while the database applies the change. The database can restart during the change. To see the applied and stored values, run aws amplifygen3 env get --env production.

Restore production to a point in time

  1. Run the following command to show the earliest and latest times that you can restore to:

    aws amplifygen3 backend restore-window

    The earliest time is never before the first completed deployment to production. The latest time moves forward as Amplify backs up the database. Until production has backups and a completed deployment, there is no window: restore-window says so, and a restore is refused with the prod branch has no restorable window yet.

  2. Run the following command to start the restore. Give the time in ISO 8601 format. Amplify reads a time without a time zone as UTC. Amplify refuses a time in the future or outside the window, and creates no branch.

    aws amplifygen3 backend restore --restore-to-time 2026-11-18T14:30:00Z

    Amplify creates a backend branch in production named production-<epoch seconds>, and restores the data into it in the background. If you restore the same time again, the command returns the same branch.

  3. Run the following commands, and wait until the branch status is READY. For each status, see Restored branch status.

    aws amplifygen3 branch list --env production aws amplifygen3 branch get --name <restored-branch-name> --env production

    Note the branch ARN in the branch get output. You need it to copy the data.

Note

Note: A restore needs a running backend. If the backend is paused, run aws amplifygen3 backend resume first. For more information about paused backends, see Capacity.

Copy restored data into production

Deployments to production keep using the production branch, so your app sees the restored data only after you copy it back.

  1. Run the following command to check the restored data:

    aws amplifygen3 db query --branch-arn <restored-branch-arn> "select count(*) from public.notes"
  2. Run the following command to dump the rows that you need. Replace public.notes with your table.

    aws amplifygen3 db dump --branch-arn <restored-branch-arn> \ --data-only --table public.notes --output-file notes.sql
  3. Load the file into production with psql. For more information about connecting with psql, see Connect to your database.

  4. Run the following command to delete the restored branch. The branch counts against your account’s branch limit until you delete it.

    aws amplifygen3 branch delete --name <restored-branch-name> --env production

production has two branches until you delete the restored one. Until then, the db, backend user and backend publishable-key commands need --branch-arn to choose a branch. A command run without --branch-arn shows a menu in a terminal. When CI=true is set, it exits with status 252 and lists both ARNs.

Keep your own copy

aws amplifygen3 db dump runs pg_dump and writes your tables to a file. A website rollback leaves the database as it is. Run the following command to save a copy before a migration that changes or deletes data:

aws amplifygen3 db dump --env production --output-file production.sql

The dump doesn’t include your users' accounts. For more information about the pg_dump client, see Connect to your database.

Warning

Warning: When you delete the app, or remove the backend with aws amplifygen3 deploy --allow-destroy, Amplify deletes every database and its backups. Save a dump of the data that you want to keep first.

Restored branch status

Status Meaning

CREATING

The restore is copying the data.

READY

You can connect to the branch.

FAILED_TO_CREATE

The restore failed. Delete the branch and restore again.

For more information about which branch each deployment uses, see Environments.