Sub topic 8
Backups, Snapshots, and Point-in-Time Restore
This chapter assumes you can create an RDS instance (covered earlier), use the AWS CLI, and understand basic database concepts such as transactions and write-ahead logs. By the end you will know how RDS protects your data, how to restore it, and where the common mistakes are.
Two kinds of backup
RDS offers two mechanisms. They protect against different failures and have different lifetimes.
| Property | Automated backups | Manual snapshots |
|---|---|---|
| Created by | RDS, on a daily schedule | You, on demand |
| Retention | 0 to 35 days (set per instance) | Until you delete them |
| Point-in-time restore | Yes, to any second inside the window | No, only to the snapshot moment |
| Deleted with the instance | Yes, unless you choose to retain them | No |
| Typical use | Recover from mistakes in the last days | Keep a copy before a risky change, or archive |
Both are stored by RDS in Amazon S3, in storage that you cannot browse. You see them only through the RDS console and API.
How automated backups work
Each day, during a backup window, RDS takes a storage-level snapshot of the instance volume. Between snapshots, RDS uploads the database's transaction logs to S3 about every five minutes. A restore combines the nearest earlier snapshot with the logs replayed up to the time you ask for.
Key facts about this design:
- The retention period is set with
--backup-retention-period. A value of0turns automated backups off, and this also disables point-in-time restore. The earlier provisioning example used7. - The backup window is a daily time range, such as
03:00-04:00UTC. If you do not choose one, RDS picks a default for your Region. - On Multi-AZ deployments the snapshot is taken from the standby, so the primary is not affected. On Single-AZ instances, the first snapshot can briefly suspend I/O for some engines. Choose a window when traffic is low.
- The latest restorable time normally lags the present by about five minutes, because it depends on the last uploaded log.
You can change retention on an existing instance:
aws rds modify-db-instance \
--db-instance-identifier demo-pg \
--backup-retention-period 14 \
--preferred-backup-window 03:00-04:00 \
--apply-immediatelyChanging retention between 0 and a non-zero value causes a brief outage on some engines, so check the documentation for your engine before doing it on a production system.
Manual snapshots
A manual snapshot copies the instance's storage at one moment. Create one before schema migrations, engine upgrades, or any change that is hard to undo.
aws rds create-db-snapshot \
--db-instance-identifier demo-pg \
--db-snapshot-identifier demo-pg-before-migration
aws rds wait db-snapshot-available \
--db-snapshot-identifier demo-pg-before-migrationSnapshots are incremental at the storage level. The first one holds the full volume, and later ones store only changed blocks, so many snapshots cost less than many full copies. You are billed for backup storage beyond the free allowance, which equals the size of your provisioned database storage in the Region.
Copying and sharing snapshots
Snapshots stay in their Region. To protect against a Regional failure, copy them elsewhere:
aws rds copy-db-snapshot \
--source-db-snapshot-identifier arn:aws:rds:us-east-1:111122223333:snapshot:demo-pg-before-migration \
--target-db-snapshot-identifier demo-pg-before-migration-copy \
--source-region us-east-1 \
--kms-key-id alias/aws/rds \
--region us-west-2Encryption affects copying and sharing:
- A snapshot of an encrypted instance is encrypted with the same KMS key.
- To copy it to another Region, you must name a KMS key in the destination Region.
- To share an encrypted snapshot with another account, it must use a customer managed KMS key, and you must grant the other account access to that key. Snapshots encrypted with the default
aws/rdskey cannot be shared. - You can encrypt an unencrypted database by copying its snapshot with a KMS key and restoring from the copy.
Restoring: always a new instance
Both restore operations create a new DB instance with a new endpoint. RDS never overwrites the source. This is safe, but it means that a restore is not complete until your applications point at the new instance.
Point-in-time restore
aws rds restore-db-instance-to-point-in-time \
--source-db-instance-identifier demo-pg \
--target-db-instance-identifier demo-pg-restored \
--restore-time 2026-11-26T14:30:00ZUse --use-latest-restorable-time instead of --restore-time to restore as close to the present as possible. You can find the valid range with:
aws rds describe-db-instances \
--db-instance-identifier demo-pg \
--query "DBInstances[0].LatestRestorableTime"The earliest restorable time is shown for the instance's automated backups in the console, or with describe-db-instance-automated-backups.
Restoring from a snapshot
aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier demo-pg-from-snap \
--db-snapshot-identifier demo-pg-before-migrationWhat a restore does not carry over
A restored instance gets default settings for several things, even though the data matches. Check and set these explicitly:
- Parameter group. The restore uses the default parameter group unless you pass
--db-parameter-group-name. Custom settings such aslog_min_duration_statementare lost otherwise. - Security groups. Pass
--vpc-security-group-ids, or the instance gets the VPC default group and your clients cannot connect. - Subnet group and public access. Pass
--db-subnet-group-nameand--no-publicly-accessiblewhere needed. - Backup retention. Set it again on the new instance.
- Read replicas. Replicas are not restored. Create them again.
- Credentials. The restored database contains the original users and passwords. The RDS-managed secret belongs to the source instance, so decide how the new instance's master password is managed.
A more complete restore command therefore looks like this:
aws rds restore-db-instance-to-point-in-time \
--source-db-instance-identifier demo-pg \
--target-db-instance-identifier demo-pg-restored \
--use-latest-restorable-time \
--db-subnet-group-name demo-subnets \
--vpc-security-group-ids sg-0123456789abcdef0 \
--db-parameter-group-name demo-pg16 \
--no-publicly-accessibleRecovering from a mistake: a typical workflow
Suppose someone ran DELETE FROM orders without a WHERE clause at 14:32 UTC.
- Note the exact time of the mistake from application logs or your engine's logs.
- Restore to a time just before it, for example 14:31:30, as a new instance such as
demo-pg-restored. - Connect to the restored instance and verify that the
orderstable has the rows. - Choose how to recover. For one table, copy the rows back to the live database with
pg_dumpfor that table or anINSERT ... SELECTthrough a foreign data wrapper. For wide damage, repoint the application to the restored instance. - Delete the restored instance when you are done, so it stops incurring cost.
Copying only the damaged rows keeps the writes made after 14:32. A full cutover loses them unless you replay them yourself. This is the main trade-off in a restore decision.
Deleting instances and keeping backups
When you delete an instance, RDS asks whether to create a final snapshot. By default, automated backups are deleted along with the instance. Two options change that:
- A final snapshot (
--final-db-snapshot-identifier) keeps a manual snapshot at the moment of deletion. --no-delete-automated-backupskeeps the automated backups for the rest of their retention period, so you can still do point-in-time restores. These are called retained automated backups, and they are billed.
aws rds delete-db-instance \
--db-instance-identifier demo-pg \
--final-db-snapshot-identifier demo-pg-final \
--no-delete-automated-backupsFor a disposable test instance, such as the restored copy, skipping the snapshot is appropriate:
aws rds delete-db-instance \
--db-instance-identifier demo-pg-restored \
--skip-final-snapshotCommon errors and gotchas
- "Cannot restore, no automated backups." Retention was
0. Set it above zero now, but you cannot go back in time to before it was enabled. - Restore time rejected. The time is outside the window between the earliest and latest restorable times. Check
LatestRestorableTime. - Cannot connect to restored instance. The security group, subnet group, or public access setting was reset to defaults.
- Cannot share a snapshot. It is encrypted with the AWS managed key. Copy it with a customer managed key first.
- Backups are not an archive. Automated backups expire at 35 days at most. For longer retention, take manual snapshots on a schedule or use AWS Backup.
- Backups are not a high-availability tool. Restoring takes minutes to hours depending on size. Use Multi-AZ, covered in a later chapter, for fast failover.
- A backup you never restored is untested. Run a restore drill periodically and time it, so your recovery time estimate is a measurement.
Exercise
A table was dropped by mistake at 09:15 UTC. Your instance has a 3-day retention period, and the last manual snapshot is from last week. Which restore method do you use, what do you pass for the time, and why must you also pass security group and parameter group options?
Show answer
Use point-in-time restore (restore-db-instance-to-point-in-time) with --restore-time set just before 09:15 UTC, such as 09:14:00Z. The weekly manual snapshot cannot recover to that moment, and it would lose a week of data. The restore creates a new instance with default settings, so you must pass --vpc-security-group-ids, --db-parameter-group-name, and the subnet group so that the new instance is reachable and tuned like the original.
Exercise
You want a copy of an encrypted snapshot, encrypted with the default aws/rds key, to be usable by another AWS account. What must you do?
Show answer
Copy the snapshot and re-encrypt it with a customer managed KMS key. Then share the copy with the other account and grant that account permission to use the key. Snapshots encrypted with the AWS managed aws/rds key cannot be shared.