To achieve continuity of business (COB) you need a business continuity plan (BCP). A crucial part of such plan is to have available backups.
Amazon Web Services (AWS) offer Amazon Elastic Compute Cloud (EC2) instances that can be crash-consistent backed up into Amazon Simple Storage Solution (S3) via Amazon Elastic Block Store (EBS) snapshots.
Here I show how to use the out of the box provided AWS CloudFormation Template for EBS Snapshot Scheduler. No need to deal with AWS CLI, lambda functions, task scheduling, extra dedicated instances, IAM policies and permissions.
From
https://s3.amazonaws.com/solutions-reference/ebs-snapshot-scheduler/latest/ebs-snapshot-scheduler.pdf locate the “View Template” button which will download the ebs-snapshot-scheduler.template file (there is also a “download the template”). Rename your template and customize it. Below is an example of relevant fields you might want to change up front:
...
"Description": "EBS Snapshot Scheduler for Test Environment,
...
"DefaultRetentionDays": {
"Description": "Default Retention Period (number of days)",
"Type": "String",
"Default": "7"
},
...
"CustomTagName": {
"Description": "Custom Tag Name for testing environment backup",
"Type": "String",
"Default": "scheduler:ebs-snapshot:test"
},
...
"DefaultTimeZone": {
"Type": "String",
"Default": "US/Eastern",
...
"AutoSnapshotDeletion": {
"Description": "Enable auto-delete EBS snapshots after retention period.",
"Type": "String",
"Default": "Yes",
...
"HistoryDDBTableName": {
"Description": "History DynamoDB Table Name for Testing Environment",
"Type": "String",
"Default": "Scheduler-EBS-Snapshot-History-Test"
},
"PolicyDDBTableName": {
"Description": "Policy DynamoDB Table Name for Testing Environment",
"Type": "String",
"Default": "Scheduler-EBS-Snapshot-Policy-Test"
},
...
The Launch Solution button/link will allow you to define a new CloudFormation Stack (the collection of resources to be provisioned which are defined in a template file). Alternatively use Console | Services | CloudFormation | Create Stack | Choose a Template. Make sure to check what zone you are in the console UI and as usual change it to the correct one.
Select “Upload a template to Amazon S3” and upload the one you created above.
Type a stack name like EBSSnapshotSchedulerTest. If you don’t pick a name the default would be EBSSnapshotScheduler. You can configure from the UI most of the previously mentioned configuration but you might want to do that from the template anyway to keep your configuration files current and correctly versioned.
Press Next all the way through to go with defaults, check “I acknowledge that AWS CloudFormation might create IAM resources.” and hit Create.
Wait until the status of your stack is CREATE_COMPLETE and tag the instances you want to include in the backup, for example the below tag will use defaults:
scheduler:ebs-snapshot:test=true
The below tag will mean take two daily snapshots, one at midnight and one at noon in UTC zone and keep them for 7 years (2555 days):
scheduler:ebs-snapshot:prod:00 0000;2555;utc;all
scheduler:ebs-snapshot:prod:12 1200;2555;utc;all
You can deactivate by removing the tags.
To get an idea about how much time you saved take a look at your template from the AWS CloudFormation Designer:
That’s probably 24 hours worth of work and troubleshooting. It is worth to be said that
I published a scheduled Lambda that will take care of cross region replication, which demonstrates that we could achieve the same most important goal for in-region backup in a simpler way. Of course you will need to code a bit for that solution. Hopefully the creators of the CloudFormation EBS Snapshot Scheduler will either add replication as a feature or will build a new CloudFormation to take care of replication for the masses.
Adding new backup policies should be straightforward. You just need to focus on customizing a new template and following the steps described above. For example, for a typical production 7 years retention backup we can use the below selecting as Stack name EBSSnapshotSchedulerProd. Don’t forget to tag the instances you want to include in the backup “scheduler:ebs-snapshot:prod=true”. To deactivate it use “scheduler:ebs-snapshot:prod=none” or just remove it:
...
"Description": "EBS Snapshot Scheduler for Production Environment,
...
"DefaultRetentionDays": {
"Description": "Default Retention Period (number of days)",
"Type": "String",
"Default": "2555"
},
...
"CustomTagName": {
"Description": "Custom Tag Name for production environment backup",
"Type": "String",
"Default": "scheduler:ebs-snapshot:prod"
},
...
"DefaultTimeZone": {
"Type": "String",
"Default": "US/Eastern",
...
"AutoSnapshotDeletion": {
"Description": "Enable auto-delete EBS snapshots after retention period.",
"Type": "String",
"Default": "Yes",
...
"HistoryDDBTableName": {
"Description": "History DynamoDB Table Name for Production Environment",
"Type": "String",
"Default": "Scheduler-EBS-Snapshot-History-Prod"
},
"PolicyDDBTableName": {
"Description": "Policy DynamoDB Table Name for Production Environment",
"Type": "String",
"Default": "Scheduler-EBS-Snapshot-Policy-Prod"
},
...
The
ebs-snapshot-scheduler is open source.
If you need to take multiple backups within a day you will need to retag your instance but you can still use just one CloudFormation stack. I have opened a
feature request to avoid adding an extra tag per snapshot creation time leveraging cron expressions.