Posted By

pollusb on 04/16/09


Versions (?)

RESTORE DATABASE from a list of files

 / Published in: SQL

URL: migration, admin, codegenerator

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.

  1. xp_cmdshell 'NET USE T: \\\w578-db-zip /user:cacpx-platespin\pollus password'
  2. xp_cmdshell 'DIR T:\2009-04-14\BMSQL\*.bak'
  4. --SNIPPET:Use a 1 file backup folder to generate RESTORE DATABASE commands
  5. CREATE TABLE #dir(filename varchar(1000))
  6. INSERT INTO #dir exec master..xp_cmdshell 'DIR T:\2009-04-14\BMSQL\*.bak /b'
  7. DELETE FROM #dir where filename is null
  8. SELECT * FROM #dir
  10. SELECT 'RESTORE DATABASE ['+REPLACE(filename,'.BAK','')+'] FROM DISK = ''T:\2009-04-14\BMSQL\'
  11. +filename+''' WITH REPLACE,NORECOVERY,STATS = 10;'
  12. from #dir where filename not in('master.bak','msdb.bak')
  14. --drop table #dir

Report this snippet  


RSS Icon Subscribe to comments
Posted By: medreg on May 17, 2009


I need an example of a project including the source code for backup and restore of the database I used language delphi7 paradox database I used four table table1 = pers.db table2 = doc.db table4 = reng.db table3 = param.db

You need to login to post a comment.