AWS Glacier CLI Command

Archived some of my files in Glacier for cold storage, jot down some note which I think useful.

To Download

aws glacier initiate-job --account-id <ACCOUNT_ID> --vault-name <VAULT_NAME> \
--job-parameters '{"Type": "inventory-retrieval"}'

Response as below, “InProgress” indicate it’s currently retrieving your vault information.

{
    "JobList": [
        {
            "InventoryRetrievalParameters": {
                "Format": "JSON"
            },
            "VaultARN": "arn:aws:glacier:us-east-1:<ACCOUNT_ID>:vaults/<VAULT_NAME>",
            "Completed": false,
            "JobId": "1IDvzqYMBTlQ22HZGpr3KmOfeyHV2BIAq3LipToKr3MiN86bTtjb4UiHCVV5Pi4q8fxNhl",
            "Action": "InventoryRetrieval",
            "CreationDate": "2018-09-29T22:19:34.973Z",
            "StatusCode": "InProgress"
        }
    ]
}

OK, tried few hours later and it showed “Succeeded”, go on…

{
    "JobList": [
        {
            "CompletionDate": "2018-09-30T02:07:27.572Z",
            "VaultARN": "arn:aws:glacier:us-east-1:<ACCOUNT_ID>:vaults/<VAULT_NAME>",
            "InventoryRetrievalParameters": {
                "Format": "JSON"
            },
            "Completed": true,
            "InventorySizeInBytes": 4783,
            "JobId": "1IDvzqYMBTlQ22HZGpr3KmOfeyHV2BIAq3Lip",
            "Action": "InventoryRetrieval",
            "CreationDate": "2018-09-29T22:19:34.973Z",
            "StatusMessage": "Succeeded",
            "StatusCode": "Succeeded"
        }
    ]
}

Get archive list with command below which will lead to output written in archive.json.

aws glacier get-job-output --account-id <ACCOUNT_ID> --vault-name <VAULT_NAME> \
--job-id 1IDvzqYMBTlQ22HZGpr3KmOfeyHV2BIAq3Lip archive.json
{
    "VaultARN": "arn:aws:glacier:us-east-1:<ACCOUNT_ID>:vaults/<VAULT_NAME>",
    "InventoryDate": "2018-08-26T21:40:40Z",
    "ArchiveList": [{
            "ArchiveId": "y3QIkLkxRIXLiL1j_lII1yvW13jscAk-wEuifLkoX_SJVCLF6T",
            "ArchiveDescription": "{\"Path\":\"CBB+20180822T070618Z\"}",
            "CreationDate": "2018-08-22T07:07:13Z",
            "Size": 5981,
            "SHA256TreeHash": "072603eaf03ba5ae4eb10083be3285a3ef577f4c"
        },
        {
            "ArchiveId": "IevypBp2RazhieImIi6-y3QIkLkxRIXLiL1j_lII1yvW13jscAk",
            "ArchiveDescription": "{\"Path\":\",\"UTCDateModified\":\"20180822T070623Z\"}",
            "CreationDate": "2018-08-22T07:07:14Z",
            "Size": 1663,
            "SHA256TreeHash": "cede08ebde7ef2fdf36f4610fc4620df56bc64"
        }
    ]
}

Then create a json file with sample content below indicate which archive to download (I use download.json in this case)

{
    "Type": "archive-retrieval",
    "ArchiveId": "dXVi00Z5j1og1REd-zEN1vmP8VB4delaX_mDdGr5IxA",
    "Description": "Test retrieval"
}

Then execute command below:

aws glacier initiate-job  --account-id <ACCOUNT_ID> --vault-name <VAULT_NAME> \
--job-parameters file://download.json

You get response as:

{
    "location": "/<ACCOUNT_ID>/vaults/<VAULT_NAME>/jobs/NiejXgaVsBVWXmNAm6A_ZYhJpgxSiZ8v2aKmGFscLMhXmUg1V",
    "jobId": "NiejXgaVsBVWXmNAm6A_ZYhJpgxSiZ8v2aKmGFscLMhXmUg1V"
}

Check the status job status:

aws glacier list-jobs --account-id <ACCOUNT_ID> --vault-name <VAULT_NAME>
{
    "JobList": [{
            "VaultARN": "arn:aws:glacier:us-east-1:<ACCOUNT_ID>:vaults/<VAULT_NAME>",
            "RetrievalByteRange": "0-6479072",
            "Tier": "Standard",
            "SHA256TreeHash": "a125bef84b6a47bf0e291c6f2f87cfb2b7ffc53955ba88fe164fd3",
            "Completed": false,
            "JobId": "Gx9PNiejXgaV7A6yDre1UZVq4WgBlN3wRuzAm6A_ZYhJpgxSiZ8v2aKmGFscLMhXmUg1V",
            "ArchiveId": "dXVi00Z5MI-P-ItzAo06hc9yE8Ca9nGSzyU5gIj1og1REd-zEN1vmP8VB4delaX_mDdGr5IxA",
            "JobDescription": "Test retrieval",
            "ArchiveSizeInBytes": 6479073,
            "Action": "ArchiveRetrieval",
            "ArchiveSHA256TreeHash": "a125bef84b6a47bf0e291c6f2f87cfb2b7ffc53955ba88fe164fd3",
            "CreationDate": "2018-09-30T12:06:03.400Z",
            "StatusCode": "InProgress"
        }
    ]
}

Come back few hours/minutes, check the status and it’s now turn to “Succeeded”

{
    "JobList": [
        {
            "CompletionDate": "2018-09-30T15:51:05.858Z",
            "VaultARN": "arn:aws:glacier:us-east-1:<ACCOUNT_ID>:vaults/<VAULT_NAME>",
            "RetrievalByteRange": "0-6479072",
            "Tier": "Standard",
            "SHA256TreeHash": "a125bef84b6a47bf0e291c6f2f87cfb2b7ffc53955ba88fe164fd3",
            "Completed": true,
            "JobId": "Gx9PNiejXgaV7A6yDre1UZVq4WgBlN3wRuzAm6A_ZYhJpgxSiZ8v2aKmGFscLMhXmUg1V",
            "ArchiveId": "dXVi00Z5MI-P-ItzAo06hc9yE8Ca9nGSzyU5gIj1og1REd-zEN1vmP8VB4delaX_mDdGr5IxA",
            "JobDescription": "Test retrieval",
            "ArchiveSizeInBytes": 6479073,
            "Action": "ArchiveRetrieval",
            "ArchiveSHA256TreeHash": "a125bef84b6a47bf0e291c6f2f87cfb2b7ffc53955ba88fe164fd3",
            "CreationDate": "2018-09-30T12:06:03.400Z",
            "StatusMessage": "Succeeded",
            "StatusCode": "Succeeded"
        }
    ]
}

Finally you can download your file with command below:

aws glacier get-job-output \
  --account-id <ACCOUNT_ID> \
  --vault-name <VAULT_NAME> \
  --job-id "Gx9PNiejXgaV7A6yDre1UZVq4WgBlN3wRuzAm6A_ZYhJpgxSiZ8v2aKmGFscLMhXmUg1V" \
  movie.zip

To Upload

aws glacier upload-archive --account-id - --vault-name <VAULT_NAME> --archive-description "YOUR_NOTE" --body <FILE_NAME>

To Delete

aws glacier delete-archive --account-id <ACCOUNT_ID> --vault-name <VAULT_NAME> --archive-id "<ARCHIVE_ID>"

 

Credit to: softwaredevelopmentstuff.com & madboa.com