• [20210225]控制文件序列号满的恢复.txt


    [20210225]控制文件序列号满的恢复.txt

    --//继续昨天的测试,今天主要是测试恢复.
    --//我想给自己增加一点点难度,就是使用noresetlogs打开,因为这样重建的控制文件要读取redo,数据文件重新
    --//回填一些信息,实际上resetlogs也类似,但是noresetlogs回填的控制文件seq很大,一样打不开数据库.
    --//也就是必须提到我前面要修改的数据文件以及redo文件的几个偏移位置.

    1.环境:
    SCOTT@book> @ ver1
    PORT_STRING                    VERSION        BANNER
    ------------------------------ -------------- --------------------------------------------------------------------------------
    x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

    --//首先做一个冷备份便于重复测试:
    $ cp /mnt/ramdisk/book/*.* /u01/tmp/
    */

    2.首先注意要修改的位置:
    $ seq 6 | xargs -IQ echo "p dba Q,1  kcvfh.kcvfhhdr.kccfhcsq" | rlbbed| grep kccfhcsq
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    BBED> ub4 kccfhcsq                                @40       0xffffffff
    --//数据文件块1的偏移40的位置.

    $ seq 501 503 | xargs -IQ echo "dump /v dba Q,1 offset 36 count 8" | rlbbed | grep 00900100
     f8ffffff 00900100                                                       l ........
     fcffffff 00900100                                                       l ........
     fcffffff 00900100                                                       l ........
    --//redo文件的位置.

    $ echo 15,17,281,319 | tr ',' ' ' | xargs -IQ echo -e 'set dba 101,Q dump /v offset 8 count 8'  | rlbbed | grep -C2 "--"
    BBED>  File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 15                                Offsets:    8 to   15                            Dba:0x1940000f
    -----------------------------------------------------------------------------------------------------------
     ffffffff ffff0104                                                       l ........

    --
    BBED>  File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 17                                Offsets:    8 to   15                            Dba:0x19400011
    -----------------------------------------------------------------------------------------------------------
     ffffffff ffff0104                                                       l ........

    --
    BBED>  File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 281                               Offsets:    8 to   15                            Dba:0x19400119
    -----------------------------------------------------------------------------------------------------------
     85ffffff ffff0104                                                       l ........

    --
    BBED>  File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 319                               Offsets:    8 to   15                            Dba:0x1940013f
    -----------------------------------------------------------------------------------------------------------
     83ffffff ffff0104                                                       l ........

    --//控制文件的位置,以上内容是昨天的分析.控制文件的修改比较麻烦我重建使用noresetlogs建立,主要这样修改我不确定这样操作是否
    --//会遗漏.

    3.修改脚本准备:
    $ seq 6 | xargs -IQ echo -e "assign dba Q,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000 sum apply dba Q,1"
    assign dba 1,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 1,1
    assign dba 2,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 2,1
    assign dba 3,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 3,1
    assign dba 4,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 4,1
    assign dba 5,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 5,1
    assign dba 6,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 6,1

    --//手工执行如上命令.如果不想手工执行,必须在第2行加上Y,这样可以通过管道执行.
    $ cat aa.txt
    assign dba 1,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    Y
    sum apply dba 1,1
    assign dba 2,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 2,1
    assign dba 3,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 3,1
    assign dba 4,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 4,1
    assign dba 5,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 5,1
    assign dba 6,1  kcvfh.kcvfhhdr.kccfhcsq=0x77770000
    sum apply dba 6,1

    --//修改redo文件:
    $ seq 501 503 | xargs -IQ echo -e "modify /x 77770000 dba Q,1 offset 36 sum apply dba Q,1"
    modify /x 77770000 dba 501,1 offset 36
    sum apply dba 501,1
    modify /x 77770000 dba 502,1 offset 36
    sum apply dba 502,1
    modify /x 77770000 dba 503,1 offset 36
    sum apply dba 503,1

    --//我按照输出修改如下:
    $ cat bb.txt
    modify /x 17770000 dba 501,1 offset 36
    Y
    sum apply dba 501,1
    modify /x 57770000 dba 502,1 offset 36
    sum apply dba 502,1
    modify /x 37777000 dba 503,1 offset 36
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    sum apply dba 503,1

    --//注:下划线的地方我修改错误.

    4.建立建立控制文件脚本:
    --//这个过程略,在mount阶段(不能使用当前的控制文件,可以使用备份的控制文件),执行alter database backup controlfile to trace.
    --//也可以手工建立:
    $ cat /tmp/aa.txt
    STARTUP NOMOUNT
    CREATE CONTROLFILE REUSE DATABASE "BOOK" NORESETLOGS FORCE LOGGING ARCHIVELOG
        MAXLOGFILES 16
        MAXLOGMEMBERS 3
        MAXDATAFILES 100
        MAXINSTANCES 8
        MAXLOGHISTORY 292
    LOGFILE
      GROUP 1 '/mnt/ramdisk/book/redo01.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 2 '/mnt/ramdisk/book/redo02.log'  SIZE 50M BLOCKSIZE 512,
      GROUP 3 '/mnt/ramdisk/book/redo03.log'  SIZE 50M BLOCKSIZE 512
    -- STANDBY LOGFILE
    --   GROUP 4 '/mnt/ramdisk/book/redostb01.log'  SIZE 50M BLOCKSIZE 512,
    --   GROUP 5 '/mnt/ramdisk/book/redostb02.log'  SIZE 50M BLOCKSIZE 512,
    --   GROUP 6 '/mnt/ramdisk/book/redostb03.log'  SIZE 50M BLOCKSIZE 512,
    --   GROUP 7 '/mnt/ramdisk/book/redostb04.log'  SIZE 50M BLOCKSIZE 512
    DATAFILE
      '/mnt/ramdisk/book/system01.dbf',
      '/mnt/ramdisk/book/sysaux01.dbf',
      '/mnt/ramdisk/book/undotbs01.dbf',
      '/mnt/ramdisk/book/users01.dbf',
      '/mnt/ramdisk/book/example01.dbf',
      '/mnt/ramdisk/book/tea01.dbf'
    CHARACTER SET ZHS16GBK
    ;

    5.开始恢复:
    $ cat aa.txt | rlbbed
    $ cat bb.txt | rlbbed
    --//输出略.
    --//检查:
    $ seq 6 | xargs -IQ echo "p dba Q,1  kcvfh.kcvfhhdr.kccfhcsq" | rlbbed| grep kccfhcsq
    BBED> ub4 kccfhcsq                                @40       0x77770000
    BBED> ub4 kccfhcsq                                @40       0x77770000
    BBED> ub4 kccfhcsq                                @40       0x77770000
    BBED> ub4 kccfhcsq                                @40       0x77770000
    BBED> ub4 kccfhcsq                                @40       0x77770000
    BBED> ub4 kccfhcsq                                @40       0x77770000

    $ seq 501 503 | xargs -IQ echo "dump /v dba Q,1 offset 36 count 8" | rlbbed | grep 00900100
     17770000 00900100                                                       l .w......
     57770000 00900100                                                       l Ww......
     37777000 00900100                                                       l 7wp.....
     ~~~~~~~~~~
    --//这里输入错误.

    --//建立控制文件.
    SYS@book> @ /tmp/aa.txt
    ORACLE instance started.

    Total System Global Area  643084288 bytes
    Fixed Size                  2255872 bytes
    Variable Size             205521920 bytes
    Database Buffers          427819008 bytes
    Redo Buffers                7487488 bytes

    Control file created.

    $ dbv file=/mnt/ramdisk/book/control01.ctl blocksize=16384
    DBVERIFY: Release 11.2.0.4.0 - Production on Thu Feb 25 09:19:00 2021
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    DBVERIFY - Verification starting : FILE = /mnt/ramdisk/book/control01.ctl
    DBVERIFY - Verification complete
    Total Pages Examined         : 614
    Total Pages Processed (Data) : 0
    Total Pages Failing   (Data) : 0
    Total Pages Processed (Index): 0
    Total Pages Failing   (Index): 0
    Total Pages Processed (Other): 29
    Total Pages Processed (Seg)  : 0
    Total Pages Failing   (Seg)  : 0
    Total Pages Empty            : 585
    Total Pages Marked Corrupt   : 0
    Total Pages Influx           : 0
    Total Pages Encrypted        : 0
    Highest block SCN            : 2004287491 (65535.2004287491)

    --//2004287491 = 0x77770003.
    --//昏后面的3从哪里跑出来的,估计哪里搞错了.

    BBED> dump /v   dba 101,1 Offset 40 count 8
     File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 1                                 Offsets:   40 to   47                            Dba:0x19400001
    -----------------------------------------------------------------------------------------------------------
     04007777 66020000                                                       l ..wwf...
     <32 bytes per line>

    --//昏前面的修改错误.大小头问题搞晕了.bbed的修改应该是0x00007777,所以做这类恢复工作要小心小心在小心.前面的检查也没注意.
    --//还有就是redo修改脚本也存在错误.

    $ cat aa.txt
    assign dba 1,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    Y
    sum apply dba 1,1
    assign dba 2,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 2,1
    assign dba 3,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 3,1
    assign dba 4,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 4,1
    assign dba 5,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 5,1
    assign dba 6,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 6,1

    $ cat aa.txt | rlbbed
    $ seq 6 | xargs -IQ echo "p dba Q,1  kcvfh.kcvfhhdr.kccfhcsq" | rlbbed| grep kccfhcsq
    BBED> ub4 kccfhcsq                                @40       0x00007777
    BBED> ub4 kccfhcsq                                @40       0x00007777
    BBED> ub4 kccfhcsq                                @40       0x00007777
    BBED> ub4 kccfhcsq                                @40       0x00007777
    BBED> ub4 kccfhcsq                                @40       0x00007777
    BBED> ub4 kccfhcsq                                @40       0x00007777

    --//建立控制文件的步骤从来.
    SYS@book> @ /tmp/aa.txt
    ORACLE instance started.
    Total System Global Area  643084288 bytes
    Fixed Size                  2255872 bytes
    Variable Size             205521920 bytes
    Database Buffers          427819008 bytes
    Redo Buffers                7487488 bytes
    Control file created.

    $ dbv file=/mnt/ramdisk/book/control01.ctl blocksize=16384
    DBVERIFY: Release 11.2.0.4.0 - Production on Thu Feb 25 09:28:18 2021
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    DBVERIFY - Verification starting : FILE = /mnt/ramdisk/book/control01.ctl
    DBVERIFY - Verification complete
    Total Pages Examined         : 614
    Total Pages Processed (Data) : 0
    Total Pages Failing   (Data) : 0
    Total Pages Processed (Index): 0
    Total Pages Failing   (Index): 0
    Total Pages Processed (Other): 29
    Total Pages Processed (Seg)  : 0
    Total Pages Failing   (Seg)  : 0
    Total Pages Empty            : 585
    Total Pages Marked Corrupt   : 0
    Total Pages Influx           : 0
    Total Pages Encrypted        : 0
    Highest block SCN            : 7370554 (65535.7370554)
    --//7370554 = 0x70773a

    BBED> dump /v   dba 101,1 Offset 40 count 8
     File: /mnt/ramdisk/book/control01.ctl (101)
     Block: 1                                 Offsets:   40 to   47                            Dba:0x19400001
    -----------------------------------------------------------------------------------------------------------
     3b777000 66020000                                                       l ;wp.f...
     <32 bytes per line>

    --//先不管它,.看看是否可以open.
    --//昏事后仔细检查我前面的脚本写成如下:
    modify /x 37777000 dba 503,1 offset 36
    --//多写了一个7.颠倒就是0x00707737 = 7370551,这样比较接近了.

    SYS@book> alter database open ;
    alter database open
    *
    ERROR at line 1:
    ORA-01113: file 1 needs media recovery
    ORA-01110: data file 1: '/mnt/ramdisk/book/system01.dbf'

    SYS@book> recover database ;
    Media recovery complete.

    SYS@book> alter database open ;
    Database altered.

    SYS@book> select  CONTROLFILE_SEQUENCE# from v$database;
    CONTROLFILE_SEQUENCE#
    ---------------------
                  7370584

    --//OK恢复成功.

    5.重来:
    --//从冷备份恢复.
    SYS@book> shutdown immediate;
    Database closed.
    Database dismounted.
    ORACLE instance shut down.

    $ /bin/cp  /u01/tmp/* /mnt/ramdisk/book/
    */

    $ cat aa.txt
    assign dba 1,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    Y
    sum apply dba 1,1
    assign dba 2,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 2,1
    assign dba 3,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 3,1
    assign dba 4,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 4,1
    assign dba 5,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 5,1
    assign dba 6,1  kcvfh.kcvfhhdr.kccfhcsq=0x00007777
    sum apply dba 6,1

    $ cat bb.txt
    modify /x 17770000 dba 501,1 offset 36
    Y
    sum apply dba 501,1
    modify /x 57770000 dba 502,1 offset 36
    sum apply dba 502,1
    modify /x 37770000 dba 503,1 offset 36
    sum apply dba 503,1

    --//其它步骤忽略.

    $ dbv file=/mnt/ramdisk/book/control01.ctl blocksize=16384 2>&1 | grep Highest
    Highest block SCN            : 30586 (65535.30586)

    --//30586 = 0x777a,这样与我的测试接近了.

    SYS@book> alter database open ;
    alter database open
    *
    ERROR at line 1:
    ORA-01113: file 1 needs media recovery
    ORA-01110: data file 1: '/mnt/ramdisk/book/system01.dbf'

    SYS@book> recover database ;
    Media recovery complete.
    SYS@book> alter database open ;

    Database altered.

    SYS@book> select  CONTROLFILE_SEQUENCE# from v$database;
    CONTROLFILE_SEQUENCE#
    ---------------------
                    30616

    --//30616= 0x7798.
    RMAN> list incarnation ;
    using target database control file instead of recovery catalog
    List of Database Incarnations
    DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time
    ------- ------- -------- ---------------- --- ---------- ----------
    1       1       BOOK     1337401710       CURRENT 925702     2015-11-24 09:11:12

    --//没有生成新的incarnation

    6.收尾:
    --//执行如下,里面的脚本选择性执行:
    -- Configure RMAN configuration record 1
    VARIABLE RECNO NUMBER;
    EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
    -- Configure RMAN configuration record 2
    VARIABLE RECNO NUMBER;
    EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEVICE TYPE','DISK PARALLELISM 3 BACKUP TYPE TO BACKUPSET');
    -- Configure RMAN configuration record 3
    VARIABLE RECNO NUMBER;
    EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('DEFAULT DEVICE TYPE TO','DISK');
    -- Commands to re-create incarnation table
    -- Below log names MUST be changed to existing filenames on
    -- disk. Any one log file from each branch can be used to
    -- re-create incarnation records.
    -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/archivelog/book/1_1_824297850.dbf';
    -- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/archivelog/book/1_1_896605872.dbf';
    -- Recovery is required if any of the datafiles are restored backups,
    -- or if the last shutdown was not normal or immediate.
    RECOVER DATABASE
    -- All logs need archiving and a log switch is needed.
    ALTER SYSTEM ARCHIVE LOG ALL;
    -- Database can now be opened normally.
    ALTER DATABASE OPEN;
    -- Commands to add tempfiles to temporary tablespaces.
    -- Online tempfiles have complete space information.
    -- Other tempfiles may require adjustment.
    ALTER TABLESPACE TEMP ADD TEMPFILE '/mnt/ramdisk/book/temp01.dbf' REUSE;
    -- End of tempfile additions.
    --
    --
    --
    ----------------------------------------------------------
    -- The following script can be used on the standby database
    -- to re-populate entries for a standby controlfile created
    -- on the primary and copied to the standby site.
    ----------------------------------------------------------
    ALTER DATABASE ADD STANDBY LOGFILE '/mnt/ramdisk/book/redostb01.log'
     SIZE 50M BLOCKSIZE 512 REUSE;
    ALTER DATABASE ADD STANDBY LOGFILE '/mnt/ramdisk/book/redostb02.log'
     SIZE 50M BLOCKSIZE 512 REUSE;
    ALTER DATABASE ADD STANDBY LOGFILE '/mnt/ramdisk/book/redostb03.log'
     SIZE 50M BLOCKSIZE 512 REUSE;
    ALTER DATABASE ADD STANDBY LOGFILE '/mnt/ramdisk/book/redostb04.log'
     SIZE 50M BLOCKSIZE 512 REUSE;

    7.总结:
    --//有点乱,但是记录我整个操作过程.我之所以这样写,便于以后回忆总结,也避免一些低级错误.
    --//建议遇到这类文件选择重建控制文件选择resetlogs,不建议像我这样操作,我自不过当作练刀过程.

    8.补充说明:
    --//前面我提到的rlbbed我建立的bash shell函数,你可以使用别名代替,效果一样的.
    $ export RLWRAP=$(which rlwrap)
    $ type rlbbed
    rlbbed is a function
    rlbbed ()
    {
        cd /home/oracle/bbed;
        $RLWRAP -s 9999 -c -r -i -f /usr/local/share/rlwrap/bbed $ORACLE_HOME/bin/bbed parfile=bbed.par cmdfile=cmd.par
    }

    --//关于bbed配置看相关文档.
    $ cat cmd.par
    set count 64
    set width 160

    $ cat bbed.par
    blocksize=8192
    listfile=$HOME/bbed/filelist.txt
    mode=edit
    PASSWORD=blockedit
    SPOOL=Y

    --//filelist.txt文件通过select file#||' '||name c100 from v$dbfile order by file#;生成.我增加了控制文件以及redo文件.
    --//还有临时文件.
    $ cat filelist.txt  | grep -v "#"
    4 /mnt/ramdisk/book/users01.dbf
    1 /mnt/ramdisk/book/system01.dbf
    2 /mnt/ramdisk/book/sysaux01.dbf
    3 /mnt/ramdisk/book/undotbs01.dbf
    5 /mnt/ramdisk/book/example01.dbf
    6 /mnt/ramdisk/book/tea01.dbf

    101 /mnt/ramdisk/book/control01.ctl
    102 /mnt/ramdisk/book/control02.ctl

    201 /mnt/ramdisk/book/temp01.dbf

    501 /mnt/ramdisk/book/redo01.log
    502 /mnt/ramdisk/book/redo02.log
    503 /mnt/ramdisk/book/redo03.log
    504 /mnt/ramdisk/book/redostb01.log

  • 相关阅读:
    zabbix 主被动模式
    MySQL角色(role)功能介绍
    MySQL权限管理实战
    创建索引,这些知识应该了解
    MySQL锁等待与死锁问题分析
    Navicat操作MySQL简易教程
    职场里,对数据库要有敬畏之心!
    MySQL字段默认值设置详解
    MySQL查看及杀掉链接方法大全
    MySQL字段类型最全解析
  • 原文地址:https://www.cnblogs.com/lfree/p/14445396.html
Copyright © 2020-2023  润新知