I have a folder with multiple .bak files of sql server.
I want to restore them to sql server. How can i do a script so that all backuped files from that folder can be restored at once.
I have a folder with multiple .bak files of sql server.
I want to restore them to sql server. How can i do a script so that all backuped files from that folder can be restored at once.
Let's talk about restoring multiple databases from multiple BAK files. I think GAWK may help. It's not the MS way, but may be the fastest way.
Do you know GAWK?
Let you build input file with file names:
Write GAWK program into file program.gawk.txt:
Experiment with substr to generate temp name for restored database based on BAK file name. Not sure if substr expression is all right - please check yourself.
$1 will be changed to file name from input.txt
substr($1,1,length($1)-4) is for cutting ".BAK" from filename
Build output script by:
..and review it.
Maybe it's possible to do this powershell-way. Don't know.
Download GAWK from: http://gnuwin32.sourceforge.net/packages/gawk.htm
Try something like this.