Backup Amazon S3 bucket with AWS CLI

Written on May 02, 2014

If you want to backup or download an entire Amazon S3 bucket you’ll probably notice that this isn’t possible through the AWS Management Console. Fortunately this is super easy using the AWS Command Line Interface (CLI).

First download and install the AWS CLI on your system:

To make sure that the AWS CLI installed correctly, open the command prompt and type aws help. You should see the help displayed.

Next, configure the CLI at least with the minimal configuration. In your command prompt, type aws configure and set the values for your AWS access keys, the default region name (e.g us-east-1) and your default output format json:

> aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json

Once, that is done you can go ahead and backup these precious buckets. Use the s3 sync command to do so. For instance type aws s3 sync s3://yourbucket . in the CLI:

> aws s3 sync s3://yourbucket .
download: s3://yourbucket/001.tgz to 001.tgz
download: s3://yourbucket/002.tgz to 002.tgz
download: s3://yourbucket/003.tgz to 003.tgz
...

This will download all of your files and directories within that bucket.

Martin Buberl

Purveyor of Internet duct tape.
If you'd like to get in touch, feel free to shout @martinbuberl.