Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Recently a task is assigned to me to create a script which restores mutiple databases on SQL Server 2008 R2 server. Powershell was asked to be used..\
The daily backkups are stored at share location from where robocopy is done to one of SQL Server. The data files and log files sit a predefined location on other than C drive.

Would like how to start writing that does the multiple db restore, reads the db name from backup header, which uses with move and replace option of db backup command and preferably also sends an email in event of db restore failure.

One of the script on code project does restore of SQL server db nicely.. how can i loop it?


Thanks in Advance
Posted

If you already have the Powershell code to restore one database file, you are nearly done. Simply do a Powershell command to list all of the backup files in your folder (wherever they are). Then pipe those file names into your restore script and replace the hard-coded file name in the script with the piped-in value.

If you don't have the backup script or wanted to look at another, here is a fairly good one: http://www.sswug.org/articles/viewarticle.aspx?id=44909[^]
 
Share this answer
 
Thanks.
I have developed the script using for each loop which picks the backup files from a pre defined location, verify backup, read header , does processing for multiple data files and sends an email when restore fails.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900