记录一次oracle dataguard缺失归档的处理

查看主备库有无新增数据文件:
RMAN> report schema;

using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name HYGEIA

List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
—- ——– ——————– ——- ————————
1 4096 SYSTEM *** +DATA/hygeia/datafile/system.266.853951045
2 4096 SYSAUX *** +DATA/hygeia/datafile/sysaux.267.853951049
3 27130 UNDOTBS1 *** +DATA/hygeia/datafile/undotbs1.268.853951053
4 22270 UNDOTBS2 *** +DATA/hygeia/datafile/undotbs2.270.853951059
5 2096 USERS *** +DATA/hygeia/datafile/users.271.853951061
6 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.300.854372701
7 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.301.854372845
8 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.302.854372969
9 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.303.854373095
10 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.304.854373217
11 1024 INDX *** +DATA/hygeia/datafile/indx.306.854373395
12 1024 NB *** +DATA/hygeia/datafile/nb.307.854373421
13 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.305.854373337
14 3072 OLD *** +DATA/hygeia/datafile/old.308.854373449
15 1024 WEB *** +DATA/hygeia/datafile/web.310.854373481
16 1024 TOOLS *** +DATA/hygeia/datafile/tools.311.854373519
17 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.309.854373455
18 32000 HYGEIA *** +DATA/hygeia/datafile/hygeia.312.854373631
19 30720 HYGEIA *** +DATA/hygeia/datafile/hygeia.441.877174865
20 30720 HYGEIA *** +DATA/hygeia/datafile/hygeia.442.877175711
21 30720 HYGEIA *** +DATA/hygeia/datafile/hygeia.417.877176157
22 100 OGG *** +DATA/hygeia/datafile/ogg.421.894446377
23 10000 HYGEIA_MZ *** +DATA/hygeia/datafile/hygeia_mz.408.898168189
24 10000 HYGEIA_QRY *** +DATA/hygeia/datafile/hygeia_qry.400.898168277

主备库数据文件相同,没有添加新文件

查看备库当前scn
SQL> select to_char(current_scn) from v$database;

TO_CHAR(CURRENT_SCN)
—————————————-
15179025089230

SQL>
生产库增量备份
run{
allocate channel c1 type disk format=’/u01/rmanbak/%U’;
allocate channel c2 type disk format=’/u01/rmanbak/%U’;
backup incremental from SCN 15179025089230 DATABASE;
release channel c1;
release channel c2;
}
查看备份进度
select s.inst_id, o.sid, CLIENT_INFO ch, context, sofar, totalwork,
round(sofar/totalwork*100,2) “% Complete”
FROM gv$session_longops o, gv$session s
WHERE opname LIKE ‘RMAN%’
AND opname NOT LIKE ‘%aggregate%’
AND o.sid=s.sid
AND totalwork != 0
AND sofar <> totalwork;
创建standby控制文件
alter database create standby controlfile as ‘/u01/rmanbak/control01.ctl.1117’;

备库注册备份片
RMAN> catalog start with ‘/oradata/rmanbak/’;

using target database control file instead of recovery catalog
searching for all files that match the pattern /oradata/rmanbak/

List of Files Unknown to the Database
=====================================
File Name: /oradata/rmanbak/14rl5bn5_1_1
File Name: /oradata/rmanbak/13rl5bn4_1_1
File Name: /oradata/rmanbak/15rl5c9g_1_1

Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files…
cataloging done

List of Cataloged Files
=======================
File Name: /oradata/rmanbak/14rl5bn5_1_1
File Name: /oradata/rmanbak/13rl5bn4_1_1
File Name: /oradata/rmanbak/15rl5c9g_1_1
应用备份集
RMAN> recover database noredo;

Starting recover at 2016-11-17 17:32:32
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=891 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: /oradata/DG/datafile/system.266.853951045
destination for restore of datafile 00003: /oradata/DG/datafile/undotbs1.268.85395105
destination for restore of datafile 00004: /oradata/DG/datafile/undotbs2.270.85395105
destination for restore of datafile 00007: /oradata/DG/datafile/hygeia.301.854372845
destination for restore of datafile 00009: /oradata/DG/datafile/hygeia.303.854373095
destination for restore of datafile 00011: /oradata/DG/datafile/indx.306.854373395
destination for restore of datafile 00013: /oradata/DG/datafile/hygeia.305.854373337
destination for restore of datafile 00014: /oradata/DG/datafile/old.308.854373449
destination for restore of datafile 00015: /oradata/DG/datafile/web.310.854373481
destination for restore of datafile 00016: /oradata/DG/datafile/tools.311.854373519
destination for restore of datafile 00018: /oradata/DG/datafile/hygeia.312.854373631
destination for restore of datafile 00020: /oradata/DG/datafile/hygeia.442.877175711
channel ORA_DISK_1: reading from backup piece /oradata/rmanbak/13rl5bn4_1_1
替换控制文件
shutdown immediate 替换文件
startup mount

开启恢复进程
alter database recover managed standby database disconnec from session;

定时删除归档:
# cat deletearchlog.sh
/u01/app/oracle/products/rdbms/bin/rman target / <<EOF
delete noprompt archivelog all completed before ‘sysdate-7’;
exit;
EOF
#crontab -l
…..
21 21 * * * su – oracle -c ‘/home/oracle/deletearchlog.sh’