Is this the right way to backup my ec2 instance? (+some questions)

0

Hi, I am an AWS EC2 free-tier user and I would like to know if the way I backup is a correct or not. So, the way I currently backup is

  1. Make a snapshot from an ebs volume
  2. Make an AMI from the snapshot
  3. Make a new instance from that AMI
  4. Terminate the pervious instance and detach the volume from the instance as well
  5. Attach the new instance with a new volume to my domain(www.blahblah)
  6. Change my domain public ip to the new instance public ip.

I have done my backup this way but I am not sure if the way I do it is correct or not. Please let me know if there is anything that I am missing.

+I have some few more questions other than the procedure of the ebs snapshot backup. My questions are

  1. How to check how much volume is left in the current ebs storage? (I want to check for the free space in my ebs. I have heard that we need to size up the ebs volume when there are more files and more snapshots in the volume. 'df -hT /dev/xvda1' command didn't show the ebs volume that are free.)
  2. Do I get a notification when my ebs storage is almost full?
  3. Do I need to stop my instance when I am making a snapshot? (For the current backup, I didn't stop my instance when I took a snapshot and It was fine. but on the internet, people seem to say it is better to stop the instance before taking a snapshot. so I'm confused.)
  4. Is using S3 mandatory to store ebs snapshots? (I'm currently not using S3 but I have seen people storing ebs snapshots in their S3 storage. so I'm not sure if If I need to store them in S3.)

Thanks!

asked a year ago428 views
2 Answers
0

Take a look at this blog for how to automate backing up your EBS volumes: Automating Amazon EBS snapshot management using Data Lifecycle Manager.

You don't need to create the AMI and boot up a new instance unless your are trying to restore the volume (steps 2-6).

  1. You have to use the OS/Filesystem commands to determine usage, like 'df'.
  2. No, not by default. You can install the CloudWatch agent to monitor OS level resources and get alerts, see: Collect metrics and logs from Amazon EC2 instances and on-premises servers with the CloudWatch agent
  3. No, no need to stop
  4. S3 is used by the EBS service, you can't control this or see the bucket where your snapshots are stored.
profile pictureAWS
EXPERT
kentrad
answered a year ago
  • Hi, Thank you for the quick response. I am a bit confused by "You don't need to create the AMI and boot up a new instance unless your are trying to restore the volume (steps 2-6).".

    If I don't create an AMI from the snapshot, how do I backup my current instance? In snapshot action, we have

    1. create volume
    2. create image
    3. manage fast snapshot restore etc

    If I don't create an image(AMI) to backup, should I create a volume from that snapshot and attach it to the current instance? Or should I do the fast snapshot restore? (but I have heard that fast snapshot restore is expensive though...)

    Thanks!

  • I got it, I created a volume from the snapshot and it worked out fine. Thanks!!

0

Adding some information to question (3):

Do you need to stop your instance before doing a snapshot? No, you don't. However the snapshot process is not aware of the state that the filesystem on the disks is in. Nor is it aware of the state that any application data might be in.

For example, if the operating system is in the middle of writing a file but has not yet updated the file allocation table (or whatever the equivalent is for that particular operating system) and you take a snapshot right then the filesystem in the snapshot is in a state which isn't (for want of a better word) "stable". That means when you restore from snapshot the new volume will be in the same state. Most operating systems will recover from this gracefully but you might lose the contents of the file. Maybe. It depends.

If you're running a database on the instance and the database is in the middle of committing a transaction and you take a snapshot at that exact moment then the database will be in an unknown state in the snapshot. Same thing applies - the database engine might automatically fix that problem on the next startup (on the new volume); or it might not. And the data might be lost. Or not. Again, it depends.

So it is safer to stop your instance to do a snapshot? Yes. If the filesystem is relatively stable but you're running a database then you might want to stop write operations to the database while you're doing the snapshot - that could be done at an application level or within the database. That way you know that the database is fully written to disk before the snapshot is taken.

profile pictureAWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions