-
Setup Env vars
export AWS_REGION=<THE_REGION> GLACIER_VAULT=<glacier-vault-name>
-
Initiate an Inventory Retrieval Job
aws glacier initiate-job --account-id - --vault-name $GLACIER_VAULT --job-parameters '{"Type": "inventory-retrieval"}'
🕒 Wait >1day
-
Get the Job Output After the job is completed, get the job ID from the list of jobs
aws glacier list-jobs --account-id - --vault-name $GLACIER_VAULT -
Download the inventory
aws glacier get-job-output --account-id - --vault-name $GLACIER_VAULT --job-id $(aws glacier list-jobs --account-id - --vault-name $GLACIER_VAULT | jq -r '.JobList[0].JobId') $GLACIER_VAULT.json
or
aws glacier get-job-output --account-id - --vault-name $GLACIER_VAULT --job-id <JOB_ID> $GLACIER_VAULT.json
-
Delete Archives Loop through the archive IDs and delete them one by one
while read archive_id; do aws glacier delete-archive --account-id - --vault-name $GLACIER_VAULT --archive-id="$archive_id" done < <(jq -r --stream 'select(.[0][-1]=="ArchiveId") | .[1]' $GLACIER_VAULT.json)
or
jq -r --stream 'select(.[0][-1]=="ArchiveId") | .[1]' $GLACIER_VAULT.json > $GLACIER_VAULT.txt
while read archive_id; do aws glacier delete-archive --account-id - --vault-name $GLACIER_VAULT --archive-id="$archive_id" done < $GLACIER_VAULT.txt
With output
total=$(jq -r --stream 'select(.[0][-1]=="ArchiveId") | .[1]' $GLACIER_VAULT.json | awk 'END{print NR}'); while read -r num archive_id; do echo "[$num/$total] Delete $archive_id" aws glacier delete-archive --account-id - --vault-name $GLACIER_VAULT --archive-id="$archive_id" done < <(jq -r --stream 'select(.[0][-1]=="ArchiveId") | .[1]' $GLACIER_VAULT.json | cat -n)
🕒 Wait >1day
-
Check if it's empty
The
NumberOfArchivesattribute must be0aws glacier describe-vault --account-id - --vault-name $GLACIER_VAULT -
Delete Glacier Vault
aws glacier delete-vault --account-id - --vault-name $GLACIER_VAULT
Based on shared steps https://repost.aws/questions/QUbzfEloStRmm0Q7gkmIFNyg/how-to-delete-a-glacier-vault-that-is-not-empty#ANmCLhUUXJQtuS9fPdQGk79w