Managing Backups
Prerequisites
- A Common Fate deployment
- Common Fate deployment Terraform version v1.38.0+
- Access to the deployment account where Common Fate is deployed
RDS Restore from backup
In Common Fate version v1.38.0 and onwards we have introduced the support for RDS backups from within Terraform. With the introduction of the
restore_to_point_in_time
and rds_db_retention_period
variables to the Common Fate deployment module to instruct the build to restore from a previous version of the RDS database.
- By default the
rds_db_retention_period
will be 7 days, meaning you will be able to backup to any point in time in the last 7 days. This is also now configurable and can be increased up to 35 days.
The restore_to_point_in_time
variable mimics the variable used in the aws_db_instance AWS Terraform resource.
Example usage in Common Fate:
Process to restore from backup
To process to restore from a backup in RDS is a 3 part process. First you will need to create a new database restore from a backup. Do do this you can pick any time that is within the db retention period and restore a backup from that. This should create a new instance of a RDS database which is restored from a PITR backup. This can be done in the AWS Cli or the AWS console.
AWS CLI
You will first need to find the name of your RDS table. To find it, head into the console and go to RDS then in the list of tables, choose the table created for the Common Fate deployment. It should be named like this: <namespace>-<stage>-pg-db
Run the following command
AWS Console
-
Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/.
-
In the navigation pane, choose Automated backups.
-
The automated backups are displayed on the Current Region tab.
-
Choose the DB instance that you want to restore.
-
For Actions, choose Restore to point in time.
-
The Restore to point in time window appears.
-
Choose Latest restorable time to restore to the latest possible time, or choose Custom to choose a time.
-
If you chose Custom, enter the date and time to which you want to restore the instance.
-
For DB instance identifier, enter the name of the target restored DB instance. The name must be unique. For example ‘temp-commonfate-restore’
-
Choose other options as needed, such as DB instance class, storage, and whether you want to use storage autoscaling.
-
Choose Restore to point in time.
Updating Common Fate deployment
Once you have made the restore and it has successfully created. You can now update the Common Fate deployment with the RDS identifier of the DB you just created. To do this add the following to your Common Fate deployment Terraform:
Then run terraform apply
- This will cause a replacement of the database. This is why we made a replica during step one.
When completed confirm that the deployment is working and you can delete the replica created in step one.