Eden Ridgway's Blog

.Net and Web Development Information

  Home :: Contact :: Syndication  :: Login
  105 Posts :: 1 Stories :: 78 Comments :: 3 Trackbacks

Search

Article Categories

Archives

Post Categories

Development

General

Today I came across a blog posting that contained a NAnt task for Redgate SQL Compare. This task would be quite useful if you planned on continuously upgrading a build server or test database with the latest development changes. However I was looking to backup our current database and drop it in a location that was accessible to our client. So I wrote the following NAnt task:

<target name="BackupDatabase" >
<property name="project.dir" value="C:\Development\Northwind"/>
<
property name="target.dir" value="C:\"/>
<
property name="server" value="(local)"/>
<
property name="databaseName" value="Northwind"/>

<!-- Backup the DB into the project directory -->

<exec program="osql.exe" verbose="true">
<arg line="-E -S ${server} -Q &quot;BACKUP DATABASE ${databaseName} TO DISK = '${project.dir}\${databaseName}.bak'&quot;"/>
</
exec>

<!-- Zip up the database in the project dir and copy it to the target dir -->
<zip zipfile="${target.dir}${databaseName}Database ${datetime::get-month(datetime::now())}-${datetime::get-day(datetime::now())}-${datetime::get-year(datetime::now())}.zip">
<fileset basedir="${project.dir}">
<include name="${databaseName}.bak" />
</
fileset>
</zip>

<!-- Remove the temporary database backup from the project dir -->
<delete>
<fileset basedir="${project.dir}">
<include name="${databaseName}.bak" />
</
fileset>
</delete>
</target>
posted on Sunday, August 14, 2005 5:50 AM
Comments have been closed on this topic.