Productivity Tools For Web Development (A Monday Series: Part 2)

September 25, 2007

[Note: busy day yesterday! Apologies that this part of my Monday series is being posted on Tuesday. Can anyone say, “post scheduling”? Amen!]

Monday #2: A good* replication process – Oh, man. This is one of my favorites.

When I first started developing for the web, I hated deploying new versions of our web applications. Why? Well, because when I first started, I deployed using the following process:

  1. Copy the newly compiled executable to the clipboard
  2. Open Windows Explorer and navigate to the first web server’s production app directory
  3. Rename the current production version
  4. Paste the executable from my clipboard into the production app directory
  5. Repeat for each web server (less than 10, but not by much)
  6. Weep softly, wondering why I’m still doing something so glaringly inefficient

Best case, doing all that usually took around 2-3 minutes if the network was responding quickly. And pray that there wasn’t a bug that somehow escaped testing, because if there is, the whole process has to be reversed for each server.

Finally, I decided that this was no good. Remember our dear, old friend, the batch file? With a couple of easy steps, a batch file can make all of our wildest dreams come true (assuming that our wildest dreams entail file replication. Be still, my beating heart!)

You’ll need:

  1. A directory into which you can put files you want to replicate – I use C:\replication, but you can create it anywhere you want and call it anything you like
  2. A batch (.BAT) file – There’s a few ways to do this. I have 2 that I use.

    replicate.bat: This allows me to specify a directory as a command line argument. Assuming that your web servers are all configured identically, this will copy the files in your replication directory to the same location on each web server.

    set directory=%1

    for %%f in (1,2,3) do copy /-Y C:\replication \\yourWebServer%%f\d\%directory%

    Example usage from the command prompt: replicate myDirectory\yourShoppingCartApp

    replicate_app.bat: This one copies to the same directory every time, which is what I want when I’m deploying apps.

    for %%f in (1,2,3) do copy /-Y C:\replication \\yourWebServer%%f\productionApps

    Example usage from the command prompt: replicate_app

Once those are set up, just compile or copy your executable to your replication directory. Open a command prompt and run your batch file of choice to deploy your file(s) to all servers in one shot. Total elapsed time: 10 seconds or less.

To save a backup of the current production app, I rename it and put it in the replication directory right next to the new version I want to deploy. Then when I run the replication, the backup is copied to each server along with the new version. You know – just in case. . .

I know there are various utilities that’ll achieve similar effects, but I don’t know of a good free one. And then of course there’s Windows File Replication Service, but that’s sort of low on my list at the moment.

Got a better way to do it? Let me know in a comment.

*”Good” in relative terms. 🙂


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: