/ Published in: SQL
Use a file list to generate a RESTORE script. You may want to review the WITH option. This script is for advanced user only. Works only with 1 file per database backup.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
xp_cmdshell 'NET USE T: \\10.106.68.110\w578-db-zip /user:cacpx-platespin\pollus password' xp_cmdshell 'DIR T:\2009-04-14\BMSQL\*.bak' --SNIPPET:Use a 1 file backup folder to generate RESTORE DATABASE commands CREATE TABLE #dir(filename VARCHAR(1000)) INSERT INTO #dir EXEC master..xp_cmdshell 'DIR T:\2009-04-14\BMSQL\*.bak /b' DELETE FROM #dir WHERE filename IS NULL SELECT * FROM #dir SELECT 'RESTORE DATABASE ['+REPLACE(filename,'.BAK','')+'] FROM DISK = ''T:\2009-04-14\BMSQL\' +filename+''' WITH REPLACE,NORECOVERY,STATS = 10;' from #dir where filename not in('master.bak','msdb.bak') --drop table #dir
URL: migration, admin, codegenerator