fbpx

How to Automate AWS EC2 Instance Backups Step-by-Step

How to Automate EC2 Instance Backup
Learn how to automate Amazon EC2 instance backup using EBS snapshots and AMI, including screenshots, shell script samples and instructions.
Share This Post

Backing up your data regularly is critical for any company with business continuity in mind, whether the company is using an on-premises data center or a public cloud like AWS. Backups should be implemented properly and tested often, so that if a disaster occurs, the business doesn’t suffer.

Taking a backup of your infrastructure resources frequently is very important in order to be able to recover from a disaster. It’s important to schedule AWS backups on a timely basis, such as taking backup weekly or monthly on different availability zones. It’s one of the best practices that is followed by DevOps teams all over the world.

So, in this article, we’ll walk you through how to backup EC2 instances using cloud-native technologies such as N2WS to manage EBS snapshots at scale, AWS Backup, AWS Data Lifecycle Manager, and Amazon EBS snapshots using CloudWatch event and AMIs— to achieve both cost-saving and time-saving benefits while maximizing your data availability.

This step-by-step article presents the various advantages and disadvantages worth considering when looking into automating your EC2 instance backups on AWS.

How to Backup EC2 Instances

When doing an EC2 instance backup, you are essentially backing up the Elastic Block Store (EBS) volume (which contains all the data on it) by creating a snapshot of it. You can also create a new Amazon Machine Image (AMI) from your existing instance or a snapshot, if needed.

This method, which was more commonly used in the past, preserves the configuration and deploys new copies of it. Both the EBS snapshot and the AMI are automatically stored on Amazon S3 which is known for being highly durable and reliable. (Learn more with this post: 3 Ways To Backup And Recover EC2 Windows Instances) Most of the recently introduced tools, including the ones discussed below, focus on EBS volumes alone.

Automate EC2 backups and recover in seconds
Try N2WS Backup & Recovery to:

4 Different Ways to Take EC2 Instance Backups

1) N2WS Backup & Recovery Tool

N2WS Backup & Recovery is a cloud-native tool to back up, restore, and optimize the data lifecycle for your AWS resources. Using it, you can automate backups for one or more AWS accounts from a single pane of glass, simplifying the backup process and making it a great tool when dealing with disaster recovery, compliance requirements and storage savings.

See how to automate EC2 instance backups in 1 minute 👇 or click around a tour.

N2WS allows users to manage multiple AWS accounts and configure policies and schedules to take automated snapshot backups. It also has a Windows agent to consistently back up Windows applications without the need for maintenance windows. Furthermore, in a dynamic cloud environment, you need to be able to keep consistent backup policies across all your instances at any point in time.

To be most effective, your solution needs to be dynamic and automated when a server is terminated and a new instance needs to be launched.

Using EC2 instance tags, N2WS can automatically assign each one of these new instances the appropriate backup policy based on their purpose and your initial configuration. For more info, check out our previous article about tag-based continuous AWS cloud backup.

N2WS Backup & Recovery has been steadily improved since its global release, and the latest updates introduced many enhanced backup features to let you protect even more AWS services like EFS backups and have improved file level recovery and reporting. We’ve also worked hard to address the growing problem of cloud waste and unnecessary AWS spend.

N2WS’ latest versions have several features specifically designed to save on your monthly AWS bill such as Resource Control, an instance scheduler to start/stop instances on-demand for better control of your resources particularly when they are idle. Also, with N2WS, you can automatically archive data into longer term storage, resulting in reduced storage costs—up to 98%.

2) Automate Backups Using AWS Data Lifecycle Manager

In July of 2018, Amazon released Data Lifecycle Manager (DLM), a tool for automating EBS volumes. DLM allows you to use tag-based lifecycle policies to define various backup schedules.

To get started, open LifeCycle Manager under the EC2 instance service and start defining the policy.

AWS data lifecycle manager for automating EC2 backups

Policy works by looking at the desired tags, so make sure your resources are tagged properly before starting. You can also pick the resource type. This is helpful when you only want to look for tagged EBS volumes, rather than finding all the tagged EC2 instances.

create snapshot lifecycle policy

Further down, you define the backup schedule. Simply choose the starting time and how often the policy will run (you can choose between 2h and 24h). You will also need to pick the number of snapshots to be retained.

set policy schedule

You can have additional tags added to your snapshots, either by checking the option to copy the tags from the original volume or by adding new ones yourself.

set tags

