Skip to content

Commit

Permalink
Merge pull request #383 from molgenis/fix/migrate-minio-skip-rds
Browse files Browse the repository at this point in the history
fix: skip rds files in minio migration
  • Loading branch information
marikaris authored Jul 18, 2023
2 parents 0c5d01c + d39331e commit f6c4a09
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions scripts/migrate-minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import getopt
import sys
import pprint
from getpass import getpass
from pathlib import Path

Expand Down Expand Up @@ -64,7 +65,11 @@ def download_all_buckets(target_dir: Path):
def download_bucket(minio_client: Minio, bucket: Bucket,
target_dir: Path):
bucket_dir = target_dir.joinpath(bucket.name)
obj_count = download_objects(bucket.name, bucket_dir, minio_client)
obj_count, skipped = download_objects(bucket.name, bucket_dir, minio_client)

if len(skipped) > 0:
print("The following rds files weren't copied and will have to be regenerated:")
pprint.pprint(skipped)

if obj_count == 0:
print("> No files found")
Expand Down Expand Up @@ -94,16 +99,20 @@ def create_minio_client():
def download_objects(bucket_name: str, bucket_dir: Path, client: Minio) -> int:
objects = client.list_objects(bucket_name, recursive=True)
obj_count = 0
skipped = []
for obj in objects:
print("- " + obj.object_name)
target_file = bucket_dir.joinpath(obj.object_name)
client.fget_object(
bucket_name,
obj.object_name,
file_path=str(target_file)
)
obj_count += 1
return obj_count
if str(target_file).lower().endswith(".rds"):
skipped.append(str(target_file))
else:
print("- " + obj.object_name)
client.fget_object(
bucket_name,
obj.object_name,
file_path=str(target_file)
)
obj_count += 1
return obj_count, skipped


if __name__ == '__main__':
Expand Down

0 comments on commit f6c4a09

Please sign in to comment.