I am managing an RDS Database in an CDK Project. From time to time it is necasary to recover an old state of the database from snapshot.
To make this possible, I have CDK Context Parameter specifying the Snapshot from which the Database should be recovered. If it is given, the snapshot is bassed to the RDS Construct. This leads to a replacement of the database (which is fine).
Now, if the database has been recovered from snapshot and I do some other update in the CDK Project and want to update the project (which is done via CD Pipeline) I usally start the update without giving any snapshot. This leads to the database to be replaced by an empty one, which is of course not what I want.
To summarize, this is how it currently works:
Current state of the stack
Deployment Paramter
Result
Not created from snapshot
No snapshot
DB is not replaced
Not created from snapshot
snapshot
DB is replaced
created from snapshot
No snapshot
DB is replaced
created from snapshot
snapshot (same)
DB is not replaced
created from snapshot
snapshot (different)
DB is replaced
This is IMHO not managable.
But what I want is something like this:
Current state of the stack
Deployment Paramter
Result
Not created from snapshot
No snapshot
DB is not replaced
Not created from snapshot
snapshot
DB is replaced
created from snapshot
No snapshot
DB is not replaced
created from snapshot
snapshot (same)
DB is replaced
created from snapshot
snapshot (different)
DB is replaced
Or, to put it in other words:
If I specify no snapshot, don't replace the DB
If I specify a snapshot, repalce the DB
Is this possible? Or is there another good way to manage an RDS Database using CDK?
Related
We have the next script for restoring DB.
Rename the current DB instance (mydb -> old_mydb).
Restore a DB instance to a specific point in time in new DB instance. Restore old_mydb to mydb.
But after restoring the new DB instance doesn't have old backups and we can't restore this instance again. Are there any ways to link the old backups to the new instance?
I have a bitnami instance working fine on my AWS console. I want to make a backup of it so that if I mess something up I can simply deploy an older backup.
I followed the instructions here:
https://docs.bitnami.com/aws/faq/administration/backup-restore-server/
So I have the snapshot created. But how do I get a bitnami instance running based off of that snapshop?
That page says:
This feature creates a new snapshot of the disk, which can later be used to restore the server to an earlier state.
To restore the snapshot, you can use "Create Volume" to create a new Amazon EBS Volume from the snapshot. You could then restore the system to the state of the snapshot with these steps:
Stop the instance
Detach the current EBS volume
Attach the new (restored) EBS volume with the same device identifier
Start the instance
However, if you wish to launch a totally new instance using the backup, then the easier backup method would be:
Use "Create Image" in the EC2 console to create an Amazon Machine Image (AMI)
Launch a new instance using that AMI
I have created and I have been managing a Postgresql RDS instance using Terraform.
Assuming I perform a terraform destroy, will this also delete the associated RDS snapshots that have been taken via the RDS schedule?
Terraform added the option to keep the automated backups for an RDS with the delete_automated_backups flag. Just set this to false.
When destroying an RDS database you have the option to either create a long lived final snapshot or retain the automated backups which will be deleted as per the schedule they were set for:
Instead of creating a snapshot, you can choose to enable Retain automated backups when you delete a DB instance. These backups are still subject to the retention period of the DB instance and age out the same way systems snapshots do.
Terraform supports keeping a final snapshot by setting the final_snapshot_identifier and making sure that skip_final_snapshot is not set to true.
Unfortunately, Terraform doesn't currently support retaining the automated backups taken from scheduled snapshots but there is an open feature request with a couple of half finished pull requests linked to it.
I made a big technical mistake when I launched my mysql database by selecting the largest storage setting by my database. As a result I deleted the instance, but I do have a snapshot of the last instance. I don't want to reinstate the snapshot and get charged, so I was wondering if there was a way for me to export the data from my last snapshot into a csv file and then create a new instance with smaller storage. Is this possible?
The only thing you can do with an RDS snapshot is restore it into a fresh RDS instance. Once you have the instance, you can export the data as CSV or using mysqldump.
From that, you can terminate the temporary instance and create your new, smaller instance and import the data.
But you cannot get at the data directly with the snapshot.
I have an RDS automated backup from several hours ago. In there is some data, which I have accidentally removed from the current database. Is it possible to extract data from an old automated backup?
Yes, assuming the data was present at your recovery time.
If you used the automated backup feature, you will be able to restore a DB instance to a specified time -- this process will create a new DB instance that uses the data from your backup. Here's a detailed explaination of what would be happening:
The automated backup feature of Amazon RDS enables point-in-time recovery of your DB Instance. When automated backups are turned on for your DB Instance, Amazon RDS automatically performs a full daily snapshot of your data (during your preferred backup window) and captures transaction logs (as updates to your DB Instance are made). When you initiate a point-in-time recovery, transaction logs are applied to the most appropriate daily backup in order to restore your DB Instance to the specific time you requested.
You haven't told us what type of database engine you're using... but very generally, once the new DB instance is in the available state, you will be able to connect to it and extract any data just as you would on the source DB instance.
You can perform this action from the:
AWS console
CLI (rds-restore-db-instance-to-point-in-time)
API (RestoreDBInstanceToPointInTime).
Note that the security group will be set to the "Default" group by default, so you may need to modify the DB instance after it becomes available if you use any custom security groups to connect.