How can I copy my Amazon EBS snapshot data to Amazon S3 and create EBS volumes for custom data in S3?

Last updated: 2022-11-29

I want to copy an Amazon Elastic Block Store (Amazon EBS) snapshot to my Amazon Simple Storage Service (Amazon S3) bucket. I also want to create Amazon EBS volumes from data that's stored in my S3 bucket. But, I don't know how.

Short description

When you create an EBS snapshot, it's automatically stored in an Amazon S3 bucket that's managed by Amazon Web Services (AWS). You can copy snapshots within the same AWS Region, or from one Region to another. However, you can't copy snapshots to S3 buckets that you manage.

To store snapshots that you infrequently access, consider using Amazon EBS Snapshots Archive. However, if you still prefer to use Amazon S3 to store your snapshots, then you can use the following workaround.

Resolution

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.

You can copy the contents of your snapshot to your S3 bucket by creating a volume from the snapshot. Mount the volume to an Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. Then, copy the data to your S3 bucket using the AWS CLI or S3 APIs.

To copy the contents of your EBS snapshots to an Amazon S3 bucket, follow these steps:

1.    Create an EBS volume from the snapshot.

2.    Launch an EC2 Linux instance in the same Availability Zone as the volume that you created.

3.    Attach the volume to the instance.

4.    Connect to your Linux instance.

5.    Install the AWS CLI on your Linux instance.

6.    Run the following command to mount the volume to your instance:

$ sudo mount /dev/xvdf /mnt

Note: The device (/dev/xvdf, in the preceding example) might be attached to the instance with a different device name. Use the lsblk command to view your available disk devices along with their mount points to determine the correct device names.

7.    Install the pv package to monitor the progress during tar archive creation:

Amazon Linux and Red Hat Enterprise Linux (RHEL) distributions

$ sudo yum install pv

Note: Before you install the pv package for Amazon Linux and RHEL distributions, you must turn on the Extra Packages for Enterprise Linux (EPEL) repository. See How do I turn on the EPEL repository for my Amazon EC2 instance running CentOS, RHEL, or Amazon Linux?

Ubuntu and Debian based distributions

$ sudo apt install pv

8.    Run the following command to copy the EBS volume data to your S3 bucket:

$ tar c /mnt | pv -s $(($(du -sk /mnt | awk '{print $1}') * 1024)) | gzip | aws s3 cp - "s3://my-bucket/backup1.tar.gz"

Note: The preceding command creates a compressed file from the /mnt directory and uploads the file to the S3 bucket named my-bucket. Replace my-bucket with your S3 bucket's name and backup1 with your file's name.

9.    Use the Amazon S3 console to confirm that the compressed file is uploaded to your S3 bucket.

10.    Run the following command to unmount the volume:

$ sudo umount /mnt

Did this article help?


Do you need billing or technical support?