In my earlier post we saw how to backup all your MS-sql databases “here”, now let us take a look how to restore all your MS-Sql databases via script.
This script is useful if you wish to restore multiple or bulk databases at once. you can restore all your databases via command line.
Here, We have three parts :
1) The “AttachDB.sql” File
The main sql script file that does the restore and contains the database and backup file location
2) “Restore.bat” File
BatchFile that take database name as parameter and restores databases with the help of AttachDB.sql
3) “Execute.bat” File
Batch file that passes database name as inputs to Restore.bat file
*Note : The above 3 script files and database backups should be placed together under same directory, the code picks your current directory as root directory.
Edit the location and paths according to your environment.
Once you have everything in place simply run “Execute.bat” file to start the restoration.
Let us take a look at the code for each file and how to execute them
(more…)