UPD: Increased sleep wait and added retry loop
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
S3 Batch Restore Script
|
||||
Restores objects from S3 Glacier Deep Archive using AWS S3 Batch Operations.
|
||||
# S3 Batch Restore Script
|
||||
# Restores objects from S3 Glacier Deep Archive using AWS S3 Batch Operations.
|
||||
|
||||
# Generate objectlist.csv with the following script:
|
||||
|
||||
# BUCKET=whk1-bea-icc-mbk-prd-s3-log-infra-log
|
||||
# PREFIX=elb/alb-icc-mbk/AWSLogs/851239346925/elasticloadbalancing/ap-east-1/2025/08/11/
|
||||
# aws s3 ls s3://$BUCKET/$PREFIX | awk "{print \"$BUCKET,$PREFIX\"\$NF}" | tee /tmp/objectlist.csv
|
||||
@@ -157,7 +158,7 @@ def create_batch_job(s3control_client, account_id, role_arn, manifest_spec, repo
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def approve_job(s3control_client, account_id, job_id):
|
||||
def approve_job(s3control_client, account_id, job_id) -> bool:
|
||||
"""Approve the batch job to start execution."""
|
||||
try:
|
||||
s3control_client.update_job_status(
|
||||
@@ -166,9 +167,10 @@ def approve_job(s3control_client, account_id, job_id):
|
||||
RequestedJobStatus='Ready'
|
||||
)
|
||||
print(f"Approved job: {job_id}")
|
||||
return True
|
||||
except ClientError as e:
|
||||
print(f"Error approving job: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
||||
|
||||
def get_account_id(sts_client):
|
||||
@@ -228,11 +230,12 @@ def main():
|
||||
)
|
||||
|
||||
# Wait a bit before approving
|
||||
time.sleep(10)
|
||||
time.sleep(5)
|
||||
|
||||
# Approve job
|
||||
print(f"Approving submitted job {job_id}...")
|
||||
approve_job(s3control_client, account_id, job_id)
|
||||
while not approve_job(s3control_client, account_id, job_id):
|
||||
time.sleep(5)
|
||||
|
||||
print(f"\nReview s3 batch job status. When it is completed, delete the manifest bucket:")
|
||||
print(f"aws s3 rb s3://{manifest_bucket} --force")
|
||||
|
||||
Reference in New Issue
Block a user