11

Is there any way to dump/save EBS volume/snapshot to file or mount it to local Linux file-system?

I found only this old thread and this script which intends to save it via S3 and doesn't seem very reliable. I also found this online-tool, but it didn't work for me. It doesn't even contain all available regions.

I do NOT seek rsync-based solutions.

Can we directly download EBS as .img or .iso file in a dd manner?

Suncatcher
  • 552
  • 2
  • 7
  • 22

3 Answers3

10

AWS don't provide a way to download or extract the actual block device that makes up an EBS volume. The standard way to grab a copy is to use rsync, but as you're after a block level way of doing this, this article might be of some use.

In short (and in case the link above disappears), use netcat and dd at both ends, e.g;

On the sender (your EC2 instance to which the volume is attached):

dd bs=16M if=/dev/sda|bzip2 -c|nc receiver.example.net 19000

On the receiver (your PC, backup server, etc):

nc -l 19000|bzip2 -d|dd bs=16M of=/path/to/my/volume.img

Which will transfer the entire contents of the block-level device over port 19000 in 16MB bzipped chunks, though it can also be done over ssh instead, but according to their performance stats, is much, MUCH slower! Naturally you need to consider the security aspect of doing it this way as well. If your block device has sensitive data on it, encrypting it with SSH or using a VPN tunnel is highly recommended instead, and the transfer speed slowdown is a reasonable trade-off.

One other thing to note is that filesystems can be cached in memory, so could result in a corrupted image. Unmount your volume (but leave it attached to the instance) before running the above to ensure filesystem consistency.

To grab a copy of a snapshot, you'll need to create a volume from it, attach it to an instance, then do the above. There is no other way to access a snapshot's data.

dannosaur
  • 953
  • 5
  • 15
  • OK, thanks. Will try this way. Should I start listening on receiver (`nc -l`) **prior** to starting dd on sender? – Suncatcher Apr 25 '18 at 18:01
  • Yes. The dd process (and thus the pipe) will start funnelling data though it almost immediately. If the receiver isn't listening, netcat on the sender will either timeout, or immediately raise a connection refused error (or similar), then the entire process will stop. – dannosaur Apr 25 '18 at 18:06
  • 3
    This method will "technically" work but remember that file systems are cached in memory. This method often results in corrupted file systems on restore. Dismount all volumes before block copying any device. This means that you cannot dismount the root file system volume so that device cannot be block copied. – John Hanley Apr 26 '18 at 20:24
  • @JohnHanley good point! I've updated the answer to reflect this. – dannosaur Apr 27 '18 at 09:18
  • Thank you. I have upvoted your answer with the improvements. – John Hanley Apr 27 '18 at 17:13
  • Awesome! Fantastically it works. Fantastically for me, Linux-noob :) – Suncatcher May 02 '18 at 18:07
  • Thank you. It worked perfectly. – gdegani Jun 11 '19 at 07:59
  • As I understand, it is not possible to dump root volume in this way? I.e. it is not possible to `dd` the volume the OS booted from now? – Suncatcher Jan 20 '20 at 11:10
  • @Suncatcher yes and no. You'll still be able to `dd` the volume, but as @JohnHanley said, you can't unmount it, so you'll likely have consistency issues with the resulting image. The best thing to do here is to detach the volume from the instance and attach it as a second volume to another instance to `dd` it. Or snapshot the volume then attach it back to the instance and image the snapshot instead. – dannosaur Jan 24 '20 at 20:30
  • Thanks for the advice, will try. – Suncatcher Jan 25 '20 at 14:13
1

best try this site. use ftp client like winscp. https://asf.alaska.edu/how-to/data-recipes/moving-files-into-and-out-of-an-aws-ec2-instance-windows/

Avikash
  • 11
  • 1
  • 2
    Please answer the question on SF directly instead of linking to outside sources only, as links have a tendency to go stale over the course of time! – Stuggi Feb 15 '20 at 09:21
-1

Looks like cloudberry does it.

https://www.cloudberrylab.com/blog/cloudberry-backup-cloud-to-local-backup-functionality/

user2099762
  • 133
  • 2
  • 4
  • 18
  • It looks like it supports only user S3 backup, while EBS volumes [are not accessible](https://serverfault.com/a/774078/309819) from user side. – Suncatcher Apr 25 '18 at 16:49