Commit initial après suppression de l'historique

This commit is contained in:
lapatatedouce
2024-09-03 02:24:27 +02:00
commit 9f96c67463
6 changed files with 423 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#!/bin/bash
# This script initiates restoration requests for objects listed in a specified file.
# It requires the bucket name, file name, and the number of days for the restoration.
# Example usage:
# ./restore-glacier-objects.sh my-bucket object-list.txt 3
# (Initiates restoration for objects listed in 'object-list.txt' in 'my-bucket' for 3 days)
# Check the number of arguments
if [[ $# -ne 3 ]]; then
echo "Usage: $0 <bucket_name> <file_name> <number_of_days>"
exit 1
fi
# Retrieve arguments
BUCKET="$1"
FILE="$2"
DAYS="$3"
# Check if the file exists
if [[ ! -f "$FILE" ]]; then
echo "Error: The file '$FILE' does not exist."
exit 1
fi
# Iterate through the file and initiate restoration requests
while read -r KEY; do
aws s3api restore-object --restore-request Days=$DAYS --bucket $BUCKET --key "$KEY"
done < "$FILE"
echo "Restoration requests initiated for objects listed in '$FILE'."

View File

@@ -0,0 +1,52 @@
#!/bin/bash
# This script lists objects stored in the Glacier storage class within an S3 bucket.
# It optionally filters the list based on a specified directory within the bucket.
# The output is saved to a text file with a sanitized name based on the bucket and directory.
# Example usage:
# ./list-glacier-objects.sh my-bucket my-directory
# (Lists objects in the 'my-directory' directory within the 'my-bucket' bucket)
# ./list-glacier-objects.sh my-bucket
# (Lists all objects in the 'my-bucket' bucket)
# Vérification du nombre d'arguments
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Utilisation: $0 <nom_du_bucket> [nom_du_répertoire]"
exit 1
fi
# Récupération des arguments
BUCKET="$1"
DIRECTORY="$2"
# Fonction pour "nettoyer" les noms pour le fichier de sortie
sanitize_name() {
echo "$1" | tr -dc '[:alnum:]-_.'
}
# Construction du nom de fichier de sortie
SANITIZED_BUCKET=$(sanitize_name "$BUCKET")
if [[ -n "$DIRECTORY" ]]; then
SANITIZED_DIRECTORY=$(sanitize_name "$DIRECTORY")
OUTPUT_FILE="${SANITIZED_BUCKET}_${SANITIZED_DIRECTORY}_glacier-restore.txt"
else
OUTPUT_FILE="${SANITIZED_BUCKET}_glacier-restore.txt"
fi
# Construction de la commande AWS CLI
COMMAND="aws s3api list-objects-v2 --bucket $BUCKET --query \"Contents[?StorageClass=='GLACIER']\""
# Ajout du préfixe si un répertoire est spécifié
if [[ -n "$DIRECTORY" ]]; then
COMMAND+=" --prefix $DIRECTORY"
fi
# Finalisation de la commande avec la sortie formatée
COMMAND+=" --output text | awk '{print \$2}' > $OUTPUT_FILE"
# Exécution de la commande
eval $COMMAND
# Message de confirmation
echo "Liste des objets Glacier enregistrée dans $OUTPUT_FILE"