Script- restore database from another database backup file

  • 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

  • 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

  • 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

  • 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.

  • 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

  • You might look at some of these.

    http://www.sqlservercentral.com/search/?q=restore+backup&t=s

  • 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