Have you ever been in a situation where you lost access to your AWS EC2 instance or EBS (Elastic Block Storage) for some reason? Reason can be anything like lost of key pair or misconfigured firewall etc.
Today we will see, how we can recover data in such case without any 3rd part recovery software or any 3rd person’s help withing in 8-10 min only. Please note: this solution may not work if your EBS is encrypted.
Before we start, you must know “How to setup EC2“.
Now, let’s get started.
Create a snapshot of EBS Volume you wish to recover data from. For creating a snapshot, goto Elastic Block Storage -> Volumes.
Wright clicks on EBS volume and select snapshot. (Refer the image below).
Give an identifiable name to new snapshot and save.
Now, your snapshot is being created and you can see its progress in “Snapshot” option under “Elastic Block Storage”. Once Progress completed copy snapshot ID.
Create a new instance and select Operating System as same as a previously misconfigured instance.
In step 4: Add Storage, click “Add New Volume” and select “EBS” as Volume type, /dev/sdf or /dev/sde as a Device.
Paste copied snapshot id in Snapshot textbox. It will show you auto-suggestion, select your snapshot.
Size should be the same as the previous instance storage. In my case, it is 30GB.
Now “Review and Launch” your instance.
Download a new key pair and log in using any SSH client, like putty.
After successful login, use lsblk command to list disk devices and their mount point.
Check if the volume has any data? Using the following command. (if morethan 1 device is there, it can be xvdf1)
sudo file -s /dev/xvdf
If the above command output shows “/dev/xvdf: data”, it means your volume is empty.
Create a directory of your choice to mount our EBS volume. I am using the name “backup”
sudo mkdir /backup
Mount the volume to “backup” directory using the following command.
sudo mount /dev/xvdf /backup/
Done, now you can access all your data of old EBS into “backup” directory.