|
| 1 | +# AWS Glacier: Clear vault |
| 2 | +Follow these steps to clear all archives from an AWS glacier vault. |
| 3 | +After this is finished, you will be able to delete the vault itself through the browser console. |
| 4 | + |
| 5 | +## Step 1 / Retrieve inventory |
| 6 | +This will create a job that collects required information about the vault. |
| 7 | +```sh |
| 8 | +$ aws glacier initiate-job --job-parameters '{"Type": "inventory-retrieval"}' --account-id YOUR_ACCOUNT_ID --region YOUR_REGION --vault-name YOUR_VAULT_NAME |
| 9 | +``` |
| 10 | + |
| 11 | +This can take hours or even days, depending on the size of the vault. |
| 12 | +Use the following command to check if it is ready: |
| 13 | +```sh |
| 14 | +aws glacier list-jobs --account-id YOUR_ACCOUNT_ID --region YOUR_REGION --vault-name YOUR_VAULT_NAME |
| 15 | +``` |
| 16 | + |
| 17 | +Copy the `JobId` (including the quotes) for the next step. |
| 18 | + |
| 19 | +## (Alternative Step / Set Job Notification) |
| 20 | +If you do not want to check your job status continously, you can create a notification to receive a email when your job is finished. [Configuring Vault Notifications Using the AWS Command Line Interface](https://docs.aws.amazon.com/amazonglacier/latest/dev/configuring-notifications-cli.html) |
| 21 | + |
| 22 | +```sh |
| 23 | +aws glacier set-vault-notifications --account-id YOUR_ACCOUNT_ID --vault-name YOUR_VAULT_NAME --vault-notification-config ~/notificationconfig.json |
| 24 | +``` |
| 25 | + |
| 26 | +Or you enable it via the aws console: [Configuring Vault Notifications by Using the S3 Glacier Console](https://docs.aws.amazon.com/amazonglacier/latest/dev/configuring-notifications-console.html) |
| 27 | + |
| 28 | +## Step 2 / Get the ArchivesIds |
| 29 | +The following command will result in a file listing all archive IDs, required for `step 3`. |
| 30 | +```sh |
| 31 | +$ aws glacier get-job-output --account-id YOUR_ACCOUNT_ID --region YOUR_REGION --vault-name YOUR_VAULT_NAME --job-id YOUR_JOB_ID ./job-output.json |
| 32 | +``` |
| 33 | + |
| 34 | +## Step 3 / Delete archives |
| 35 | +Set the following parameters through environment variables: |
| 36 | +```sh |
| 37 | +export AWS_ACCOUNT_ID=YOUR_ACCOUNT_ID |
| 38 | +export AWS_VAULT_NAME=YOUR_VAULT_NAME |
| 39 | +``` |
| 40 | + |
| 41 | +And run the script via npx/pnpx: |
| 42 | +```sh |
| 43 | +npx @chieforz/clear-aws-glacier ./archive-log.json |
| 44 | + |
| 45 | +pnpx @chieforz/clear-aws-glacier ./archive-log.json |
| 46 | +``` |
| 47 | + |
| 48 | +All additional parameters will be passed to the aws cli sdk: |
| 49 | +[Command line options](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-options.html) |
| 50 | + |
| 51 | +For debugging you can pass --verbose to disable the progress bar. |
| 52 | + |
| 53 | +# Acknowledgement |
| 54 | +This tutorial is based on: [https://gist.github.com/Remiii/507f500b5c4e801e4ddc |
| 55 | +icon](https://gist.github.com/veuncent/ac21ae8131f24d3971a621fac0d95be5) |
0 commit comments