A script to transfer azure storage containers to another storage
Here is an example of a script to copy azure storage containers from one storage to another and keep public access level. It uses Azure CLI and AzCopy tools.
#!/bin/bash
STORAGE_NAME_SOURCE="<source_account_name>"
STORAGE_KEY_SOURCE="<source_account_key>"
STORAGE_NAME_DEST="<dest_account_name>"
STORAGE_KEY_DEST="<dest_account_key"
CONNECTION_STRING_SOURCE="DefaultEndpointsProtocol=https;AccountName=$STORAGE_NAME_SOURCE;AccountKey=$STORAGE_KEY_SOURCE"
CONNECTION_STRING_DEST="DefaultEndpointsProtocol=https;AccountName=$STORAGE_NAME_DEST;AccountKey=$STORAGE_KEY_DEST"
containers=$(az storage container list --connection-string $CONNECTION_STRING_SOURCE --output tsv | awk '{print $2}')
for i in $containers;
do
docker run --rm incendonet/azcopy azcopy --source https://$STORAGE_NAME_SOURCE.blob.core.windows.net/$i --source-key $STORAGE_KEY_SOURCE --destination https://$STORAGE_NAME_DEST.blob.core.windows.net/$i --dest-key $STORAGE_KEY_DEST --recursive
access_level=$(az storage container show-permission -n $i --connection-string $CONNECTION_STRING_SOURCE --output tsv)
az storage container set-permission -n $i --connection-string $CONNECTION_STRING_DEST --public-access $access_level
done