Update code scaleway

This commit is contained in:
lapatatedouce
2024-09-03 16:07:23 +02:00
parent 60b35dfed3
commit 06a955e042
2 changed files with 68 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
#!/bin/bash
# This script initiates restoration requests for objects listed in a specified file.
# This script initiates restoration requests for Glacier objects listed in a specified file,
# but only if they haven't been restored yet, do not have an ongoing restoration request,
# and are still in the Glacier storage class. The script processes these objects in parallel
# using xargs to speed up the execution.
# It requires the bucket name, file name, and the number of days for the restoration.
# Example usage:
@@ -24,9 +27,26 @@ if [[ ! -f "$FILE" ]]; then
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"
# Function to process each object
process_object() {
KEY="$1"
STORAGE_CLASS=$(aws s3api head-object --bucket "$BUCKET" --key "$KEY" --query 'StorageClass' --output text)
STATUS=$(aws s3api head-object --bucket "$BUCKET" --key "$KEY" --query 'Restore' --output text)
echo "Restoration requests initiated for objects listed in '$FILE'."
if [[ "$STORAGE_CLASS" != "GLACIER" ]]; then
echo "Skipping $KEY: Already in $STORAGE_CLASS storage class."
elif [[ "$STATUS" == *"ongoing-request=\"true\""* ]]; then
# Skip if there's an ongoing restoration
:
else
echo "Initiating restoration for: $KEY"
aws s3api restore-object --restore-request Days=$DAYS --bucket "$BUCKET" --key "$KEY"
fi
}
export -f process_object
export BUCKET
export DAYS
# Use xargs to run process_object in parallel for each line in the file
cat "$FILE" | xargs -P 4 -I {} bash -c 'process_object "$@"' _ {}