Skip to content

Commit

Permalink
add restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-butcher committed Jun 12, 2024
1 parent 1b73bc3 commit c73786e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/transferrer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import logging
logging.basicConfig(level=logging.INFO)
26 changes: 26 additions & 0 deletions src/transferrer/check_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging
from transferrer.common import should_download_file, shoot_number_to_folder_path, get_source_bucket

logger = logging.getLogger(__name__)


def check_shoot_restore_status(bucket, shoot_number):
check_folder_restore_status(bucket, shoot_number_to_folder_path(shoot_number))


def check_folder_restore_status(bucket, s3_folder: str):
print(s3_folder)
for obj in bucket.objects.filter(Prefix=s3_folder, OptionalObjectAttributes=[
'RestoreStatus',
]):
if should_download_file(obj.key):
status = obj.restore_status
else:
status = "ignored"
logger.info(f"{obj.key}\t{status}")


if __name__ == "__main__":
import sys
shoot_number = sys.argv[1]
check_shoot_restore_status(get_source_bucket(), sys.argv[1])
13 changes: 8 additions & 5 deletions src/transferrer/restore.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import os
import logging

from transferrer.common import should_download_file, shoot_number_to_folder_path, get_source_bucket

logger = logging.getLogger(__name__)


def restore_s3_folder(bucket, s3_folder: str, days_to_keep=1):
print(s3_folder)
logger.info(f"restoring folder {s3_folder}")
for obj in bucket.objects.filter(Prefix=s3_folder):
print(obj.key)
if should_download_file(obj.key):
print(obj.restore_object(
logger.info(obj.restore_object(
RestoreRequest={
'Days': days_to_keep,
'GlacierJobParameters': {
'Tier': 'Bulk'
}
}
))
else:
logger.info(f"ignoring {obj.key}")


def restore_shoot_folder(bucket, shoot_number):
Expand All @@ -25,7 +28,7 @@ def restore_shoot_folder(bucket, shoot_number):
def restore_shoot_folders(shoot_numbers):
bucket = get_source_bucket()
for shoot_number in shoot_numbers:
print(f"restoring {shoot_number}")
logger.info(f"restoring shoot {shoot_number}")
restore_shoot_folder(bucket, shoot_number)


Expand Down
Empty file added src/transferrer/transfer.py
Empty file.

0 comments on commit c73786e

Please sign in to comment.