Sunday, January 20, 2013

Copy EC2 EBS

It is possible to make clone of the EBS volume other than from the AWS console (and then move it between AWS servers, zones or accounts).

Via AWS console, attach EBS volume to the temporary server.

First step - fill  with zeros all free space on the disk (because for removed files data still stored on the disk). This will prepare drive for better data compression.

$ mount /dev/xvdf /mnt/disk1
$ dd if=/dev/zero of=/mnt/disk1/tmp/zero bs=10M
$ rm /mnt/disk1/tmp/zero
$ umount /mnt/disk1


Copy and compress raw drive data:

$ cat /dev/xvdf | bzip2 >image.bz2
*This may take some minutes.

Then you can copy this file to another server (via scp, ftp, ...)
And finally you can restore this image on the EBS-volume of the same size as the original.

$ bzcat image.bz2 >/dev/xvdf

No comments:

Post a Comment