How to do Linux backups on Azure without shutting the VM down.

I feel Azure has always had a gap of taking VM backups without requiring a host shutdown. Sure I could create a script that would shut my VM’s down take a snapshot and export them to blob storage. However, the problem here is that I don’t want this piece of code running from my local machine. I also don’t want a dedicated host to do this.

Now with the release of http://azure.microsoft.com/en-us/services/automation/ you can easily run PowerShell scripts as a service in azure to get what you need done solving the problem of a dedicated host.

That being said , this still requires you shutting down the VM to take a snapshot.

I imagined we could do this in real-time. What if we simply Tar gz, the whole file system and upload it to azure blob storage?
We could easily get this done using the azure cli and some nifty bash commands. So let’s do it.

Pre reqs:
You need to install Nodejs and then azure-cli on the machine in which you wish to setup monthly backups.

Installing node can be a bit tricky due to another package named node that comes pre installed on ubuntu.
http://stackoverflow.com/questions/16302436/install-nodejs-on-ubuntu-12-10

After you have node installed you’ll need node package manager (npm). Simply run:

sudo apt-get install npm

After npm you can now download the azure-cli run:

sudo npm install azure-cli -g

To make sure this works run :

azure account download

You’ll need to download this from the link provided to tie the cli to your azure account. Once you have the file simply run:

azure account import

If everything goes smoothly you should be good to go with azure CLI. The next part is the actual script which you can download here:
https://github.com/jlark/azurelinuxbackup

First off this is a very basic script so it will tar gz everything under /
With the exception of paths you provide in the local file backupAzure-exc.txt which should be placed locally to the backup script.

Some folders you might wish to avoid are:
/proc/*
/run/*

After words you need to modify a few variables tied to your azure storage account in the backupscript.


storageAccountName=
storageAccountKey=
storageContainer= //excample if your container url is https://backupsalp.blob.core.windows.net/backups you would put in backups

Once you’ve got these in place from the azure portal simply run the script.

If you would like to run this the first of every month you can simple modify cron to do this

Run:
Sudo Crontab -e

And add
0 0 1 * * /<pathto/backupAzure

And you’re done.

Hope that helps.

Alp

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s