restore database with t-sql

  • Hi,

    i'm building an app that (between other things) will let users restore databases.

    The user selects (through the app) the backup that they want to restore and then the app will restore this database.

    The app lets the users change the path to where data file and the log file will go.

    To restore the database i have to use something like this:

    RESTORE DATABASE db_name From disk ='c:\test.BAK'

    Move 'test_Data' TO 'C:\Program Files\Microsoft SQL ......\test.mdf',

    Move 'test_Log'" TO 'C:\Program Files\Microsoft SQL .......\test.ldf'

    My problem is with the Move instruction.

    I have to give the logical name of the datafile and the logical name of the log file.

    How can i do this?

    The backup does not have the information of the logical names of this two files (data file and log file).

    I have tried to see if the restore headeronly of the backup as logical file names, but it does not have....

    How can i know what is the logical file names?

    Thank you

  • restore filelistonly holds that info

    ---------------------------------------------------------------------

  • Try RESTORE FILELISTONLY. I think that'll get you what you want.

    "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

  • Hi,

    Are you looking for this query

    RESTORE DATABASE [DBNAME] FROM DISK = N'File Source' WITH FILE = 1, MOVE N'MDF Name' TO N'MDF PATH', MOVE N'log Name' TO N'Log Path', NOUNLOAD, REPLACE, STATS = 10

    Thanks

    Regards
    Durai Nagarajan

  • as to filelistonly, that's a very good ideia, thanks.

    about Durai Nagarajan's post i didn't understood the command very well. can you explain the command?

    Thank you

  • RESTORE DATABASE [b]DBNAME[/b] FROM DISK = N'File Source' WITH FILE = 1, MOVE N'MDF Name' TO N'MDF PATH', MOVE N'log Name' TO N'Log Path', NOUNLOAD, REPLACE, STATS = 10

    Kindly fill those which are marked bold. Note MDF and LDF name should be the original file name.

    This is a script of backup restore with restoration path specified. you have to specify the source path and file name and path respectively with desired DB name and restoration path.

    hope this clears you doubt.

    i forgot to notice are you guys mentioning about "file and file group restoration"

    Regards
    Durai Nagarajan

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply