Jay Harris's blog on .net development, automation, and improving quality through code. RSS 2.0
# Tuesday, August 23, 2005

With all that we stuff into the database on the QA environment, we need to perform a regular database restore. This way, we also get a fresh DB without any of the corruption from the previous day’s QA attacks.

I created a NAnt script to automate the process, including restoring security access when we restore from a backup created on a different machine. Centerting around the NAnt code below, my script disconnects all current connections to the database in question (we can not restore the DB without dropping it, and we can not drop it while connections are open), drops and restores the database, refreshes security, and performs a few other tasks such as setting all email addresses to internal addresses to prevent spamming the client and truncating the log since our server is a little short on disk space.

if exists (Select * from master.dbo.sysdatabases where name = ‘${database}’)

Begin

    DROP DATABASE [${database}]

End

 

RESTORE DATABASE [${database}]

    FROM DISK = N’${backupfile}’

    WITH FILE = 1,

    NOUNLOAD ,

    STATS = 10,

    RECOVERY,

    – changes file locations from what was in the backup

    MOVE ‘${dataname}’ TO ‘${path::combine(datadirectory,database+’.mdf’)}’,

    MOVE ‘${logname}’ TO ‘${path::combine(logdirectory,database+’_Log.ldf’)}’

Tuesday, August 23, 2005 11:09:03 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
NAnt | Task Automation
Comments are closed.
Navigation
Twitter : Do you follow me?
View Jason Harris's profile on LinkedIn
Upcoming Conferences
Join me at CodeStock
devLink : I'll be there, how about you?
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Jason Harris
Sign In
Statistics
Total Posts: 70
This Year: 9
This Month: 1
This Week: 1
Comments: 1
All Content © 2008, Jason Harris
DasBlog theme 'Business' created by Christoph De Baene (delarou)
Technorati Profile