Howto detele archive in AWS Glacier Vault

Post writed only as note for me. All information fount on docs https://docs.aws.amazon.com/cli/latest/reference/glacier/delete-archive.html and from github https://gist.github.com/veuncent/ac21ae8131f24d3971a621fac0d95be5

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
Script:
#!/usr/bin/env bash

file='./output.json'
id_file='./output-archive-ids.txt'

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
fi

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
fi
total=$(wc -l $id_file | awk '{print $1}')
echo "got $total"

num=0
while read -r archive_id; do
  num=$((num+1))
  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"

wait
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.

  1. No comments yet.

  1. No trackbacks yet.

You must be logged in to post a comment.