Monday, July 03, 2006

SQL 2000 Database Recovery from Network Drive using SQL commands

In my current project, we frequently need to update our QA database with our production database. We get production database backup copy by FTP. SQL Enterprise Manager donot support recovery of database from remote file. UI only support only local backup file. Following SQL commands came as rescue:

-- Command to list database from remote drive
restore filelistonly FROM disk='\\remotemachine\DB Backup\Northwind.bak'

-- Command to recover database using this list
RESTORE Database Core FROM disk='\\remotemachine\DB Backup\Northwind.bak''
WITH
move 'Northwind_Data'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL$INSTANCE2\Data\Northwind.mdf',
move 'Northwind_Index'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL$INSTANCE2\Data\Northwind_1.mdf',
move 'Northwind_Log'
TO 'C:\Program Files\Microsoft SQL Server\MSSQL$INSTANCE2\DataNorthwind_log.ldf',
Partial, Recovery

No comments: