Blog Articles
Read MSP360’s latest news and expert articles about MSP business and technology
AWS EC2 Backup

How to Back Up Amazon EC2 Instances

How to Back Up Amazon EC2 Instances

Amazon EC2 is one of the world’s most popular cloud virtual machine environments. Naturally, there are several ways to perform the backup of your instances running on this server. The ways depend on the way you want to perform a backup, on the flexibility of the recovery operations available for you, and on the number and type of data you will transfer. This article overviews the different methods for backing up EC2 instances and discusses the pros and cons of each Amazon cloud backup approach.

Table of Contents

     

    EC2 Backup Method 1: EBS Snapshots

    Amazon EC2 Backup Method 1: EBS Snapshot

    Each Amazon EC2 instance should have a drive with system information. This drive, in AWS terms, is an Amazon EBS volume. Naturally, you would want to back it up. (Learn more about EBS storage type in our comparison of Amazon S3 vs EBS vs EFS.)

    AWS has an embedded mechanism for the Amazon EBS volumes backup. It allows you to save the state of an EBS volume at any given point in time.

     

    To perform this type of backup you should:

    1. Stop the EC2 instance in question or unmount the volume you want to backup.
    2. Choose the Snapshot tool in your AWS web console, in the Amazon EC2 section, and follow the instructions.

    Note that the process of creating a snapshot can take several hours, depending on how much data you are capturing.

      New call-to-action

    While this backup is fairly simple, it’s also manual and won’t fit if you are trying to backup several instances or create multiple recovery points.

    Further reading How to Resize an Amazon EBS Volume

    FREE WHITEPAPER
    Backup and Disaster Recovery on AWS
    Every minute of downtime means money lost.
    Plan your perfect disaster recovery strategy on AWS:
    New call-to-action
    WP icon

    EC2 Backup Method 2: Creating a New AMI

    AWS EC2 Backup Method 2: Amazon Machine Image (AMI)

    Amazon Machine Image is yet another embedded into AWS Amazon EC2 backup feature. It allows backup of the system information and configuration, and all data on your instance.Basically, it’s a complete replica of your EC2 machine at the given point-in-time.

    This method of EC2 backup is slightly more complicated than snapshotting an EBS volume because it involves more steps, but it is still relatively simple. Plus, when you create an AMI image for backup purposes, you gain the convenience of having your operating system and configuration data packaged into a single backup image, which you can then use to restore an instance quickly. This is more convenient than having only the EBS volume backed up.

    1. To create an AMI you would need to stop your Amazon EC2 in most cases.One of the exceptions, for example, is when you use a file system such as XFS, which can be “frozen” in order to create backups.
    2. Once your instance has stopped, start the AWS web console and go to the EC2 section. After that select the instance you want to back up. Then navigate to Actions>Image>Create Image. This opens a dialog where you can configure how your new AMI will be created.

    This method of EC2 backup is slightly more complicated than snapshotting an EBS volume because it involves more steps, but it is still relatively simple. Plus, when you create an AMI image for backup purposes, you gain the convenience of having your operating system and configuration data packaged into a single backup image, which you can then use to restore an instance quickly. This is more convenient than having only the EBS volume backed up.

    Yet AMI image backups also have a downside. Like EBS snapshotting, this Amazon cloud backup method is heavy on manual work. It is also not feasible on a large scale.

    EC2 Backup Method 3: AWS Backup

    AWS backupAWS Backup solution allows the creation of both the AMI and EBS volumes using the AWS web console. At the same time, AWS Backup allows you to back up the given EC2 instances to different AWS Regions, and recover instances in full or granularly, restoring only the required files in case of need. The restore, full and granular, can be done through the web console, using the API or the AWS command-line interface.

    To perform a backup of an Amazon EC2 instance with AWS Backup, in your AWS web console go to AWS Backup, Protected Resources and select either On-Demand Backup or Backup Plan. Check out the official AWS guide on EC2 Backup.

    EC2 Backup Automating with S3 and the AWS CLI

    Except for AWS Backup, you can automate the backup of Amazon EC2 instances with other means. By completing a little upfront configuration, you can use S3 storage buckets and Bash scripts to create an automated backup solution that can scale whenever you need.

    To automate EC2 backups, you need three things:

    1. An S3 storage bucket. Click this link to get information on creating an S3 bucket.
    2. An IAM role with permissions to access the S3 storage bucket. Learn how to create an IAM role and how to configure IAM permissions for S3.
    3. A script that uses the AWS Command Line Interface (CLI) to create an EBS snapshot or AMI image.

    To create your Amazon cloud backup script, you need first to install the AWS CLI, which supports Windows, Linux, and macOS.

    You can then write a script in Bash (for Linux and macOS) or PowerShell (for Windows) that automates your EC2 backup process.

    A simple example backup script written in Bash looks like this:

    #!/bin/bash
    
    aws ec2 create-snapshot --volume-id vol-xxxxx --description "Backup: `date`."

    This script uses the create-snapshot command on the AWS CLI. This command allows you to snapshot EBS volumes.

    If you wish instead to use the AMI image approach, you can swap in the create-image command instead. Your script would then resemble the following:

    #!/bin/bash
    
    aws ec2 create-image --instance-id i-1234567890abcdef0 --name "Image Backup" --description "Backup AMI"

    These are very basic examples. By expanding your script (and using it in conjunction with a tool such as cron), you could easily back up multiple EC2 instances, perform backups at a set time of day and so on.

    You can also use your script to remove older backup snapshots or AMIs in order to reduce your S3 storage costs.

    Alternate Approach: Backing Up Just Data

    Data backup on Amazon EC2 instance

    In some instances, you may wish to back up just the data inside your EC2 instance, rather than the entire instance.

    This can be a good approach to EC2 backup if, for example, you want to minimize the storage costs of your backups by backing up only application data, rather than a full file system. If you need to restore your instance, you can combine the application data with a stock root file system image to create a new instance.

    As long as your file system does not contain an extensive amount of custom configuration settings, this approach would work well -- although it may make recovery during an emergency somewhat more complicated because you would need to build a new instance, rather than simply recreate one based on an existing EBS snapshot or AMI.

    Flexible EC2 Backups with CloudBerry Backup

    Flexible EC2 Backup with CloudBerry

    Sometimes you need to only backup the files inside your EC2 instances. For such cases, AMI and EBS volume snapshots, and the full-on AWS API backup automation might seem excessive. Hence, you need a backup solution that can be installed on the given EC2 instance.

    CloudBerry Backup is a versatile solution that supports all of the Amazon cloud backup methodologies described above.

    CloudBerry Backup also provides a flexible approach to restoring data. It can restore instances directly to EC2, or restore data to an AMI or EBS volume that can then be used to rebuild an EC2 instance. This flexibility ensures that you can recover quickly during an emergency by choosing the most effective path to data restoration. To learn more about that functionality, check out our article:

    Further reading How to Do a Full Server Restore to Amazon EC2

    Because CloudBerry Backup offers not only a graphical user interface but also a command-line tool, called cbb.exe, it can be used to automate EC2 backups, too.

    Conclusion

    There are two main approaches to backing up EC2 instances: First, to use EBS snapshots, and second, to use AMI images.

    There are also different methodologies for implementing both of these approaches. The default method is to work manually through the EC2 Console. While this strategy is easy, it suffers from the major drawback of being impossible to automate. Lack of automation prevents this backup strategy from being feasible to execute on a large scale.

    If you use S3 storage and scripting to automate the EC2 backup process, however, you can achieve streamlined, efficient backups. Any organization seeking to create an EC2 backup solution that works at scale should adopt an automated approach.

    MSP360 Managed Backup.
    Simple. Reliable.
    Powerful cross-platform backup and disaster recovery that leverages the public cloud to enable a comprehensive data protection strategy.
    New call-to-action
    MBS CTA image