Can I automate a snapshot of an Amazon Lightsail instance? - amazon-web-services

I have just set up an instance of a WordPress site on Amazon Lightsail.
I'm looking for a backup solution.
The option to create a snapshot of the instance is there and works fine, but I see in the control panel that each snapshot takes 30GB and "Total snapshot data Snapshots are billed monthly per GB".
Is it feasible to do a daily snapshot without costing a bundle?
Or would it be better just to copy the whole WordPress directory to another directory or a S3 bucket on a daily basis?

Yes, it is possible to automate the creating snapshots of an Amazon Lightsail instance. Amazon has the CLI tool for all services including Lightsail. You can use it for automation or the AWS SDK tools for different programming languages.
If you want to create your own script you can take a look at these links
https://docs.aws.amazon.com/cli/latest/reference/lightsail/create-instance-snapshot.html?highlight=lightsail
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lightsail.html
https://aws.amazon.com/getting-started/
I also created a script for the AWS Lambda NodeJS to automate the process using AWS SDK. See the instructions and adjust it for your needs.
https://github.com/vidanov/lambda-nodejs-lightsail-backup

Yes, you should use snapshots rather than copying files. It is always fiddly to recreate a computer with only some of the files and it is easy to miss some important files (eg web server configuration).
Assuming that an Amazon Lightsail snapshots are the same as EBS snapshots (which would be a pretty safe assumption):
Snapshots only consume space for used blocks of the disk
Snapshots are incremental, only taking a copy of blocks that have been added or modified since a previous snapshot
Storage is charged on a pro-rata basis, so if it is only stored for 7 days, it would only be charged 7/30 of the cost (7 days divided by 30 days).
To reduce costs, you could take a snapshot each day and only keep the last n snapshots (eg the last 5 snapshots). You would need to code this yourself but it would be quite simple. (See example for Amazon EBS volumes,
but Lightsail would involve different API calls.)

For not so technical people like me, AWS now provides automatic snapshot for last 7 days.
This can be easily enabled via console in few simple steps.
Here is the detailed article.
https://aws.amazon.com/about-aws/whats-new/2019/10/amazon-lightsail-now-provides-automatic-snapshots/
which reads
Amazon Lightsail now supports automatic snapshots, allowing you to
schedule daily snapshots of your Lightsail Linux/Unix instances.
With automatic snapshots, Lightsail will automatically take a daily
snapshot for you at a time you specify, eliminating the need to take
snapshots manually. Lightsail keeps the seven most recent snapshots,
so you can rest easy knowing that you’ll have a full weeks’ worth of
snapshot history. Snapshots can be used to restore your instance to a
previous state and to create multiple new instances that are replicas
of the original instance.
Enabling the feature is free; you only pay for the storage of your
snapshots on Lightsail ($0.05 USD per GB per month). Although
Lightsail retains your seven most recent automatic snapshots, you can
choose to keep specific automatic snapshots as long as you wish or
continue to take manual snapshots of the instance (storage for manual
snapshots is charged at the same rate, $0.05 USD per GB per month).
Moreover, Lightsail optimizes your snapshot storage so that for each
consecutive snapshot, you’re charged only for the data that’s changed
from the previous one.
You can enable automatic snapshots using the Lightsail console or API
in all regions where Lightsail is available. To learn more about
automatic snapshots on Lightsail, click the link below.
https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-configuring-automatic-snapshots
Here is how to do it
Sign in to the Lightsail console.
On the Lightsail home page, choose the Instances tab.
Choose the name of the instance for which you want to enable or disable automatic snapshots.
On the instance management page, choose the Snapshots tab.
Under the Automatic snapshots section, choose the toggle to enable it. Likewise, choose the toggle to disable it if it's enabled.
At the prompt, choose Yes, enable to enable automatic snapshots, or Yes, disable to disable the feature.
The automatic snapshot is enabled or disabled after a few moments.

Related

How to take a backup of EC2 instance in AWS and move to a low cost alternative?

We have an EC2 instance running in AWS EC2 instance. We have our ML algorithms and data that. We have also hosted a web-based interface also in that machine.
Now there are no new developments happening in that EC2 instance. We would like to terminate AWS subscription for a short period of time (for the purpose of cost-reduction and exploring new cloud services). Most importantly, we want to be in a position where we can purchase a new EC2 instance with a fresh AWS subscription, use the backup which we take now, and resume all operations (web-backend, SMS services for our app which is hosted in AWS, etc.).
What is the best way to do it? Is temporary termination of AWS subscription advisable?
There is no concept of an "AWS Subscription". AWS is charged on-demand, which means you only pay when you use resources.
If you temporarily do not want the Amazon EC2 instance, you could:
Stop the instance, which is like turning off the power. You will not be charged for the instance, but you will still pay for the disk storage attached to the instance. You can simply Start the instance again when you wish to use it. You will only be charged while the instance is running. OR
Create an image of the instance, then terminate the instance. This will create an Amazon Machine Image (AMI), which contains a copy of the disks. You can then launch a new Amazon EC2 instance from the AMI when you wish to use it again. This is a lower-cost option compared to simply stopping the instance, but it takes more effort to stop/start.
It is quite common for companies to stop Amazon EC2 instances at night or over the weekend to reduce costs while they are not needed.
EDIT: Just thought of a third option. Will test it and be back. Not worth it; it would involve creating an image from the EC2 instance and then convert that image to a VM image, storing the VM image in S3. There may be some advantages to this, but I do not see them.
I think you have two options, both of them very reasonably priced. If you can separate the data from the operating system, then your best option would be to use an S3 bucket as a file system within the EC2 instance. Your EC2 instance would use this bucket to store all your "ML algorithms and data" and, possibly, even your "web-based interface". Whenever you decide that you no longer need the processing capacity of the EC2, you would unmount the S3 bucket file system from the EC2 instance and terminate that instance. After configuring an appropriate lifecycle rule for the S3 bucket, it would transition to Glacier, or even Glacier Deep Archive [you must considerer the different options of long term storage]. In the future, whenever you want to work with your data again, you would move your data from Glacier back to S3, create a new EC2 instance, install your applications, mount your S3 bucket as a file system and you would have access to all your data. I think this is your least expensive and shortest recovery time objective option. To implement this option, look at my answer to this question; everything you need to use an S3 bucket as a regular folder inside the EC2 instance is there.
The second option provides an integrated solution, meaning the operating system and the data stay together, and allows you to restore everything as it was the day you stopped processing your data. It's made up of the following cycle:
Shutdown your EC2 and make a note of all the specs [you need them further down].
Export your instance to a virtual image, vmdk for example, and store it in your S3 bucket. Something like this:
aws ec2 create-instance-export-task --instance-id i-0d54b0682aa3998a0
--target-environment vmware --export-to-s3-task DiskImageFormat=VMDK,ContainerFormat=ova,S3Bucket=sm-vm-backup,S3Prefix=vms
Configure an appropriate lifecycle rule for the S3 bucket so that it transitions to Glacier, or even Glacier Deep Archive.
Terminate the EC2 instance.
In the future you will need to implement the inverse, so you will need to restore the archived S3 Object [make sure you you can live with the time needed by AWS to do this]
Import the virtual image as an EC2 AMI, something like this [this is not complete - you will need some more options that you saved above]:
aws ec2 import-image --disk-containers
Format=ova,UserBucket="{S3Bucket=sm-vm-backup,S3Key=vmsexport-i-0a1c382e740f8b0ee.ova}"
Create an EC2 instance based on the image and you're back in business.
Obviously you should do some trial runs and even automate the entire process if it's something that will be done frequently. I have a feeling, based on what you said, that the first option is a better option, provided you can easily install whatever applications they use.
I'm assuming that you launched an EC2 instance from a base Amazon Machine Image and then added your own software and models to it. As opposed to launched an EC2 instance from an AWS Marketplace offering.
The simplest thing to do is to create an Amazon Machine Image (AMI) from your running EC2 instance. That will capture the current state of the instance and persist it in your AWS account. Then you can terminate the instance. Later, when you want to recreate it, launch a new instance, selecting the saved AMI instead of a standard AMI.
An alternative is to avoid the need to capture machine state at all, by using standard DevOps practices to revision-control everything you need to recreate the state of a running machine.
Note that there are costs associated with an AMI, though they are minimal ($0.05 per GB-month of data stored, for example).
I had contacted AWS customer care regarding this issue. Given below is the response I received. Please add your comments on which option might be good for me.
Note: I acknowledge the AWS customer care team for their help.
I understand that you require some information on cost saving for your
Instance since you will not be utilizing the service for a while.
To assist you with this I would recommend checking out the Instance
Stop/Start link here:
==>https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Stop_Start.html .
When you stop an Instance, you do not lose any data & you are not
charged for the resources any further. However please keep in mind
that you will still be charged for any EBS Storage Volumes attached to
the stopped Instance(s).
I also recommend checking out the below links on how you can reduce
your costs.
==>https://aws.amazon.com/premiumsupport/knowledge-center/reduce-aws-bill/
==>https://aws.amazon.com/blogs/compute/10-things-you-can-do-today-to-reduce-aws-costs/
That being said, please note that as I am in the billing department,
for the best assistance with the various plans you will require the
assistance of our Sales Team.
The Sales Team will be able to assist with ways to save while
maintaining your configurations.
You will be able to reach the Sales Team here:
==>https://aws.amazon.com/websites/contact-us/.
Once you have completed the details in the link, a member of the team
will be in touch with you at their soonest.

