Skip to content

Instantly share code, notes, and snippets.

@joelparker
Created November 7, 2013 16:05
Show Gist options
  • Save joelparker/7357104 to your computer and use it in GitHub Desktop.
Save joelparker/7357104 to your computer and use it in GitHub Desktop.
Python boto script to delete all archives in an AWS Glacier Vault
import boto.glacier
#These should be filled in by you
GLACIER_KEY_ID=None
GLACIER_SECRET_ACCESS_KEY=None
#You can get the vault ARN from the AWS Console or list_vaults()
GLACIER_VAULT_ARN='FILL IN'
#The job ID is retrieved by calling value.retrieve_inventory_job
#The job takes hours to complete but you can send notification using SNS
#You can get the SNS ARN from the AWS console
#
#connection = boto.connect_glacier()
#vault = connection.get_vault(GLACIER_VAULT_ARN)
#vault.retrieve_inventory_job(sns_topic='SOMETHING LIKE arn:aws:sns:us-east-1:1234567890:my_glacier_sns')
GLACIER_VAULT_JOB_ID='FILL THIS IN'
def main():
#Connect to Glacier Valut
connection = boto.connect_glacier(aws_access_key_id=GLACIER_KEY_ID, aws_secret_access_key=GLACIER_SECRET_ACCESS_KEY)
vault = connection.get_vault(GLACIER_VAULT_ARN)
job = vault.get_job(GLACIER_VAULT_JOB_ID)
response = job.get_output()
deleted_archives=0
errors=0
show_progess=0
progess_threshold=100
total_archives = len(response['ArchiveList'])
for archive in response['ArchiveList']:
show_progess += 1
if show_progess > progess_threshold:
show_progess = 0
print 'Deletes={0}, Errors={1}. {2}%'.format(deleted_archives,errors, (deleted_archives+errors)/float(total_archives)*100)
try:
result = vault.delete_archive(archive['ArchiveId'])
deleted_archives += 1
except:
#Usually a socket error, might be worth retying the call to delete_archive
errors += 1
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment