AWS Cloudformation Automatic Backup and Restore Redis CacheCluster - amazon-web-services

I want to enable automatic backups on my redis cluster on AWS.
Looking at the documentation I have to specify SnapshotRetentionLimit and SnapshotWindow. This kind of works and it creates the backup for me.
Now the problem is how can I use the latest backup and restore my redis cluster when it's restarted for example ?
I see there's a parameter SnapshotName:
SnapshotName
The name of a Redis snapshot from which to restore data into the new node group (shard). The snapshot status changes to restoring while the new node group (shard) is being created.
Which name should I include? Automatic backup creates backups with dynamic names (prefixes them with date and time). Can I somehow get the latest backup name through cloudformation template? Is this even possible via cloudformation template?
Thank you

Related

Restore AWS Backups to RDS using terraform

I have an AWS Backup plan which do a snapshot every day from a RDS instance, created by terraform. (This AWS Backup plan is not created by terraform).
The point is that I have to restore some of this snapshot without my tfstate lose the state of de whole deployment, because if I restore by hand, a new instance will be created and I would have to change the database endpoint in my application pointing to the new rds instance..
Using the aws_db_instance only allow to restore backups created by the own rds and I haven't found any resource to restore using terraform this snapshot..
Is there any way to restore an AWS backup snapshot without lose my tfstate? Could be the solution create the backups in the own RDS service using terraform?
Thanks in advance.
Sadly, you can't do this. You have to restore by hand, and then manually update your TF code to reflect the changes. This is the same situation when your RDS fail-overs due to failures. TF will not be aware of this, and you have to manually correct the drift.
We handled this situation in the following way in AWS to avoid changing any TF configuration:
Restore snapshot to new database db-new, ensuring that the configuration matches the original db
Modify original db to have a new identifier like db-old. Note that this will cause your endpoint to change, so your app will lose connectivity when AWS completes the modification.
Modify the db-new to have the original db identifier. This will change the endpoint to match the original endpoint.
Run terraform plan and see whether there are any configuration changes. Make sure to update the new db to match the config in the current TF state.
You should see that TF only updates a security group in place, and it sees the new db as matching the old db.

Amazon RDS: Backup and restore into new database on existing DB instance

I have a database hosted on Amazon RDS , which i need to take backup and create new database out of it. Being new, not sure how to do it. Tried doing from SSMS but it didnt work.
This is one of the top google results but there is some outdated information here.
You can enable sql native backup / restore for sql server in RDS, backup a single database to S3 and then restore that database to the same RDS instance with a new database name.
Steps for environment setup and performing the backup/restore:
Create an S3 bucket to store your native backups.
Enable Sql native backup by configuring a new option group for your RDS instance and adding the "SQLSERVER_BACKUP_RESTORE" option.
Executing a series of procedures in SSMS to run the backup and restore tasks:
exec msdb.dbo.rds_backup_database
#source_db_name='database_name', #s3_arn_to_backup_to='arn:aws:s3:::bucket_name/file_name_and_extension',
#overwrite_S3_backup_file=1;
exec msdb.dbo.rds_restore_database
#restore_db_name='database_name',
#s3_arn_to_restore_from='arn:aws:s3:::bucket_name/file_name_and_extension';
exec msdb.dbo.rds_task_status #db_name='database_name'
Note: I cannot find any announcement about removing this prior limitation:
You can't restore a backup file to the same DB instance that was used to create the backup file. Instead, restore the backup file to a new DB instance.
However, as of today, I can confirm restoring a native backup to the same instance works as you would expect.
You can do this in couple of easy steps using AWS console as well
Take RDS database snapshot. You might have already RDS snapshots. Check in AWS Console --> RDS --> Snapshots.
If you do not have snapshot, then RDS Instances --> Select the required instance--> Click on "Instance Action"--> Take Snapshot.
Then next Item is you have to create new RDS instance from this snapshot.
Go snapshots--> Select the snapshot you want to create instance. --> Click on "Snapshot actions" --> Restore snapshot.
In restore screen, for "DB Instance Identifier*", enter the name of new RDS instance.
There are certain restriction in restoring from snapshot like you can not change the size of the DB, version of software etc. New instance inherit these attributes from original database.
Take a look at the documentation for creating a DB snapshot and restoring from a DB snapshot.
I suppose you use SQL server RDS.
It is not clear if you want to restore database to the same instance or not.
Restoring backup on same instance under different name is not available in Amazon RDS
You can't restore a backup file to the same DB instance that was used to create the >backup file. Instead, restore the backup file to a new DB instance.
Troubleshooting part at
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html#SQLServer.Procedural.Importing.Native.Using.Poll
Also SQL Server native backup is not supported from SSMS in Amazon RDS since it requires to choose location for backup but in RDS you could not access OS resources.
There are few options:
1) Create another instance from snapshot,
2) if there are many databases and you want to restore only one, you need to enable SQLSERVER_BACKUP_RESTORE and use rds_backup_database to create a backup and rds_restore_database to restore it.
Prerequisite are to have S3 bucket and IAM account has access to S3 bucket
Steps should be:
change parameter SQLSERVER_BACKUP_RESTORE in option group. Be careful, it might require server reboot.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.SQLServer.Options.BackupRestore.html
call rds_backup_database in msdb database. Required parameters are database name and S3 bucket, optional are if you want to encrypt backup, overwrite backup with same name in S3 bucket, and back up type full or differential
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html#SQLServer.Procedural.Importing.Native.Using.Backup
Output of the procedure is task id and it can be used to check status of backup task.
exec msdb..rds_task_status #task_id= 5
After backup has been created, login to another instance and run rds_restore_database. Parameters are name of the database to restore and S3 bucket where the backup is located.
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/SQLServer.Procedural.Importing.html#SQLServer.Procedural.Importing.Native.Using.Restore
If you want you can download backup file from S3 and restore it to SQL server on premise.
3) And the longest one if you want to have both database on same instance, to script database, create under different name and export data to the new database
The whole process is described here
UPDATE: Amazon allowed to restore database on the same instance where backup was created.
https://aws.amazon.com/about-aws/whats-new/2018/10/amazon-rds-for-sql-server-enhances-backup-and-restore-capabilities/

