restoring .bak file to new database using T-SQL

  • briancampbellmcad (5/15/2015)


    With the first block of code I get this:

    Msg 3201, Level 16, State 2, Line 1

    Cannot open backup device '\\belmont\c$\BCC_DB_backup_201505030017'. Operating system error 2(The system cannot find the file specified.).

    plus for the second block of code... I dont have needed files:

    RESTORE DATABASE BCCrestore

    FROM DISK = '\\belmont\c$\BCC_DB_backup_201505030017.bak'

    WITH MOVE 'BBC' TO '\\belmont\c$\BCCrestore.mdf',

    MOVE 'BBC_log' TO '\\belmont\c$\BCCrestore_log.ldf',

    REPLACE,

    STATS = 10;

    GO

    Msg 3234, Level 16, State 2, Line 1

    Logical file 'BBC' is not part of database 'BCCrestore'. Use RESTORE FILELISTONLY to list the logical file names.

    My mistake, correct the script I gave you changing BBC to BCC in the MOVE clauses.

    As for this part, you need to know where the file resides and if you have the necessary permissions to access it:

    FROM DISK = '\\belmont\c$\BCC_DB_backup_201505030017.bak'

  • running this gives errors too:

    RESTORE DATABASE BCCrestore

    FROM DISK = '\\belmont\c$\BCC_DB_backup_201505030017.bak'

    WITH MOVE 'BCC' TO '\\belmont\Databases\Data\BCCrestore.mdf',

    MOVE 'BCC_log' TO '\\belmont\Databases\Data\BCCrestore_log.ldf',

    REPLACE,

    STATS = 10;

    GO

    Msg 5110, Level 16, State 2, Line 1

    The file "\\belmont\Databases\Data\BCCrestore.mdf" is on a network path that is not supported for database files.

    Msg 3156, Level 16, State 3, Line 1

    File 'BCC' cannot be restored to '\\belmont\Databases\Data\BCCrestore.mdf'. Use WITH MOVE to identify a valid location for the file.

    Msg 5110, Level 16, State 2, Line 1

    The file "\\belmont\Databases\Data\BCCrestore_log.ldf" is on a network path that is not supported for database files.

    Msg 3156, Level 16, State 3, Line 1

    File 'BCC_log' cannot be restored to '\\belmont\Databases\Data\BCCrestore_log.ldf'. Use WITH MOVE to identify a valid location for the file.

    Msg 3119, Level 16, State 1, Line 1

    Problems were identified while planning for the RESTORE statement. Previous messages provide details.

    Msg 3013, Level 16, State 1, Line 1

    RESTORE DATABASE is terminating abnormally.

  • We're getting closer, you need to restore to a drive on the server, not a network path.

  • You really need to read this:

    https://msdn.microsoft.com/en-us/library/ms186858(v=sql.110).aspx

  • Also, you may want to bookmark this, it is the SQL Server 2012 Books Online on MSDN:

    https://msdn.microsoft.com/en-us/library/ms130214(v=sql.110).aspx

  • I'm not sure what you mean by a 'drive' on the server... all I can get to is \\belmont\c$ and the \\belmont\Databases\Data which is where I see BCCrestore.mdf and BCCrestore_log.ldf

  • briancampbellmcad (5/15/2015)


    I'm not sure what you mean by a 'drive' on the server... all I can get to is \\belmont\c$ and the \\belmont\Databases\Data which is where I see BCCrestore.mdf and BCCrestore_log.ldf

    Local drives on the server on which you are attempting to restore the database. You know, D: or E:, or what ever drives are local to the server.

  • briancampbellmcad (5/15/2015)


    I'm not sure what you mean by a 'drive' on the server... all I can get to is \\belmont\c$ and the \\belmont\Databases\Data which is where I see BCCrestore.mdf and BCCrestore_log.ldf

    You see \\belmont from your machine. However you don't run the RESTORE command. The SQL Server does and wants to see the paths from its perspective, which as Lynn mentioned, are the drive letters in Windows.

  • How do I discover the drives on this \\belmont server?

  • briancampbellmcad (5/18/2015)


    How do I discover the drives on this \\belmont server?

    Ask the system administrator?

  • My system admin says \\Belmont has no drives mapped within itself.

  • You're not looking for mapped drives, you're looking for local drives, like C:, D:, E:, etc

    Maybe give the sysadmin the backup and ask him to restore it?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • briancampbellmcad (5/15/2015)


    I'm not sure what you mean by a 'drive' on the server... all I can get to is \\belmont\c$ and the \\belmont\Databases\Data which is where I see BCCrestore.mdf and BCCrestore_log.ldf

    You're trying to use a windows hidden administrative share to access the database backup file. Copy the file to the backup file location on the server where you wish to restore the database would be your best option

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

  • If you run the following from SSMS while connected to the server:

    exec xp_fixeddrives

    what do you see? Those are the drives the Sql Server can access and that's where you'll have to put the files you want to get to.


    And then again, I might be wrong ...
    David Webb

  • David Webb-CDS (5/18/2015)


    exec xp_fixeddrives

    Bear in mind this wont help if you use mounted volumes

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

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 15 posts - 16 through 30 (of 65 total)

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