EBS Snapshots, who manages backups?

I'm starting with AWS and I've been taking my first steps on EC2 and EBS. I've learnt about EBS snapshots but I still don't understand if the backups, once you've created a snapshot, are managed automatically by AWS or I need to do them on my own.
AWS just introduced a new feature called Lifecycle Manager (in the EC2 Dashboard, at the bottom left) that allows you to create automated backups for your volumes. Once you configure a policy, AWS will handle the backup process for your volumes.
This is only a couple of weeks old so just wanted to mention here.
Snapshots are managed by AWS
snapshot of an EBS volume, can be used as a baseline for new volumes or for data backup. If you make periodic snapshots of a volume, the snapshots are incremental—only the blocks on the device that have changed after your last snapshot are saved in the new snapshot. Even though snapshots are saved incrementally,
the built in durability of EBS is comparable to a RAID in the physical sense. The data itself is mirrored (think more like a RAID stripe though) in the availability zone where the volume exists. Amazon states that the failure rate is somewhere around 0.1-0.5% annually. This is more reliable than most physical RAID setups

Best option to take complete Backup of EC2 instance?

Currently I am taking manual backup of our EC2 instance by zipping the data and downloading it locally as well as on DropBox.
But I am wondering, can I have an option where I just take a complete copy of the whole system automatically daily so if something goes wrong/crashes, I can replace it with previous copy immediately rather than spending hours installing and configuring things ?
I can see there is an option of take "Image" but can I automated them to have just 1 latest image and replace the system with single click ?
You can create a single Image of your instance as Backup of your instance Configuration.
And
To keep back up of your data you can use snapshots of your volumes.
snapshots store data in incremental format whenever you make any changes.
When ever needed you can just attach the volume from the snapshot to your Instance.
It is not a good idea to do "external backup" for EC2 instance snapshot, before you read AWS pricing details.
First, AWS is charging every GB of data your transfer OUTside AWS cloud. Check out this pricing. Generally speaking, after the 1st GB, the rest will be charge at least $0.09/GB, against S3-standard pricing ~ $0.023/GB.
Second, the snapshot created is actually charges as S3 pricing(Check :
Copying an Amazon EBS Snapshot), not EBS pricing. After offset the transfer cost, perhaps you should consider create multiple snapshot than keep doing the data transfer out backup.
HOWEVER, if you happens to use an instance that use ephemeral storage, snapshot will not help. You need to copy the data out from ephemeral storage yourself. Then it is your choice to store under S3 or other place.
Third. If you worry the AWS region going down, check the multiple AZ option. Or checkout alternate AWS region option.
Fourth. When storing backup data in S3, you can always store them under Infrequent-Access, which save you some bucks, and you don't need to face an insane Glacier bills during emergency restore(Avoid Glacier, unless you are pretty sure about your own requirement).
Fifth, after done your plan of doing everything inside AWS, you can write bash script (AWS CLI) or use boto3, etc API to do the automatic backup.
Lastly , here is way of AWS create and maintain snapshot. Though each snapshot are deem "incremental", when u delete old snap shot :
the snapshot deletion process is designed so that you need to retain
only the most recent snapshot in order to restore the volume.
You can always "test" restore by create another EC2 instance that load the backup snapshot. Or you can mount the snapshot volume from another EC2 instance to check the contents.