You can also exclude the snapshot of the root volume. This is a useful option if you only need additional data volumes to be backed up. For the role, you can keep the default.

set parameters

It is possible to create the policy without immediately enabling it. If you do this, simply modify the policy later.

policy summary

After you are done, you can see your newly created policy, as well its status.

policy status

If you want more details, you can look at the policy summary. It will tell you exactly how you have defined the backup schedule, and it will show the retention of the backups.

policy summary text

When the defined schedule triggers backups, you will see them under Snapshots.

snapshots

3) Backup Automation Using AWS Backup

AWS Backup is a fully managed service that is used to automate backups on AWS (though it can be implemented on-premises as well, by using AWS Storage Gateway). Compared to Data Lifecycle Manager, it is a much more powerful tool, and it can serve as a centralized location for configuring and monitoring backups.

AWS Backup can be used not only for an EBS volume, but also for RDS databases, DynamoDB tables, Storage Gateway volumes, and even EFS file systems.

To start, open the AWS Backup service.

aws backup service

Click on Backup plans (or Manage Backup plans), and then Create Backup plan.

There, you have a couple of options.

create an aws backup plan

You can start by using an existing plan and choosing an option such as “Daily 35-day retention” or “Daily Monthly 1yr Retention.” In this example, we are going to start from scratch, so pick Build a new plan.

After naming your plan, you will configure the backup rule—or, more specifically, a schedule that will be followed for creating backups. Make sure you set the desired backup window (if using a custom one, UTC is always used and can’t be changed) and the frequency of execution.

backup rule configuration

You can also create the life cycle settings and either transition the backups to Amazon Glacier cold storage or expire them completely.

Below that section is the one in which you pick the Backup vault. You can either use the default one or select a custom vault, if you’re looking for logical separation. As with the Data Lifecycle Manager, you can add tags to your backups if needed.

backup lifecycle info

After you’re done and your plan is created, it is time to assign resources to it.

backup plan success

Resources can be assigned by using tags or by adding them based on the Resource ID.

assign resources

With the plan created and the resources assigned, your AWS Backup is ready.

You can go back to the AWS Backup dashboard and actually see the backup (and also restore) jobs. The screenshot below shows that there is a backup job in progress.

aws backup dashboard

After the backup has been completed, the dashboard will be updated accordingly, as shown below.

aws backup overview

With AWS Backup, you can easily initiate the restore of your backups. This can be very convenient, especially in a disaster recovery situation when multiple volumes may need to be restored quickly.

4) Schedule Automated Amazon EBS Snapshots Using CloudWatch Events

The last backup method we will examine is EBS Snapshot creation using CloudWatch events. To implement this process, you will use a CloudWatch rule.

CloudWatch alarms

Click on Create rule, and pick Schedule under Event Source.

create rule

This will give you two options: you can either have this rule triggered using a fixed rate (every X minutes, hours, or days), or you can use a cron expression, which gives you much more flexibility. For example, you can have an event that triggers every Wednesday, Thursday, and Friday at 6pm. You will also see a preview of your next ten trigger dates. Do note that all times are presented in GMT.

event source

After configuring the desired schedule, click on Add Target and chose “EC2 CreateSnapshot API call” from the list. Then, copy the volume ID of the volume you want to backup. You can leave the option to create a new role, unless you have one already.

targets

Click on Configure details, name your rule, and give it description. After that, you are ready to go.

Automating AWS EC2 Backup is a great way to save time and ensure critical data is protected

AWS EC2 backup automation is a great way to save time on recurring tasks. It also helps you to confirm that desired tasks have indeed been done. Since having regular backups is an absolute must in any business environment, this critical process should be not hinge upon manual execution.

Depending on your cloud environment, one of the four different methods presented above for automating your AWS EC2 instance backups could be a better fit than the others. N2WS Backup & Recovery is worth exploring, since it is a powerful and useful tool, as it supports not only AWS EC2 instance backup, but a range of other AWS services such as RDS, Redshift, DynamoDB, Aurora, and EFS all under one single pane of glass.

You can manage your entire AWS backup and recovery operations from a dedicated N2WS instance within your secure AWS environment as you scale. You can check it out by spinning up a 30 day free trial here (no credit card needed). Bonus: your free trial automatically turns into our forever Free Edition.

Click here to read the original post →

 

Keep Reading:

Next step

Automate EC2 backups and recover in seconds

Allowed us to save over $1 million in the management of AWS EBS snapshots...

Try N2WS for Free