Restoring an Elastic Beanstalk RDS

When rebuilding an elastic beanstalk environment, EB automatically recreates a new and associated RDS instance.
Once associated, RDS instances cannot be dissociated from an EB environment.
I have a snapshot of the previous RDS prior to the rebuild.
You cannot restore RDS snapshots to an existing RDS instance.
How then, can I rebuild the environment with my desired snapshot attached? Or, how can I use my existing snapshot, or how can I migrate the existing snapshot data to the new database (I tried a data export with create schema's but lacked permissions on the import). Any appropriate but ideally simple option will do.
If you have a snapshot of your RDS DB, you can create a new environment with it. For this, you need to specify the DBSnapshotIdentifier option setting.
Create a file .ebextensions/rds_builder.config in the root of your project
Add the following:
option_settings:
aws:rds:dbinstance:
DBSnapshotIdentifier: <snapshot ID here>
EDIT:
You can also create a new environment using a saved configuration template of the present one. It is likely that this saved template will contain information in the aws:rds:dbinstance (since you have associated your present environment with an RDS), so you would need to basically modify this bit to point to your snapshot. This should work, and is probably the better approach.

Elasticsearch perform snapshot incrementally

I have created a snapshot in AWS S3 and I am trying to update the same snapshot every day. Is it possible to do in Elasticsearch cloud-aws plugin ? Tried running the same create snapshot link but it doesn't updates the existing snapshot.
It is incremental by default.
Which means that you create a repository.
Then create a snapshot to this repo. This one is a full backup.
Then create a new snapshot to the same repo. This one is incremental.

AWS Elastic Beanstalk Backup & Recovery

I am new to AWS EB and I am trying to figure out how to backup and restore an entire EB environment. I created an AMI based on the EC2 instance generated by EB, and took a snapshot of RDS, also created by EB.
The problem I have is, how do I restore it, assuming that this is the correct approach of backup. Also, I am doing it manually, shouldn't there be an automated way of doing this within EB? By the way, when I created the AMI, it destroyed the source and the EB just created a new EC2 instance without all my changes.
How do I save & restore configuration changes to my application that impact both filesystem and database?
Unfortunately, Amazon AWS Elastic Beanstalk (EB) does not support restoring databases that contain live data, if those databases were created with EB. If you reload (AKA AWS "deploy") the EB saved configuration, you get a blank database!
I called them and they told me to create the RDS DB separately and update the application code to connect to the DB once you know it's name. If you restore the RDS DB it will have a new name too! So you have to update your code again to connect to it.
Also, if you code and environment is fine, but you want to restore your database, again it will have a new name and you will need to change your code.
How to change your code easily and automatically deploy it is a whole other question for which I don't have an answer yet.
So basically the RDS DB provisioning within Elastic Beanstalk has very limited uses, maybe coding and debugging and testing, but not live production use. :(
This is as of Jan 2015.
First go into your EB environment and save the current config. You should go to a running EC2 instance created by EB and make an Image. Then use that new AMI ID by going to the EB configuration and setting it. It will rebuild the environment tearing down all running instances and creating new ones.
For your RDS instance you should make a backup and restore with a new instance name as the docs say you will lose it if the environment is destroyed. You should probably just manually set the environment variables like RDS does and setup the proper security groups between RDS and EC2.
One option I think could work is just renaming the RDS instance name as the environment seems to break and then destroy the environment and create a new one with an attached RDS instance and then destroy that one and rename the old one to the new one's name which may work.
As always make proper backups before proceeding with any of these ideas.