04.04.2022

Das Löschen eines großen AWS-Glacier-Archivs mit der AWS CLI ist eine mühsame Angelegenheit. Für jede Datei muss einzeln die ID ermittelt werden und ein Löschbefehl abgesetzt werden. Nachfolgendes Script macht da das Leben etwas leichter.

Quelle

AWS Doku Glacier Delete Vault

AWS CLI Kommandos

    accountid 999999999999
    
    Server jobid     ADU1FNTeTqF2x55BrkuZvPucRfs0EHYqbJCGfpm7UwcS631-pP1Ew44Qc7Gd7nlT5dmBJ3MWbMn1MRR_14dX_6NWXy5J
    Personal jobid   A-4lyhjqgiZjra_k6aifd7GZTWLZmWiQaEbLAZNRyV-E42xChbWlGCVB7puvZgxEK6R5hhzVuveAr-r55hf0OBmvBYuD
    Mediafiles jobid AXG9He9_pzlGqrpCRCcU9Yi2xy6RGP3I26AkMrbaF7hsmOso9RyJNM1Gxn2mXhiDEipOHSaOsAaCntTLjPrftc759VKC
    
    aws glacier initiate-job --vault-name NAS-Server --account-id 999999999999 --job-parameters '{"Type": "inventory-retrieval"}'
    aws glacier describe-job --vault-name NAS-Server --account-id 999999999999 --job-id ADU1FNTeTqF2x55BrkuZvPucRfs0EHYqbJCGfpm7UwcS631-pP1Ew44Qc7Gd7nlT5dmBJ3MWbMn1MRR_14dX_6NWXy5J
    aws glacier get-job-output --vault-name NAS-Server --account-id 999999999999 --job-id ADU1FNTeTqF2x55BrkuZvPucRfs0EHYqbJCGfpm7UwcS631-pP1Ew44Qc7Gd7nlT5dmBJ3MWbMn1MRR_14dX_6NWXy5J output.json
    aws glacier delete-archive --vault-name NAS-Server --account-id 999999999999 --archive-id="*** archiveid ***"
    
    aws glacier initiate-job --vault-name NAS-Personal --account-id 999999999999 --job-parameters '{"Type": "inventory-retrieval"}'
    aws glacier describe-job --vault-name NAS-Personal --account-id 999999999999 --job-id A-4lyhjqgiZjra_k6aifd7GZTWLZmWiQaEbLAZNRyV-E42xChbWlGCVB7puvZgxEK6R5hhzVuveAr-r55hf0OBmvBYuD
    aws glacier get-job-output --vault-name NAS-Personal --account-id 999999999999 --job-id A-4lyhjqgiZjra_k6aifd7GZTWLZmWiQaEbLAZNRyV-E42xChbWlGCVB7puvZgxEK6R5hhzVuveAr-r55hf0OBmvBYuD output.json
    aws glacier delete-archive --vault-name NAS-Personal --account-id 999999999999 --archive-id="*** archiveid ***"
    
    aws glacier initiate-job --vault-name NAS-Mediafiles --account-id 999999999999 --job-parameters '{"Type": "inventory-retrieval"}'
    aws glacier describe-job --vault-name NAS-Mediafiles --account-id 999999999999 --job-id AXG9He9_pzlGqrpCRCcU9Yi2xy6RGP3I26AkMrbaF7hsmOso9RyJNM1Gxn2mXhiDEipOHSaOsAaCntTLjPrftc759VKC
    aws glacier get-job-output --vault-name NAS-Mediafiles --account-id 999999999999 --job-id AXG9He9_pzlGqrpCRCcU9Yi2xy6RGP3I26AkMrbaF7hsmOso9RyJNM1Gxn2mXhiDEipOHSaOsAaCntTLjPrftc759VKC output.json
    aws glacier delete-archive --vault-name NAS-Mediafiles --account-id 999999999999 --archive-id="*** archiveid ***"

Python Script zum Erstellen des Löschscripts

    import json
    
    # read file
    with open('output.json', 'r') as myfile:
        data=myfile.read()
    
    # parse file
    obj = json.loads(data)
    
    # show values
    #print("VaultARN: " + str(obj['VaultARN']))
    txt = str(obj['VaultARN'])
    arr = txt.partition(':vaults/')
    tok = arr[0]
    vaultname = arr[2]
    accountid = tok.rpartition(':')[2]
    archiveid = 'unknown'
    
    print ("#! /bin/sh")
    print ("echo JobID: " + arr[0]);
    print ("echo accountid: " + accountid);
    print ("echo vaultname: " + vaultname);
    
    ct = 0
    for elem in obj['ArchiveList']:
    	archiveid = str(elem['ArchiveId'])
    	print ("aws glacier delete-archive --vault-name "+vaultname+" --account-id "+accountid+" --archive-id=\"" + archiveid +"\"")
    	print ("echo -n " + str(ct))
    	ct = ct + 1
    print (str(ct) + " deleted archives")
Über … ×

doc.stumpp.name
Version 0.2.14

Michael Stumpp
michael@stumpp.name

Diese Webseite ist ein rein privates Angebot. Von dieser Seite werden keine Cookies oder andere Tracking-Methoden eingesetzt. Die Seite nutzt, soweit möglich, lokale Kopien der eingesetzen Bibliotheken und Ressourcen.

Lizenz: ISC ×
/*
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
Release Notes ×
  doc.stumpp.name
  Version 0.2.14
  Release Notes


  v0.1
    + Erstausgabe