Backup solutions for AWS EC2 instances [closed]

隐身守侯 提交于 2019-12-03 09:38:47

问题


I'm looking for a backup solution for Amazon EC2 instances. I found this: http://www.n2ws.com and I wanted to know if there were other ones.

Thank you

PS: It's possible to automatically backup RDS databases using Amazon solution but there isn't anything for EC2 instances... Is there?


回答1:


I've been using Skeddly for several months now to automatically backup the EBS volumes attached to my EC2 instances.

I'm really happy with it so far. I liked the way I could define which instances to backup: only instances with a specific tag are backed up. I just have to add this tag to the instances I want to back up. No need to do any change in Skeddly each time I add an instance. I had to define 2 actions in Skeddly: one to backup the instances and one to delete the old snapshots.

And I receive emails to inform me the actions (backup and expiration) have been successful or not.




回答2:


If you want a 100% AWS solution for automated backups of EC2 instances, there's one: AWS lambda.

Create a Python-based lambda with something like this:

import boto3

BACKUP_VOLUMES = [
  'vol-xxxxxxxx'
]

def lambda_handler(event, context):
    ec2 = boto3.resource('ec2')
    for volume in BACKUP_VOLUMES:
        ec2.create_snapshot(VolumeId=volume, Description='Automated backup')

And configure an event source for it so that it runs daily. And boom, no hassle, automated EC2 backups that are reliable, don't require another instance to drive them and cron jobs, or a 3rd party service. With the SES API, you could send email confirmations from that lambda too.

PS: Make sure the IAM role for the lambda has the rights to operate on EC2 snapshots e.g.:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "ec2:CreateSnapshot",
                "ec2:DeleteSnapshot",
                "ec2:DescribeSnapshots"
            ],
            "Resource": "*"
        }
    ]
}



回答3:


If by "EC2 Instances" you really mean "EC2 Instances with EBS Drives" then the Snapshot features of EBS, available through the AWS Console and the AWS API, are what you're looking for.

From the EBS Docs:

Amazon EBS also provides the ability to create point-in-time snapshots of volumes, which are persisted to Amazon S3. These snapshots can be used as the starting point for new Amazon EBS volumes, and protect data for long-term durability. The same snapshot can be used to instantiate as many volumes as you wish. These snapshots can be copied across AWS regions, making it easier to leverage multiple AWS regions for geographical expansion, data center migration and disaster recovery.

Amazon doesn't offer any scheduling or retention type policies around snapshots, but there are some third party tools that leverage the AWS API's.




回答4:


For easy management with a GUI, there is also Skeddly. It is pay as you go with CAD 0.15 for most actions. It is also possible to do all this things free. A good script to start from is this.




回答5:


The company I work for has been using Amazon's S3, EBS, and EC2 almost since their inception. It became painfully obvious, after losing 2 (1 development and 1 production) virtual servers 4 days after they were completed and scheduled to be let loose on EC2 the next night. To make a long story short, we did not find a standalone application that was very small, lightweight, and nearly configurable to any situation.

Using AWS .NET SDK, we were able to write the above application in less than a day and then using the Task Scheduler on our in-house Windows Server 2008 R2 server. We have gone through a number of scenarios and settled on the following schedule: EC2 instances images are created weekly, EBS snapshots are created daily. EC2 instances older than 31 days are dropped and EBS snapshots are dropped after 60 days, per our contract we entered in a contract with a client who had been burned previously with a standalone application that was supposed to run the backups on its own internal scheduling code/mechanism. It never ran, and no one looked at it after they set it up. As the application matures we plan on having Simple E-Mail Service (SES) for backup summary/log e-mail to our developers, and Simple Queuing Service (SQS) to record the process.

Hope this helps.




回答6:


The cloud protection manager product you found (www.n2ws.com) does support automoated backups of full EC2 instances, beyond backing-up EBS volumes individually, as well as RDS snapshots. It also has the scheduling, data retention policies and automated alerts options you were looking for and other backup related features for AWS.

Couldn't find other 3rd party products providing comparable automated backups for EC2 instances, but some of the cloud management consoles allow snapshot scheduding & creation of data retention policies.




回答7:


Here is AWS Lambda Boto3-based script which backups instance to AMI images and it works awesome:

import boto3, collections, datetime, sys

ec = boto3.client('ec2')

