kirk mads
kirk mads

Reputation: 13

How to automate EC2 Instance snapshots?

How can I automate EC2 instance snapshots every X time? By snapshot, I mean an image of all data and state and configuration of the virtual machine, so I can recover it quickly. Is there an AWS service for this purpose? What's the best way?

My EC2 instance type is m5.2xlarge

Upvotes: 0

Views: 3685

Answers (4)

S V Naresh
S V Naresh

Reputation: 89

AWS has an service called Lifecycle Manager in EC2 dashboard. With the help of it, you can automate the backup procedure of the EBS volumes.

  • You can define backup and retention schedules for EBS snapshots by creating lifecycle policies based on tags defined for volumes.

  • With this feature, you no longer have to rely on custom scripts to create and manage your backups.

  • This feature is now available in the US East (N. Virginia), US West (Oregon), and Europe (Ireland) AWS regions at no additional cost.

Upvotes: 1

John Rotenstein
John Rotenstein

Reputation: 270294

You mention "all data and state and configuration of the virtual machine". This really consists of two parts:

  • Contents of the disks
  • Configuration of the Amazon EC2 virtual machine ("instance")

Configuration of virtual machine

Backups normally only consist of the contents of the disks. The configuration of the virtual machine is specified when a replacement machine is launched, including:

  • Instance Type
  • Subnet & IP Address
  • Tags
  • IAM Role

It is not possible to "back-up" these settings, but you could create a CloudFormation template that launches an instance with matching settings. This can then become a repeatable, automated process.

Contents of the disks

The easiest way to backup the contents of the disks to allow the launch of an equivalent instance would be to create an Amazon Machine Image (AMI). The AMI contains a copy of all disks connected to the instance.

A new Amazon EC2 instance can then be launch from the AMI, and it will contain exactly the same data on the disks. (An AMI consists of Amazon EBS Snapshots, plus some metadata about the instance configuration. A new instance can be launched from an AMI, but not from an EBS Snapshot.)

If you wish to automate the regular creation of an AMI, you can use the Amazon Data Lifecycle Manager.

See: New – Lifecycle Management for Amazon EBS Snapshots | AWS News Blog

I also recommend that you test the backup by launching a new EC2 instance from the AMI.

Upvotes: 0

amitd
amitd

Reputation: 1532

Some of the options are;

  1. Use AWS Back Up service

OR

  1. Schedule AWS Systems Manager Automation AWS-CreateImage or AWS-CreateSnapshot (choose either of these or both depends upon your use-cases) using AWS EventBridge or AWS CloudWatch

Upvotes: 1

Mark J. Bobak
Mark J. Bobak

Reputation: 14433

You may want to investigate a service called AWS Backup. I have only read abou it, as it's relatively new, and I had imlemented a custom solution using a Lambda function before it became available,

If I were to do it again, I'd use AWS Backup.

Upvotes: 1

Related Questions