zoukankan      html  css  js  c++  java
  • oracle data guard备库备份恢复

    oracle data guard备库备份恢复

    Posted on 2017-10-18 17:51  会飞的板儿  阅读(1345)  评论(0)  编辑  收藏

      客户有套data guard环境,主库在阿里云上,备库在本地机房,现在想定期做备份,但是因为一些原因,备份阿里云上的主库实现会有些问题,所以只能备份本地的备库。目前需求就是测试备库的备份文件是否可以进行恢复,当误删除等操作之后,能否通过备份找回数据。以下为具体的测试:

    1. 在data guard的备库进行完整+归档的备份

    复制代码
    RMAN> run {
    2> allocate channel t1 type disk;
    3> allocate channel t2 type disk;
    4> allocate channel t3 type disk;
    5> allocate channel t4 type disk;
    6> backup as compressed backupset INCREMENTAL LEVEL 0 FORMAT '/u01/app/oracle/racdb_data_%T_%s' database;
    7> backup format '/u01/app/oracle/racdb_arch_%T_%s' skip inaccessible archivelog ALL not backed up;
    8> backup format '/u01/app/oracle/racdb_cont_%T_%s' current controlfile;
    9> release channel t1;
    10> release channel t2;
    11> release channel t3;
    12> release channel t4;
    13> }
    复制代码

    2. 将文件拷贝到测试库上

    复制代码
    [oracle@dg1 oracle]$ scp racdb_* 192.168.100.100:/u01/app/oracle/
    oracle@192.168.100.100's password: 
    racdb_arch_20171018_24                                                                                    100% 3646KB   3.6MB/s   00:00    
    racdb_arch_20171018_25                                                                                    100%   30MB  30.1MB/s   00:01    
    racdb_arch_20171018_26                                                                                    100% 2995KB   2.9MB/s   00:00    
    racdb_arch_20171018_27                                                                                    100%   59MB  59.2MB/s   00:01    
    racdb_arch_20171018_28                                                                                    100%   21MB  20.9MB/s   00:00    
    racdb_cont_20171018_29                                                                                    100% 9856KB   9.6MB/s   00:00    
    racdb_data_20171018_19                                                                                    100%  194MB  48.6MB/s   00:04    
    racdb_data_20171018_20                                                                                    100%   77MB  77.0MB/s   00:01    
    racdb_data_20171018_21                                                                                    100%   30MB  30.2MB/s   00:01    
    racdb_data_20171018_22                                                                                    100% 1104KB   1.1MB/s   00:00    
    racdb_data_20171018_23                                                                                    100%   96KB  96.0KB/s   00:00    
    复制代码

    3. 在主库上生成pfile文件,并拷贝到测试库上

    复制代码
    SQL> create pfile='/home/oracle/pfileabbott' from spfile;
    
    File created.
    
    [oracle@dg1 ~]$ scp pfileabbott 192.168.100.100:/home/oracle
    oracle@192.168.100.100's password: 
    pfileabbott                                                                                               100% 1375     1.3KB/s   00:00  
    复制代码

    4. 在测试库上修改参数文件

    复制代码
    [oracle@Abbott ~]$ mv pfileabbott $ORACLE_HOME/dbs/initabbott.ora
    [oracle@Abbott ~]$ cd $ORACLE_HOME/dbs
    [oracle@Abbott dbs]$ export ORACLE_SID=abbott
    [oracle@Abbott dbs]$ vi initabbott.ora 
    *.audit_file_dest='/u01/app/oracle/admin/abbott/adump'
    *.audit_trail='db'
    *.compatible='11.2.0.4.0'
    *.control_files='/u01/app/oracle/oradata/abbott/control01.ctl','/u01/app/oracle/fast_recovery_area/abbott/control02.ctl'
    *.db_block_size=8192
    *.db_domain=''
    *.db_name='abbott'
    *.db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'
    *.db_recovery_file_dest_size=4385144832
    *.diagnostic_dest='/u01/app/oracle'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=abbottXDB)'
    *.log_archive_dest_1='LOCATION=/u01/app/oracle/archivelog'
    *.log_archive_format='%t_%s_%r.arc'
    *.log_archive_max_processes=30
    *.open_cursors=300
    *.pga_aggregate_target=655360000
    *.processes=150
    *.remote_login_passwordfile='EXCLUSIVE'
    *.sga_target=1967128576
    *.standby_file_management='AUTO'
    *.undo_tablespace='UNDOTBS1'
    复制代码

    5. 测试库开启到nomount

    复制代码
    [oracle@Abbott dbs]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 08:24:18 2017
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    Connected to an idle instance.
    
    SQL> startup nomount;
    ORACLE instance started.
    
    Total System Global Area 1970864128 bytes
    Fixed Size                  2254544 bytes
    Variable Size             520096048 bytes
    Database Buffers         1442840576 bytes
    Redo Buffers                5672960 bytes
    SQL> 
    复制代码

    6. 恢复控制文件

    复制代码
    [oracle@Abbott ~]$ rman target /
    
    Recovery Manager: Release 11.2.0.4.0 - Production on Tue Oct 17 09:29:20 2017
    
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    
    connected to target database: ABBOTT (not mounted)
    
    RMAN> restore controlfile from '/u01/app/oracle/racdb_cont_20171018_29';
    
    Starting restore at 17-OCT-17
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=134 device type=DISK
    
    channel ORA_DISK_1: restoring control file
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    output file name=/u01/app/oracle/oradata/abbott/control01.ctl
    output file name=/u01/app/oracle/fast_recovery_area/abbott/control02.ctl
    Finished restore at 17-OCT-17
    
    RMAN> alter database mount;
    
    database mounted
    released channel: ORA_DISK_1
    复制代码

    7. 恢复数据文件

    复制代码
    RMAN> restore database;
    
    Starting restore at 17-OCT-17
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=150 device type=DISK
    
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/abbott/undotbs01.dbf
    channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/abbott/example01.dbf
    channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_21
    channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_21 tag=TAG20171018T153509
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/abbott/sysaux01.dbf
    channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/abbott/users01.dbf
    channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_20
    channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_20 tag=TAG20171018T153509
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/abbott/system01.dbf
    channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_data_20171018_19
    channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_data_20171018_19 tag=TAG20171018T153509
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
    Finished restore at 17-OCT-17
    复制代码

    8. 恢复数据库

    复制代码
    RMAN> recover database;
    
    Starting recover at 17-OCT-17
    using channel ORA_DISK_1
    
    starting media recovery
    
    channel ORA_DISK_1: starting archived log restore to default destination
    channel ORA_DISK_1: restoring archived log
    archived log thread=1 sequence=196
    channel ORA_DISK_1: reading from backup piece /u01/app/oracle/racdb_arch_20171018_28
    channel ORA_DISK_1: piece handle=/u01/app/oracle/racdb_arch_20171018_28 tag=TAG20171018T153550
    channel ORA_DISK_1: restored backup piece 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    archived log file name=/u01/app/oracle/archivelog1_196_953375126.arc thread=1 sequence=196
    unable to find archived log
    archived log thread=1 sequence=197
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of recover command at 10/17/2017 09:33:30
    RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 197 and starting SCN of 1907246
    复制代码

    9. 将数据库open

    复制代码
    RMAN> alter database open;
    
    database opened
    
    RMAN> quit
    
    Recovery Manager complete.
    复制代码

    10. 连接数据库后,无法创建表等,因为控制文件是standby controlfile,所以打开的模式为READ ONLY

    复制代码
    [oracle@Abbott ~]$ sqlplus / as sysdba
    
    SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 17 09:41:46 2017
    
    Copyright (c) 1982, 2013, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> create table t1(a int);
    create table t1(a int)
    *
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-16000: database open for read-only access
    
    
    SQL> select open_mode , database_role, flashback_on from v$database; 
    
    OPEN_MODE            DATABASE_ROLE    FLASHBACK_ON
    -------------------- ---------------- ------------------
    READ ONLY            PHYSICAL STANDBY NO
    复制代码

    11. 尝试启用备库,因缺少standby log报错

    复制代码
    SQL> alter database activate standby database; 
    alter database activate standby database
    *
    ERROR at line 1:
    ORA-00314: log 4 of thread 1, expected sequence# 197 doesn't match 0
    ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/abbott/std_log4.log'
    
    
    SQL> select * from v$standby_log;
    select * from v$standby_log
                  *
    ERROR at line 1:
    ORA-00339: archived log does not contain any redo
    ORA-00334: archived log: '/u01/app/oracle/oradata/abbott/std_log4.log'
    复制代码

    12. 因此对缺少的log进行clear及drop(当然,这里也可以把standby redo拷贝过来,并进行open)

    复制代码
    SQL> alter database drop logfile group 4;
    alter database drop logfile group 4
    *
    ERROR at line 1:
    ORA-00314: log 4 of thread 1, expected sequence# 197 doesn't match 0
    ORA-00312: online log 4 thread 1: '/u01/app/oracle/oradata/abbott/std_log4.log'
    
    
    SQL>  ALTER DATABASE CLEAR LOGFILE GROUP 4;
    
    Database altered.
    
    SQL> alter database drop logfile group 4;
    
    Database altered.
    复制代码

    13. 再次arctive备库,启动正常,并且open之后可读写

    复制代码
    SQL> alter database activate standby database;   
    
    Database altered.
    
    SQL> select open_mode , database_role, flashback_on from v$database;
    
    OPEN_MODE            DATABASE_ROLE    FLASHBACK_ON
    -------------------- ---------------- ------------------
    MOUNTED              PRIMARY          NO
    
    SQL> alter database open;
    
    Database altered.
    
    SQL> select open_mode , database_role, flashback_on from v$database; 
    
    OPEN_MODE            DATABASE_ROLE    FLASHBACK_ON
    -------------------- ---------------- ------------------
    READ WRITE           PRIMARY          NO
    
    SQL> create table t1(a int);
    
    Table created.
    
    SQL> 
    SQL> archive log list;
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            /u01/app/oracle/archivelog
    Oldest online log sequence     1
    Next log sequence to archive   1
    Current log sequence           1
    SQL> 
    复制代码
  • 相关阅读:
    【PAT甲级】1054 The Dominant Color
    【PAT甲级】1001 A+B Format
    【算法】二分排序和二分查找
    【PAT甲级】1008 Elevator (20分)
    移动端工作准备
    媒体查询
    多列布局
    怪异盒模型
    弹性盒
    圆角
  • 原文地址:https://www.cnblogs.com/yaoyangding/p/12913908.html
Copyright © 2011-2022 走看看