Return to Snippet

Revision: 13269
at April 16, 2009 22:30 by pollusb

Initial Code
xp_cmdshell 'NET USE T: \\\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\'
from #dir where filename not in('master.bak','msdb.bak')

--drop table #dir

Initial URL
migration, admin, codegenerator

Initial Description
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.

Initial Title
RESTORE DATABASE from a list of files

Initial Tags

Initial Language