Update code scaleway
This commit is contained in:
42
backup_and_restore/scaleway/list-glacier-objects.sh
Executable file
42
backup_and_restore/scaleway/list-glacier-objects.sh
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This script counts the number of objects stored in the Glacier storage class within an S3 bucket.
|
||||||
|
# It optionally filters the list based on a specified directory within the bucket.
|
||||||
|
|
||||||
|
# Example usage:
|
||||||
|
# ./count-glacier-objects.sh my-bucket my-directory
|
||||||
|
# (Counts Glacier objects in the 'my-directory' directory within the 'my-bucket' bucket)
|
||||||
|
# ./count-glacier-objects.sh my-bucket
|
||||||
|
# (Counts all Glacier objects in the 'my-bucket' bucket)
|
||||||
|
|
||||||
|
# Check the number of arguments
|
||||||
|
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
||||||
|
echo "Usage: $0 <bucket_name> [directory_name]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Retrieve the arguments
|
||||||
|
BUCKET="$1"
|
||||||
|
DIRECTORY="$2"
|
||||||
|
|
||||||
|
# Function to sanitize names (though not necessary for an output file in this version)
|
||||||
|
sanitize_name() {
|
||||||
|
echo "$1" | tr -dc '[:alnum:]-_.'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Construct the AWS CLI command
|
||||||
|
COMMAND="aws s3api list-objects-v2 --bucket $BUCKET --query \"Contents[?StorageClass=='GLACIER']\""
|
||||||
|
|
||||||
|
# Add the prefix if a directory is specified
|
||||||
|
if [[ -n "$DIRECTORY" ]]; then
|
||||||
|
COMMAND+=" --prefix $DIRECTORY"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Finalize the command to count the objects
|
||||||
|
COMMAND+=" --output text | wc -l"
|
||||||
|
|
||||||
|
# Execute the command and retrieve the number of Glacier files
|
||||||
|
NUM_FILES=$(eval $COMMAND)
|
||||||
|
|
||||||
|
# Display the number of Glacier files
|
||||||
|
echo "Number of files in Glacier storage class to be restored: $NUM_FILES"
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/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.
|
# It requires the bucket name, file name, and the number of days for the restoration.
|
||||||
|
|
||||||
# Example usage:
|
# Example usage:
|
||||||
@@ -24,9 +27,26 @@ if [[ ! -f "$FILE" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Iterate through the file and initiate restoration requests
|
# Function to process each object
|
||||||
while read -r KEY; do
|
process_object() {
|
||||||
aws s3api restore-object --restore-request Days=$DAYS --bucket $BUCKET --key "$KEY"
|
KEY="$1"
|
||||||
done < "$FILE"
|
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 "$@"' _ {}
|
||||||
|
|||||||
Reference in New Issue
Block a user