Skip to content

Instantly share code, notes, and snippets.

@hackedunit
Created October 11, 2018 10:44
Show Gist options
  • Save hackedunit/23df4267df4b6cd6213a64d17988e2ba to your computer and use it in GitHub Desktop.
Save hackedunit/23df4267df4b6cd6213a64d17988e2ba to your computer and use it in GitHub Desktop.
Gzip a directory and upload to Azure Blob storage
#!/bin/bash
# Requires azure-cli to be installed
source $HOME/.profile
echo "backing up media dir..."
tar -zcf /tmp/media.gz /var/www/app/shared/media
if [ $? == 0 ]; then
/usr/bin/az storage blob upload --name "media-$(date +%s).gz" --file /tmp/media.gz --container-name "fileuploads" --connection-string "DefaultEndpointsProtocol=https;AccountName=$AZURE_STORAGE_ACCOUNT;AccountKey=$AZURE_STORAGE_ACCESS_KEY;EndpointSuffix=core.windows.net;"
if [ $? == 0 ]; then
echo "success!"
rm /tmp/media.gz
else
>&2 echo "couldn't transfer media.gz to Azure"
fi
else
>&2 echo "couldn't gzip media dir"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment