zoukankan      html  css  js  c++  java
  • 基于时间点恢复数据库stopat

    create database newtestdb

    use newtestdb
    go


    drop table t1
    go

    create table t1 (
    id int not null identity(1,1) primary key
    ,vdate datetime default (getdate())
    ,name varchar(32)
    )


    backup database newtestdb to disk='c: ewtestdb_ful.bak'
    insert into t1 (name) values ('aa')

    insert into t1 (name) values ('bb')
    backup log newtestdb to disk='c: ewtestdb_1.trn' --2016-05-18 13:42:30.767
    select getdate()


    insert into t1 (name) values ('cc')
    backup log newtestdb to disk='c: ewtestdb_2.trn' --2016-05-18 13:43:59.707
    select getdate()


    insert into t1 (name) values ('dd')
    backup log newtestdb to disk='c: ewtestdb_3.trn' --2016-05-18 13:45:05.310
    select getdate()


    insert into t1 (name) values ('ee')
    backup log newtestdb to disk='c: ewtestdb_4.trn' --2016-05-18 13:46:29.783
    select getdate()


    insert into t1 (name) values ('ff')
    backup log newtestdb to disk='c: ewtestdb_5.trn' --2016-05-18 13:47:21.833
    select getdate()


    --恢复到dd
    use master
    go
    restore database newtestdb from disk='c: ewtestdb_ful.bak' with replace,norecovery;
    /*
    Processed 344 pages for database 'newtestdb', file 'newtestdb' on file 1.
    Processed 6 pages for database 'newtestdb', file 'newtestdb_log' on file 1.
    RESTORE DATABASE successfully processed 350 pages in 0.025 seconds (109.179 MB/sec).
    */
    restore log newtestdb from disk='c: ewtestdb_1.trn' with replace,norecovery,stopat='2016-05-18 13:45:09.310';
    /*
    Processed 0 pages for database 'newtestdb', file 'newtestdb' on file 1.
    Processed 7 pages for database 'newtestdb', file 'newtestdb_log' on file 1.
    This backup set contains records that were logged before the designated point in time. The database is being left in the restoring state so that more roll forward can be performed.
    RESTORE LOG successfully processed 7 pages in 0.008 seconds (6.103 MB/sec).
    */
    restore log newtestdb from disk='c: ewtestdb_2.trn' with replace,norecovery,stopat='2016-05-18 13:45:09.310';
    /*
    Processed 0 pages for database 'newtestdb', file 'newtestdb' on file 1.
    Processed 1 pages for database 'newtestdb', file 'newtestdb_log' on file 1.
    This backup set contains records that were logged before the designated point in time. The database is being left in the restoring state so that more roll forward can be performed.
    RESTORE LOG successfully processed 1 pages in 0.006 seconds (0.325 MB/sec).
    */
    restore log newtestdb from disk='c: ewtestdb_3.trn' with replace,norecovery,stopat='2016-05-18 13:45:09.310';
    /*
    Processed 0 pages for database 'newtestdb', file 'newtestdb' on file 1.
    Processed 1 pages for database 'newtestdb', file 'newtestdb_log' on file 1.
    This backup set contains records that were logged before the designated point in time. The database is being left in the restoring state so that more roll forward can be performed.
    RESTORE LOG successfully processed 1 pages in 0.006 seconds (0.325 MB/sec).
    */
    restore log newtestdb from disk='c: ewtestdb_4.trn' with replace,norecovery,stopat='2016-05-18 13:45:09.310';
    /*
    Processed 0 pages for database 'newtestdb', file 'newtestdb' on file 1.
    Processed 1 pages for database 'newtestdb', file 'newtestdb_log' on file 1.
    RESTORE LOG successfully processed 1 pages in 0.004 seconds (0.488 MB/sec).
    */
    restore log newtestdb from disk='c: ewtestdb_5.trn' with replace,norecovery,stopat='2016-05-18 13:45:09.310';
    /*
    Msg 4305, Level 16, State 1, Line 57
    The log in this backup set begins at LSN 34000000022700001, which is too recent to apply to the database. An earlier log backup that includes LSN 34000000022500002 can be restored.
    Msg 3013, Level 16, State 1, Line 57
    RESTORE LOG is terminating abnormally.
    */

    restore database newtestdb with replace,recovery;
    /*
    RESTORE DATABASE successfully processed 0 pages in 0.086 seconds (0.000 MB/sec).
    */

    --成功恢复至dd

    select * from newtestdb.dbo.t1


    id vdate name
    1 2016-05-18 13:41:44.500 aa
    2 2016-05-18 13:42:26.767 bb
    3 2016-05-18 13:43:57.707 cc
    4 2016-05-18 13:45:05.290 dd

  • 相关阅读:
    区块链中的随机数 nonce
    SaaS(软件即服务)、PaaS(平台即服务)、IaaS(基础架构即服务)、BaaS(区块链即服务)
    程序插桩简介
    侧链技术
    闪电/雷电网络
    Ubuntu16.04安装/升级openssl到1.1版本
    Ubuntu16.04升级Python3及其pip3并切换为默认版本
    Python——/usr/bin/env: ‘python(3) ’: No such file or directory
    TCP通信功能 (agent功能)
    gin框架web操作数据库
  • 原文地址:https://www.cnblogs.com/justdba/p/5505046.html
Copyright © 2011-2022 走看看