Howto detele archive in AWS Glacier Vault

Howto detele archive in AWS Glacier Vault

Post writed only as note for me. All information fount on docs and from github

First step: create job for retrieve information in Vault

aws glacier initiate-job --job-parameters '{"Type": "inventory-retrieval"}' --account-id - --vault-name VM-test 
    "location": "/727672876752/vaults/VM-test/jobs/OLMDWS22tHYasKGnvdT-L9l4ryYX1NKnE6SNnwztrgbw5wMNZuXUjzdTPd-HRKUGv6jNxnwA3fysoeb5M4yj4N9_lblQ",
    "jobId": "OLMDWS22tKVfeKGnvdT-L9l4ryGTDSnE6SNnwztrgbw5wMNZuXUjzdTPd-HRKUGv6jNxnwA3fysoeb5M4yj4N9_lblQ"

Get status of our Job

aws glacier list-jobs --account-id - --vault-name VM-test
    "JobList": [
            "JobId": "OLMDWS22tKVfeKGnvdT-L9l4ryYHFESnE6SNnwztrgbw5wMNZuXUjzdTPd-HRKUGv6jNxnwA3fysoeb5M4yj4N9_lblQ",
            "Action": "InventoryRetrieval",
            "VaultARN": "arn:aws:glacier:eu-central-1:727633333352:vaults/VM-test",
            "CreationDate": "2020-04-25T11:34:14.142Z",
            "Completed": false,
            "StatusCode": "InProgress",
            "InventoryRetrievalParameters": {
                "Format": "JSON"

When status wil be “Completed: true” we can download list of archives and start remove all data from Vault using script from github

aws glacier get-job-output --account-id - --region YOUR_REGION --vault-name VM-test --job-id YOUR_JOB_ID ./output.json
#!/usr/bin/env bash


if [[ -z ${AWS_ACCOUNT_ID} ]] || [[ -z ${AWS_REGION} ]] || [[ -z ${AWS_VAULT_NAME} ]]; then
        echo "Please set the following environment variables: "
        echo "AWS_ACCOUNT_ID"
        echo "AWS_REGION"
        echo "AWS_VAULT_NAME"
        exit 1

echo "Started at $(date)"

echo -n "Getting archive ids from $file..."
if [[ ! -f $id_file ]]; then
  cat $file | jq -r --stream ". | { (.[0][2]): .[1]} | select(.ArchiveId) | .ArchiveId" > $id_file 2> /dev/null
total=$(wc -l $id_file | awk '{print $1}')
echo "got $total"

while read -r archive_id; do
  echo "Deleting archive $num/$total at $(date)"
  aws glacier delete-archive --archive-id=${archive_id} --vault-name ${AWS_VAULT_NAME} --account-id ${AWS_ACCOUNT_ID} --region ${AWS_REGION} &
  [ $( jobs | wc -l ) -ge $( nproc ) ] && wait
done < "$id_file"

echo "Finished at $(date)"
echo "Deleted archive ids are in $id_file"

Start script and wait. You can freely to change the variable “$( nproc )” for the CPU thread will be used.

Залишити відповідь