def lambda_handler(event, context):

    reservations = ec.describe_instances(        
        Filters=[
        {'Name': 'tag-key', 'Values': ['backup', 'Backup']},
    ]
    ).get(
        'Reservations', []
    )

    instances = sum(
        [
            [i for i in r['Instances']]
            for r in reservations
        ], [])

    print("Found %d instances that need backing up" % len(instances))

    to_tag = {}

    for instance in instances:
        try:
            retention_days = [
                int(t.get('Value')) for t in instance['Tags']
                if t['Key'] == 'retention'][0]
        except IndexError:
            retention_days = 7

        create_time = datetime.datetime.now()
        create_fmt = create_time.strftime('%Y-%m-%d_%H-%M-%S')

        AMIid = ec.create_image(InstanceId=instance['InstanceId'], Name="backup of " + instance['InstanceId'] + " dated " + create_fmt, Description="Lambda-created AMI of instance " + instance['InstanceId'] + " from " + create_fmt, NoReboot=True, DryRun=False)

        to_tag[retention_days] = AMIid['ImageId']

        print("Retaining AMI %s of instance %s for %d days" % (AMIid['ImageId'],
                                                               instance['InstanceId'],
                                                               retention_days)
             )

    print(to_tag.keys())

    for retention_days in to_tag.keys():
        delete_date = datetime.date.today() + datetime.timedelta(days=retention_days)
        delete_fmt = delete_date.strftime('%m-%d-%Y')
        print("Will delete %d AMIs on %s" % (len(to_tag[retention_days]), delete_fmt))

        ec.create_tags(
            Resources=[to_tag[retention_days],],
            Tags=[
                {'Key': 'DeleteOn', 'Value': delete_fmt},
            ]
        )

It was taken from here and adapted for Python 3. Highly recommend!




回答8:


For critical applications, a backup solution should be more than just scheduling snapshots.

You'd expect features like application-support, backup policies and powerful recovery options and more.

You can read about it in my post:

http://www.n2ws.com/blog/tier-1-application-backup-on-amazon-cloud.html

It's from the n2ws site and also references the CPM product.




回答9:


Sort of. You can snapshot EBS volumes on a regular interval. While there isn't anything in the UI to do this for you automatically, the API will allow you to do it. You can either roll your own backup script, or search for one that has been publicly released.




回答10:


Here is script Script to Automate AMI backup ! It will find instance-id of all instance in your VPC n create AMI backup !

 #!/bin/bash

 #Script to Automate AMI backup

echo "----------------------------------\n   `date`   \n----------------------------------"

aws ec2 describe-instances --filters Name=vpc-id,Values=vpc-1c927479 |   awk '{ print $8 }' | sort -n   | grep  "i-" > /tmp/instanceid.txt



 #echo "instance-`date +%d%b%y`"-i-29efe0e4 > /tmp/aminame.txt

echo "Starting the Daily AMI creation: "
 #echo -e "Starting the Daily AMI creation: `cat /tmp/aminame.txt`\n"

 #To create AMI of defined instance

for i in $(cat /tmp/instanceid.txt); do
        echo "Creating AMI for Instance id $i ......."

echo "instance-`date +%d%b%y`-$i" > /tmp/aminame.txt

aws ec2 create-image --instance-id $i --name "`cat /tmp/aminame.txt`" --description "This is created by ami-backup.sh" --no-reboot | grep -ir ami | awk '{print $4}' > /tmp/amiID.txt

echo  "AMI Name is: `cat /tmp/aminame.txt`\n"

echo done 
done
echo done



回答11:


I forget when Cloudwatch was introduced, but it definitely allows you to schedule automated EBS snapshots.

Pol's answer using AWS Lambda is still relevant. There's a great couple of blogposts about Scheduling EBS Snapshots and Deleting old snapshots




回答12:


There is an opensource project called Scalr that I just started using for about a week and it has features that enable you to scheduled automated snapshots/backups of your EBS volumes. Scalr is actually a cloud management solution and has many fabulous features that I've yet to play with but I'm looking forward to it.

There is a pay version but I'm just kickn the tires on the free open source version for now. The Scalr installer is available on Github: https://github.com/Scalr/installer-ng The Scalr source code is on Gitub too: https://github.com/Scalr/scalr Installation instructions are on the Scalr wiki: https://scalr-wiki.atlassian.net/wiki/x/0Q8b




回答13:


You can use AutomatiCloud to backup your EC2 volumes and RDS instances. AutomatiCloud allows you to define schedules for backups and cleans up after a retention period you can configure. It also sends out email notifications in case of success/failure. And it is free! www.automaticloud.net

Disclaimer: I am the author




回答14:


An easy way to backup all your aws ec2 instances is to use noovolari. It allows you to schedule periodic backups, has a file level recovery feature and allows you to recover a previous snapshot in a very easy way. It also sports an unlimited free tier for 5 ec2 instances, which does not hurt.

We have been using it on several infrastructures for a while and it works flawlessly.



来源:https://stackoverflow.com/questions/17087542/backup-solutions-for-aws-ec2-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!