Skip Navigation LinksHome > View Post

Getting started with the CLI and backing up your scripts (Day 4)

One of the things I love about Mobile Services is the zero-friction, no impedance approach to development. It just feels so much fun to fire up a new service, start scripting and have a custom API in the sky in a matter of minutes.

Sometimes, I do this and before I know it (literally within 30 minutes) I have a pretty advanced service and a bunch of scripts that I’d really hate to lose. And, whilst I feel great that my data and scripts are safely stored in Windows Azure, it’s still entirely possible for me to lose that work by doing something silly like accidentally deleting the whole mobile service.

Wouldn’t it be cool if I could easily backup my mobile services scripts? Yes. Well, enter just one cool possibility created by the CLI that Scott announced in his post the other day.

In case you didn’t catch it, here’s a quick overview…

We recently added Mobile Services support to the Azure Cross-Platform CLI. You can see all of the code that powers this thing on github. Yup, it’s sweet, sweet open source.

To run and install the xplat CLI you’ll need node. Since Mobile Services runtime runs in node this is a great thing to have on your machine already, so go get it: install nodeJS.

image

Seriously, install it now because we’ll need it later in this very series!

And once you’re done, you can start to use node and NPM. If you’re not familiar, NPM is Node’s Package Manager. .NET guys can think of it as NuGet for NodeJS; iOS guys can think of it as CocoaPods for NodeJS.

NPM is also the way you install the azure xplat CLI. Open the (freshly installed) Node.js command prompt:

IMPORTANT, all of these commands work identically in terminal on the Mac.

image

And once opened you can execute the necessary npm command: npm install –g azure-cli

image

Once done, you can start to use the azure commands. The first thing you’ll need to do, is import your publishsettings to allow you to securely connect the your azure services. There’s even a CLI command to help you with this. Just type:

azure account download

This will pop a browser window that will help you download your publish settings for your azure subscription(s).

SNAGHTMLb0d8159

Note that you may need to login to your azure account here. Once done, you’ll be presented with a download of a file with a .publishsettings extension. Save this somewhere memorable and safe because it contains the key to manage your azure services. The next step, is to import this:

azure account import .\path\to\your\download.publishsettings

This will have you all setup, to test, why not list your mobile services using

azure mobile list

image

Very cool! Now, let’s get on to backing up our scripts. I mentioned above that everything we’ve done so far works great on Mac and Linux, so let’s use some of those built in terminal commands to start our backup. The ideas is easy, we’ll be using these two commands

azure mobile script list <servicename>
azure mobile script download <servicename> <scriptname>

The first will list all of your scripts (include scheduled etc) and the second can download the script. Great, so we can download all our scripts to a local folder in bash with this simple script:

azure mobile script list <servicename> | grep 'table/' | awk '{system("azure mobile script download <servicename> "$2)}'

image

And you’re done! You’ll now have a folder ‘table’ with all your scripts:

image

You can use exactly the same on a Windows machine if you have a bash terminal (chances are you do, if you have git installed). Here’s the same command running on Windows and my files, thanks to gitbash!

image

This was day 4 of the series: the twelve days of ZUMO. We’ll be back tomorrow pushing the CLI even harder!

 
Josh Post By Josh Twist
11:46 PM
24 Dec 2012

» Next Post: More CLI &ndash; changing your Mobile Services workflow (Day 5)
« Previous Post: Filter this (Day 3)

Comments are closed for this post.

Posted by Nick @ 13 Mar 2013 11:31 AM
Hey, just tried to follow these steps and ran into issues importing the account information (ie azure account import). Turns out that there seems to be an incompatibility between the current version of Node.js and the azure cli (look for "FATAL ERROR: JS Allocation failed - process out of memory" at http://www.windowsazure.com/en-us/manage/linux/other-resources/command-line-tools/). I uninstalled Node.js and went back to v0.8 and it all works.

Posted by Martin Suchan @ 17 Mar 2013 9:14 PM
How much time should the "azure account import ..." command take? I'm stuck several minutes on "Setting service endpoint..." line.

© 2005 - 2014 Josh Twist - All Rights Reserved.