-
Notifications
You must be signed in to change notification settings - Fork 11
Add biobank merge code #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mandawilson
merged 8 commits into
knowledgesystems:master
from
callachennault:biobank-merge
Jun 18, 2026
Merged
Add biobank merge code #1304
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9455b3
Add biobank merge code
callachennault 223ef68
fix download_from_S3 commands
callachennault 6800733
Merge branch 'master' into biobank-merge
mandawilson 0b79fec
Skip biobank merge non-fatally when S3 download or combine fails.
mandawilson 8461bc3
Add try_upload/download S3 helpers while preserving fatal wrappers.
mandawilson a184bab
Simplify biobank merge to call try_download_from_s3 directly.
mandawilson 3a15081
Use bulk-synced biobank files instead of re-downloading from S3.
mandawilson 10f99b1
Document arguments for S3 upload and download helpers.
mandawilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,18 +5,25 @@ if ! [ -n "$PORTAL_HOME" ] ; then | |
| exit 1 | ||
| fi | ||
|
|
||
| # Uploads a file or directory to an S3 bucket (from local to S3) | ||
| # If a directory is provided, files removed locally will be deleted from S3 | ||
| # PATH_TO_UPLOAD must end in the same path as PATH_IN_S3, or the script exits with an error | ||
| function upload_to_s3() { | ||
| # Uploads a file or directory to an S3 bucket (from local to S3). | ||
| # If a directory is provided, files removed locally will be deleted from S3. | ||
| # Returns 0 on success, 1 on failure (does not exit the shell). | ||
| # | ||
| # Args: | ||
| # $1 PATH_TO_UPLOAD Local file or directory to upload (must exist). | ||
| # $2 PATH_IN_S3 S3 key prefix within the bucket (no s3:// prefix). Must match | ||
| # the trailing path of PATH_TO_UPLOAD, unless empty to sync the | ||
| # bucket root (e.g. upload_to_s3 "$DMP_DATA_HOME" "" "mskimpact-databricks"). | ||
| # $3 BUCKET_NAME S3 bucket name (e.g. mskimpact-databricks). | ||
| function try_upload_to_s3() { | ||
| PATH_TO_UPLOAD="$1" | ||
| PATH_IN_S3="$2" | ||
| BUCKET_NAME="$3" | ||
|
|
||
| # Check if path exists | ||
| if [ ! -e "$PATH_TO_UPLOAD" ]; then | ||
| echo "`date`: Path '$PATH_TO_UPLOAD' does not exist, exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| # Normalize paths | ||
|
|
@@ -28,7 +35,7 @@ function upload_to_s3() { | |
| if [ -n "$PATH_IN_S3_CLEAN" ]; then | ||
| if [[ "$PATH_TO_UPLOAD_ABS" != *"/$PATH_IN_S3_CLEAN" && "$PATH_TO_UPLOAD_ABS" != "$PATH_IN_S3_CLEAN" ]]; then | ||
| echo "`date`: ERROR – PATH_IN_S3 ('$PATH_IN_S3') must exactly match the trailing path of '$PATH_TO_UPLOAD_ABS'. Exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
|
|
@@ -56,38 +63,61 @@ function upload_to_s3() { | |
| --profile saml | ||
| else | ||
| echo "`date`: '$PATH_TO_UPLOAD' is neither a file nor a directory, exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "`date`: Failed to upload '$PATH_TO_UPLOAD' to S3, exiting..." | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| # Uploads a file or directory to an S3 bucket (from local to S3). | ||
| # If a directory is provided, files removed locally will be deleted from S3. | ||
| # Exits 1 on failure. | ||
| # | ||
| # Args: | ||
| # $1 PATH_TO_UPLOAD Local file or directory to upload (must exist). | ||
| # $2 PATH_IN_S3 S3 key prefix within the bucket (no s3:// prefix). Must match | ||
| # the trailing path of PATH_TO_UPLOAD, unless empty to sync the | ||
| # bucket root (e.g. upload_to_s3 "$DMP_DATA_HOME" "" "mskimpact-databricks"). | ||
| # $3 BUCKET_NAME S3 bucket name (e.g. mskimpact-databricks). | ||
| function upload_to_s3() { | ||
| if ! try_upload_to_s3 "$1" "$2" "$3"; then | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Syncs a file or directory from S3 to a local path | ||
| # Files not in S3 will be removed from the local destination (for directories) | ||
| # PATH_TO_OVERWRITE must end in PATH_IN_S3 (if provided), and cannot be "/" | ||
| function download_from_s3() { | ||
| # Syncs a file or directory from S3 to a local path. | ||
| # Files not in S3 will be removed from the local destination (for directories). | ||
| # Returns 0 on success, 1 on failure (does not exit the shell). | ||
| # | ||
| # Args: | ||
| # $1 PATH_TO_OVERWRITE Local file or directory to sync into (must already exist; cannot be "/"). | ||
| # $2 PATH_IN_S3 S3 key prefix within the bucket (no s3:// prefix). Must match | ||
| # the trailing path of PATH_TO_OVERWRITE, unless empty to sync the | ||
| # bucket root (e.g. download_from_s3 "$DMP_DATA_HOME" "" "mskimpact-databricks"). | ||
| # $3 BUCKET_NAME S3 bucket name (e.g. mskimpact-databricks). | ||
| function try_download_from_s3() { | ||
| PATH_TO_OVERWRITE="$1" | ||
| PATH_IN_S3="$2" | ||
| BUCKET_NAME="$3" | ||
|
|
||
| # Normalize local path | ||
| if [ -z "$PATH_TO_OVERWRITE" ]; then | ||
| echo "`date`: PATH_TO_OVERWRITE is empty, exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| PATH_TO_OVERWRITE_ABS=$(realpath "$PATH_TO_OVERWRITE" 2>/dev/null) | ||
| if [ $? -ne 0 ]; then | ||
| echo "`date`: '$PATH_TO_OVERWRITE' does not exist, exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| if [ "$PATH_TO_OVERWRITE_ABS" == "/" ]; then | ||
| echo "`date`: Refusing to sync to root directory '/', exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| # Clean PATH_IN_S3 | ||
|
|
@@ -97,7 +127,7 @@ function download_from_s3() { | |
| if [ -n "$PATH_IN_S3_CLEAN" ]; then | ||
| if [[ "$PATH_TO_OVERWRITE_ABS" != *"/$PATH_IN_S3_CLEAN" && "$PATH_TO_OVERWRITE_ABS" != "$PATH_IN_S3_CLEAN" ]]; then | ||
| echo "`date`: ERROR – PATH_IN_S3 ('$PATH_IN_S3') must exactly match the trailing path of '$PATH_TO_OVERWRITE_ABS'. Exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
|
|
@@ -129,11 +159,27 @@ function download_from_s3() { | |
|
|
||
| else | ||
| echo "`date`: '$PATH_TO_OVERWRITE_ABS' is neither a file nor a directory, exiting..." | ||
| exit 1 | ||
| return 1 | ||
| fi | ||
|
|
||
| if [ $? -ne 0 ]; then | ||
| echo "`date`: Failed to download from '$S3_SOURCE', exiting..." | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| # Syncs a file or directory from S3 to a local path. | ||
| # Files not in S3 will be removed from the local destination (for directories). | ||
| # Exits 1 on failure. | ||
| # | ||
| # Args: | ||
| # $1 PATH_TO_OVERWRITE Local file or directory to sync into (must already exist; cannot be "/"). | ||
| # $2 PATH_IN_S3 S3 key prefix within the bucket (no s3:// prefix). Must match | ||
| # the trailing path of PATH_TO_OVERWRITE, unless empty to sync the | ||
| # bucket root (e.g. download_from_s3 "$DMP_DATA_HOME" "" "mskimpact-databricks"). | ||
| # $3 BUCKET_NAME S3 bucket name (e.g. mskimpact-databricks). | ||
| function download_from_s3() { | ||
| if ! try_download_from_s3 "$1" "$2" "$3"; then | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above - would document args |
||
| exit 1 | ||
| fi | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.