Quick reference examples for Amazon AWS Glacier command line interface (CLI)

I do not use Amazon AWS Glacier very often. I backing up my files to Glacier every a few months. So I hate to check the manual all the time. Hence, this blog post.

Preparation


Make sure that you have the ~/.aws/config and ~/.aws/credentials configured. In terms of how to set up, look at here: http://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html

I would also assume that you are familiar with the terminology of AWS Glacier.

Listing vaults


In case that you forget what vaults you have in an AWS data center, do this:

aws glacier list-vaults  --account-id - --region us-east-2 --output table

Initiating a job for inventory retrieval


Basically if you wanna know what is in a vault, you do this.

aws glacier initiate-job --account-id - --vault-name myvault --region us-east-2 --job-parameters "{\"Type\": \"inventory-retrieval\", \"Format\":\"CSV\", \"Description\":\"what's in my Neuro vault?\"}"

For more details, refer to http://docs.aws.amazon.com/amazonglacier/latest/dev/api-initiate-job-post.html and http://docs.aws.amazon.com/cli/latest/reference/glacier/initiate-job.html

To my surprise, I don't need to specify which profile to use. The AWS CLI seems to automatically find the profile/credential that match the data center and vault name.

Listing jobs


Fetching the inventory is a job. In case the job ID is lost, here is the way to get it back.

aws glacier list-jobs --account-id - --region us-east-1 --vault-name myvault --output table

I always prefer table-format output.

Fetching job result


Either archive retrieval (download the file uploaded to the vault) or inventory retrieval is a job. You need to fetch the result after the job is done. Depending on the type of job, you will either get an inventory in the format specified (JSON by default) or the file uploaded to the vault. Be sure to specify the correct job ID.

aws glacier get-job-output --account-id - --region us-east-1 --job-id xxxyyyzzz --vault-name myvault data.txt

Deleting an archive


aws glacier delete-archive --account-id - --vault-name myvault --archive-id xxxyyyzzz

No comments: