locked
Restore db File RRS feed

  • Question

  • Hi All,

    I have restore a test db from .ndf file, the restore was successfull with no error, but the database is in restoring mode, could anyone explain or help?

     

    My script is given below

     

    use testdb1
    go
    create table Employee (id int primary key not null identity(1,1), name varchar(100))
    go
    insert into testdb1.dbo.Employee values('JN'),('PC')
    go
    Use master
    go
    backup database testdb1 to disk =N'C:\test\testdb1.bak' with init --copy_only
    go
    backup log testdb1 to disk =N'C:\test\testdb1_log.bak' with norecovery
    go
    truncate table testdb1.dbo.Employee
    go
    restore database testdb1 file =N'testdb1_idx' from disk =N'C:\test\testdb1.bak' with norecovery
    go
    restore log testdb1 from disk =N'C:\test\testdb1_log.bak' with recovery
    go


    JN
    Wednesday, June 22, 2011 3:20 PM

Answers

  • It's happening because of this statement:

    backup log testdb1 to disk =N'C:\test\testdb1_log.bak' with norecovery

    and here is the explanation from BOL:

    NORECOVERY | STANDBY = undo_file_name }
    NORECOVERY
    Backs up the tail of the log and leaves the database in the RESTORING state. NORECOVERY is useful when failing over to a secondary database or when saving the tail of the log before a RESTORE operation.

    To perform a best-effort log backup that skips log truncation and then take the database into the RESTORING state atomically, use the NO_TRUNCATE and NORECOVERY options together.
    STANDBY = standby_file_name
    Backs up the tail of the log and leaves the database in a read-only and STANDBY state. The STANDBY clause writes standby data (performing rollback, but with the option of further restores). Using the STANDBY option is equivalent to BACKUP LOG WITH NORECOVERY followed by a RESTORE WITH STANDBY.

    Using standby mode requires a standby file, specified by standby_file_name, whose location is stored in the log of the database. If the specified file already exists, the Database Engine overwrites it; if the file does not exist, the Database Engine creates it. The standby file becomes part of the database.

    This file holds the rolled back changes, which must be reversed if RESTORE LOG operations are to be subsequently applied. There must be enough disk space for the standby file to grow so that it can contain all the distinct pages from the database that were modified by rolling back uncommitted transactions.


    Harsh Chawla(MSFT) Personal Blog:-http://blogs.msdn.com/batala Team Blog:- http://blogs.msdn.com/b/sqlserverfaq/
    Wednesday, June 22, 2011 3:31 PM
  • Seems like you try to go back in time for a part of the database (prior to your TRUNCATE TABLE), and using filegroup backups aren't the direct answer to this. I've blogged this: http://sqlblog.com/blogs/tibor_karaszi/archive/2009/06/25/table-restore-and-filegroups.aspx
    Tibor Karaszi, SQL Server MVP | web | blog
    • Marked as answer by WeiLin Qiao Monday, July 4, 2011 9:34 AM
    Wednesday, June 22, 2011 3:39 PM

All replies

  • It's happening because of this statement:

    backup log testdb1 to disk =N'C:\test\testdb1_log.bak' with norecovery

    and here is the explanation from BOL:

    NORECOVERY | STANDBY = undo_file_name }
    NORECOVERY
    Backs up the tail of the log and leaves the database in the RESTORING state. NORECOVERY is useful when failing over to a secondary database or when saving the tail of the log before a RESTORE operation.

    To perform a best-effort log backup that skips log truncation and then take the database into the RESTORING state atomically, use the NO_TRUNCATE and NORECOVERY options together.
    STANDBY = standby_file_name
    Backs up the tail of the log and leaves the database in a read-only and STANDBY state. The STANDBY clause writes standby data (performing rollback, but with the option of further restores). Using the STANDBY option is equivalent to BACKUP LOG WITH NORECOVERY followed by a RESTORE WITH STANDBY.

    Using standby mode requires a standby file, specified by standby_file_name, whose location is stored in the log of the database. If the specified file already exists, the Database Engine overwrites it; if the file does not exist, the Database Engine creates it. The standby file becomes part of the database.

    This file holds the rolled back changes, which must be reversed if RESTORE LOG operations are to be subsequently applied. There must be enough disk space for the standby file to grow so that it can contain all the distinct pages from the database that were modified by rolling back uncommitted transactions.


    Harsh Chawla(MSFT) Personal Blog:-http://blogs.msdn.com/batala Team Blog:- http://blogs.msdn.com/b/sqlserverfaq/
    Wednesday, June 22, 2011 3:31 PM
  • Seems like you try to go back in time for a part of the database (prior to your TRUNCATE TABLE), and using filegroup backups aren't the direct answer to this. I've blogged this: http://sqlblog.com/blogs/tibor_karaszi/archive/2009/06/25/table-restore-and-filegroups.aspx
    Tibor Karaszi, SQL Server MVP | web | blog
    • Marked as answer by WeiLin Qiao Monday, July 4, 2011 9:34 AM
    Wednesday, June 22, 2011 3:39 PM