A client error (InvalidObjectState) occurred when calling the CopyObject operation: Operation is not valid for the source object’s storage class.

A client error (InvalidObjectState) occurred when calling the CopyObject operation: Operation is not valid for the source object’s storage class.

This is because the file is in Amazon Glacier. You have to restore it to S3 before aws cli or s3cmd will be able to work with it.

When an S3 file is in Glacier it’s sort of like an offline reference. You know how with OneDrive/Skydrive, when you sign in with your phone for the first time and browse your files – they’re not actually on your phone. But in the case of OneDrive if you ask to open the file it’s kind enough to figure out that it should download it automatically for you 😉

How do you get something from Glacier back to S3?

Install AWS CLI

Configure AWS CLI (this uses multiple profiles)
aws configure –profile myprofile
— fill in the key/secret key

Modify this script, filling in the stuff between the “<...>“. The “–profile ….” part would be “myprofile” if you used what I typed above. do “chmod u+x ” to make it executable:


#!/bin/sh

# This will give you a nice list of all objects in the bucket with the bucket name stripped out
s3cmd ls -r s3:// | awk '{print $4}' | sed 's#s3:///##' > glacier-restore.txt

for x in `cat glacier-restore.txt`
do
echo "Begin restoring $x"
aws s3api restore-object --restore-request Days=7 --bucket --profile --key "$x"
echo "Done restoring $x"
done

You’ll see a lot of “NoSuchBucket” messages because the glacier-restore.txt file has a lot of folder names in it, when it really should just have object names. But that’s ok. Fix it if you want 😉