RDS incremental backup

We are trying to take incremental back for mysql in RDS. We are unable to find any methods to take incremental backup . How can this be done in RDS ? In FAQ we read that we can restore the data up to last five minutes. But we are not sure how to do that?
You can use AWS Data Pipeline to do this.
It supports full RDS dump or incremental dump and restore.The problem is you cannot reuse a pipeline. You will have to clone the pipeline and create a new one using AWS Lambda or Jenkins or some other job scheduling system each time you want to create a Backup or Restore.
Check out this blog to find more information on that.
a. RDS provides Native incremental backup feature - RDS snapshots and also has a feature called Point in time recovery (PITR). This allows you to restore a state of RDS instance from last 5 minutes upto max 35 days in the past (35 days being the max automatic backup retention period).
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html
b. You can also trigger Manual snapshots in RDS - which is once again incremental (which means that if you have a running RDS server of 1TB your first/base snapshot will be 1TB) and any subsequent snapshots of the same server will only capture the modified blocks. In manual snapshots there is not retention period. You can keep as long as you wish unless you want to delete it manually. But the PITR feature is not available over Manual snapshots (i.e not longer than the configured automatic backup retention window)
In both the above features, you are dependent upon the RDS API/platform to take backup, list all the backups and restore RDS from backup. You dont have any control over the raw data / row level data.
For raw data backup, you need to consider Mysqldumps and restore - but that is an expensive operation (both backup and restore). You can use some third party tools like (percona) which provides good utilities to perform the same - but you cant use few tools because RDS does not allows you with RDS host access - so unless you run your own Mysql on VM/EC2, you are limited to the above 2 options. hope this helps.
https://www.percona.com/doc/percona-xtrabackup/2.3/innobackupex/incremental_backups_innobackupex.html
https://www.percona.com/doc/percona-xtrabackup/2.3/backup_scenarios/incremental_backup.html

How can find out how much space my snapshots are taking in Amazon EC2

I am creating daily snapshots (backups) in Amazon Ec2, and I need to find out how much space the snapshots are taking so that I can remove them if they take up too much space. I have looked and I am unable to find what I need.
I know that its on S3, but I have not seen any bucket created here so that I can see that snapshot.
Also, is there a way to download a snapshot to my computer (where I can store it), and upload it when needed?
Snapshots are persisted to S3, but are not stored in buckets owned by the user - so you won't be able to see them there.
To see how much space is being used by snapshots, you should be able to log in to the AWS Console through your web browser and see it under "Elastic Block Store", or if you've installed the command-line tools by running the ec2-describe-snapshots command you will see the following parameter returned:
volume-size
The size of the volume
As for downloading your snapshots, it's possible with the non-Windows instance snapshots, but it's also quite involved. But here's the instructions.