Skip to content

Instantly share code, notes, and snippets.

@camallen
Created September 25, 2018 12:55
Show Gist options
  • Save camallen/8d4c5271b7146104499d786c8619c47b to your computer and use it in GitHub Desktop.
Save camallen/8d4c5271b7146104499d786c8619c47b to your computer and use it in GitHub Desktop.
Download data or request from glacier storage
while read row; do
#echo $row
file_name=$(echo $row | awk '{print $4}')
#echo $file_name
#test if the file is already downloaded
file -E $file_name &> /dev/null
LOCAL_FILE_TEST_RESULT=$?
if [ $LOCAL_FILE_TEST_RESULT -eq 0 ]; then
#echo "${file_name} exists locally - skipping"
continue
fi
# test if we can download the file
bucket_path="data/Galaxy-Zoo-SDSS/COS_stamps_large/${file_name}"
bucket="zooniverse-cold-storage"
s3_path="s3://${bucket}/${bucket_path}"
aws s3 cp --quiet $s3_path .
DOWNLOAD_REQ_RESULT=$?
if [ $DOWNLOAD_REQ_RESULT -eq 0 ]; then
echo "downloaded ${file_name}"
echo $file_name > downloaded.log
else
aws s3api restore-object --restore-request '{"Days":5,"GlacierJobParameters":{"Tier":"Bulk"}}' --bucket ${bucket} --key ${bucket_path}
RESTORE_REQUEST_RESULT=$?
if [ $RESTORE_REQUEST_RESULT -eq 0 ]; then
echo "requested a restore of ${file_name}"
echo $file_name > restore_requests.log
else
echo "failed to request restore ${file_name}"
echo $file_name > failed_restores.log
fi
fi
done <file_list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment