NAnt Task to Restore a SQL Server Database

In my long tradition of releasing odd utilities (ok, utility) that no one but me uses I think I've come up with a winner.  On one of my projects we've created an extensive database build process using NAnt.  This process creates the database with all its objects and runs a series of jobs to populate data.  Much of that data comes from other databases on the same server.  At the start of the build process we need to restore a series of database backups as of specific dates.  Since this script can run against a variety of developer workstations, test servers, QA servers, etc. we need to restore these backups into a variety of directories.

This NAnt task will restore a database backup onto the target server.  The task will query the server to determine the proper location for the data files and log files and move them to the proper directory.  It will also rename the files based on the database name.  It can set the database to simple recovery mode and shrink it.  It handles multiple data and log files but only restores the first backup in a backup file.

You can download the binary and the source code.  It is a NAnt task so you'll need to be using NAnt to use it.  Installation is as simple as dropping the DLL into NAnt's bin directory.

If you're running any kind of build script in your development process and aren't using NAnt I'd encourage you to look at it.  It's a great tool!

UPDATE: I've release 0.92 which you can download here: (binary and source code)

UPDATE: I've released 0.94.

Show Comments