As this blog runs on a Ubuntu VPS I wanted to ensure that I get daily backups of it for obvious reasons. I opted for Azure Storage account - Cool tier for that.

In order to setup the daily backups the steps followed include downloading

1) azcopy tool and adding it to the PATH

cd /usr/binwget
tar -xzvf azcopy_linux_amd64_10.3.4.tar.gzmv azcopy_linux_amd64_10.3.4 azcopy
PATH=$PATH:/usr/bin/azcopysource ~/.bashrc

Verify using the azcopy --version

2) Create the storage account, file share and the shared access signature that will be used. Note here that other authentication methods are available described on the azcopy reference link. The storage account is using the Cool tier as the backup will not be accessed frequently. In addition a retention policy can be set to delete older backups after X amount of time.

Shared Access Signature generation 

3) Write the shell script for it and setup the cron job. The backup script should zip the website folder, upload to file share and delete the zip. I'm excluding the node_modules and the versions folder to reduce the size as both are restorable using npm.$(date +%Y-%m-%d-%H-%M).zip
zip -q -x var/www/* var/www/* -r $FNAME /var/www/
sudo /usr/bin/azcopy/azcopy copy "$FNAME" ""sudo rm -rf "$FNAME"

Use crontab -e to edit or create current user crontab file and add  

0 0 * * * ~/ At 00:00 every day the script will execute.

To make sure the cronjob is working at first I set it to */1 * * * * which means every minute.

It took a while to get the right user permissions for azcopy / script execution, for debugging have a look on the /var/mail/<username>

permission issue with azcopy during cron job execution
successful execution of the cron job 

Using Azure Storage Manager I can instantly validate it

Thanks for reading.