We use BACKUP and RESTORE to move databases around all the time - from our production customer servers to our development servers and workstations here at my office.
SQL scripts look like this
The BACKUP is commented out above.Code:/* BACKUP DATABASE Stufiles TO DISK = 'C:\acs desktop\Stufiles_Feb24_Lap.bak'*/ RESTORE FILELISTONLY FROM DISK = 'd:\steve.bak' RESTORE DATABASE Stufiles FROM DISK = 'd:\steve.bak' WITH MOVE 'Stufiles_data' TO 'D:\SQL data\Stufiles.mdf', MOVE 'Stufiles_log' TO 'D:\SQL Logs\Stufiles.ldf' GO
RESTORE FILELISTONLY dumps the contents of the BACKUP saveset.
The RESTORE DATABASE actually does the job.
This script can be run manually in MANAGEMENT STUDIO EXPRESS - yes...
But you already know this stuff - but did you look deeply into how RESTORE works when the DATABASE already exists on the server? MSDN BOOKS ONLINE has lots on info on BACKUP and RESTORE best practices - no reasons to discuss them here one topic at a time...
At any rate - make one of these .SQL scripts when you do your automated backups from your code. Make the script smart enough to do the job of restoring the database. Save it as a text file ending in .SQL - just like you would from a query window in Management studio.
But add to that the creation of a .BAT file that uses this file.
Here's a RUN_SPROCS.BAT file I have laying around that does this type of stuff
Code:osql /E /S xxx.xx.xx.130 /i frmAddDrop_Inquire.sql /o log_frmAddDrop_Inquire.sql.txt osql /E /S xxx.xx.xx.130 /i frmAppt_Inquire.sql /o log_frmAppt_Inquire.sql.txt osql /E /S xxx.xx.xx.130 /i frmAppt_View_Student.sql /o log_frmAppt_View_Student.sql.txt




Reply With Quote