How to reset EC2 ubuntu instance?
Asked Answered
D

4

16

My client created a ubuntu server 16.04 to deploy a web app. And I have been getting difficulties the get the app deployed properly ...

So is there a way for me to reset the server back to its original state via command line?

Drunkard answered 19/8, 2017 at 11:40 Comment(2)
What is the "original" state you are referring to?Alcibiades
Before installing any app. You know when you first hit ssh -i key.pem [email protected]Drunkard
A
9

AWS doesn't have a feature like VmWare's restore snapshot. If you want the machine restore to its original state, you have to launch the machine again. But it will get a different IP. There is no way to reset your instance to its original state.

Update: Please check this answer as Amazon recently added this feature in 2021. Check this Amazon link

Alcibiades answered 19/8, 2017 at 11:55 Comment(2)
even removing all what is been installed once get access?Drunkard
Even if you uninstall, it is still not a original instance. You never know if uninstall did a good job. There is no guarantee the dependencies are uninstalled correctly.Alcibiades
L
31
  1. Go to the EC2 Dashboard -> Instances
  2. Select the instance you want to reset.
  3. Hit the dropdown menu for "Actions" -> "Monitor and troubleshoot" -> "Replace root volume"

enter image description here

Lith answered 28/4, 2021 at 13:13 Comment(6)
No , that doesnt work in fact. You need BEFOREHAND at least one (1) Snapshot , like @drsromero suggested.Fluidize
@Fluidize No, you can provide a snapshot ID to restore to, but it's NOT mandatory. You can leave the box empty, as the line about it says "Specify a snapshot to restore the root volume to that state. Or omit the snapshot to restore the root volume to its initial launch state."Darrick
"Monitor and troubleshoot" doesn't exist as an option under actionsWindstorm
@Windstorm I added a picture for youLith
Note: this requires the instance to be running AFAIKOrizaba
Worked for me. One note: if you're in a windows OS using the terminal to ssh,(with public key file) when you finish the process, it may not let you ssh right away and give you this error message: ` WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!`. In this case, find your C:\Users\USER\.ssh\known_hosts file, edit and delete the line with the server IP so it will generate a new fingerprint next time you ssh (due to the AWS instance ID that might have changed).Cingulum
A
9

AWS doesn't have a feature like VmWare's restore snapshot. If you want the machine restore to its original state, you have to launch the machine again. But it will get a different IP. There is no way to reset your instance to its original state.

Update: Please check this answer as Amazon recently added this feature in 2021. Check this Amazon link

Alcibiades answered 19/8, 2017 at 11:55 Comment(2)
even removing all what is been installed once get access?Drunkard
Even if you uninstall, it is still not a original instance. You never know if uninstall did a good job. There is no guarantee the dependencies are uninstalled correctly.Alcibiades
L
1

Did you created a snapshot before deploying the app? If not you need to redeploy the AMI in a new EC2 instance.

Lysias answered 19/8, 2017 at 11:49 Comment(2)
I just the orignal state of the ubuntu instance before even installing any app, you know when you first issue "ssh -i key.pem [email protected]"Drunkard
you can't do it without a snapshot. I recommend you using a third party software for EC2 backups I use Nakivo B&R because I can restore single files or complete instances. There is a free version for 3 ec2, here you have some tutorials here I wrote dbigcloud.com/backups/…Lysias
C
0

The feature of replacing Root Volumes was introduced in April 2021 and has been extended to also work for Bare Metal EC2 Mac Instances in Feb 2023 (see this blog post).

To reset an instance to its initial launch state, you can either do it in the EC2 Console ("Actions" -> "Monitor and troubleshoot" -> "Replace root volume" as detailed in another answer) or use this command line:

aws ec2 create-replace-root-volume-task --region <your-instance-region-here> --instance-id <your-instance-id-here> --delete-replaced-root-volume

If you already have a snapshot you want to revert to instead, simply add --snapshot-id <your-snapshot-id-here> to the command line above.

Calceiform answered 24/7, 2024 at 20:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.