April 19, 2011 at 5:02 pm
Is there a restore database script that I can use to automate to restore database from a backup file of another database.
I guess I have to define some parameters like sourec file information, destination file information, also I need to pull most recent full backup which is also a copy-only full back up, then do the restore.
Any existing scripts that I can use to modify to do this work?
Thanks
April 19, 2011 at 8:46 pm
Sure you can do it. You could use "restore filelistonly" to get the file information from the backup file and then build your restore dynamically from that and the other information that you would have already available based on your requirements.
I don't know of anything that is readily available but the script is not hard to write up.
David
@SQLTentmaker“He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot
April 20, 2011 at 4:52 am
It's just a standard RESTORE operation using the REPLACE keyword, probably along with MOVE. Look it up in Books Online. There are even examples of how to replace a database right there.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
April 20, 2011 at 9:43 am
I would like to make the script to be portable for all other databases, each time I just need to change the database name, I know how to write a simple restore script, but a little harder for this one.
April 20, 2011 at 10:00 am
Ah, you'll have to build out a rather large script that can go into a given backup and get the file structure out and then automatically figure out where to place all those files on a new server (not necessarily easy) and then automate that into the restore command. Personally, I'd go with just using a little typing.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
April 20, 2011 at 10:22 am
You might look at some of these.
http://www.sqlservercentral.com/search/?q=restore+backup&t=s
April 20, 2011 at 10:29 am
Thanks all for the help, I will look more into it.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply