Skip to content

Instantly share code, notes, and snippets.

@hitenpratap
Created July 3, 2018 09:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitenpratap/a9e672b624604b47cfe0fb5ac660e226 to your computer and use it in GitHub Desktop.
Save hitenpratap/a9e672b624604b47cfe0fb5ac660e226 to your computer and use it in GitHub Desktop.
Download Latest Blob from a container using Azure CLI
#!/bin/bash
echo "Downloading latest Database dump from Sandbox Server"
AZURE_STORAGE_CONNECTION_STRING=""
AZURE_CONTAINER_NAME=""
AZURE_DB_ZIP_FILE_NAME=$(az storage blob list --connection-string "$AZURE_STORAGE_CONNECTION_STRING" --container-name "$AZURE_CONTAINER_NAME" --query "reverse(sort_by([], &properties.lastModified)[*].{name: name, lastModified: properties.lastModified})[:1]" --prefix "sandbox" | jq '.[0] | {name}.name')
AZURE_DB_ZIP_FILE_NAME=${AZURE_DB_ZIP_FILE_NAME//\"/}
echo $AZURE_DB_ZIP_FILE_NAME
rm -rf /mnt/tempSandboxData/*
echo "Dowloading latest sandbox db dump named ===>>> $AZURE_DB_ZIP_FILE_NAME"
az storage blob download --connection-string "$AZURE_STORAGE_CONNECTION_STRING" --file "/mnt/tempSandboxData/latest-sandbox-db-dump.zip" --name "$AZURE_DB_ZIP_FILE_NAME" --container-name "$AZURE_CONTAINER_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment