tags:

views:

614

answers:

2

I'm looking for the best way to run a nightly script that exports a set of files from a SVN Repository to a local directory. When the export finishes, copy the contents of the local directory to several remote servers.

This will be a scheduled back job running on a Windows Server 2003 machine. Remote servers are all on the network, so there's no need for FTP, etc.

Pseudocode would run like this

1. svn export repo localdir (plus some switches)
2. ... wait to make sure export is finished ...
3. robocopy localdir \\remotedir1
4. robocopy localdir \\remotedir2, etc

I'm very new to writing batch jobs, but I'd like this to be as robust as possible: - copy doesn't start until export is done - if copy to remotedir1 fails, script still proceeds copying to remotedir2,3,etc - is it possible to log problems if there is any trouble at one of the steps?

Any input on what the batch job would look like would be much appreciated!

+1  A: 

Ant (Java required) might be a good candidate for this sort of work.

Ant is a build tool with strong support for the sort of reliance-chains that you describe. The syntax is fairly straightforward as well, since it is just XML.

tehblanx
Thanks for the idea, but I can't really get into installing/learning/using a whole new system. For what I need, a simple scheduled batch job should be sufficient.
AR
+2  A: 

You probably don't need step 2 to wait since SVN blocks while exporting. Apart from that it looks good. You can use

svn export ... || (echo SVN export failed > log.txt & goto :eof)

to log failures and stop the batch if the export fails. || basically tells that the command(s) after the || only get executed when the preceding command fails (errorlevel > 0). goto :eof exits the batch file (or subroutine), alternatively you could use exit /b for this.

You can apply this chaining to the robocopy commands as well:

robocopy ... || echo Copy to remotedir1 failed > log.txt

or something like this.

Another, more verbose way would be an if block after each command you want to safeguard:

if errorlevel 1 (
  echo Stuff > log.txt
)

All of these methods need proper exit codes from the tools, though.

Joey