rac归档在本地的备份和恢复

rac归档在本地的备份和恢复

os:Red Hat Enterprise Linux Server release 5.1 (Tikanga)
oracle:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

两个节点rac1 rac2
归档在本地目录:
log_archive_dest_1    string      location=/home/oracle/archive
第一节点归档目录
[oracle@rac1 ~]$ ls
archive  rmanbak
第二节点归档目录
[oracle@rac2 ~]$ ls
archive  rmanbak

在第一节点执行备份和恢复
备份文件放在rmanbak目录,每个节点的归档备份在各自的rmanbak目录下

rman配置自动备份控制文件
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/rmanbak/%F';

采用脚本如下:
ORAHOME=/u01/app/product/10.2.0/db_1
ORAOWNER=oracle
dt=`date +%m%d`
su - $ORAOWNER -c "$ORAHOME/bin/rman target /  log /home/oracle/rmanbak/backup_$dt.log << EOF
RUN {

ALLOCATE CHANNEL c1 TYPE DISK; 
ALLOCATE CHANNEL c2 TYPE DISK;
BACKUP full
    TAG hot_db_bk_level0
    FILESPERSET 2
    FORMAT '/home/oracle/rmanbak/fullbk_%s_%p_%t'
    DATABASE;  
    sql 'alter system archive log current';
RELEASE CHANNEL c1;
RELEASE CHANNEL c2;

ALLOCATE CHANNEL c1 TYPE DISK connect 'sys/admin123@syk1';
ALLOCATE CHANNEL c2 TYPE DISK connect 'sys/admin123@syk2';
BACKUP
  
   FORMAT '/home/oracle/rmanbak/arch_%s_%p_%t'
   ARCHIVELOG ALL DELETE INPUT;
   delete noprompt obsolete; 
RELEASE CHANNEL c1;
RELEASE CHANNEL c2;
}
EOF"

备份完成后备份文件如下:
[oracle@rac1 rmanbak]$ ls
arch_121_1_758986045  c-921635118-20110812-02  fullbk_117_1_758985958  fullbk_119_1_758986006
arch_123_1_758986047  backup_0812.log          fullbk_118_1_758985958

[oracle@rac2 rmanbak]$ ls
arch_122_1_758986043

库里查看相关备份信息如下:
select bs_key,bp_key,handle,to_char(start_time,'yyyy-mm-dd hh24:mi:ss') from v$backup_piece_details order by 1,2;

    BS_KEY     BP_KEY HANDLE                                         TO_CHAR(START_TIME,
---------- ---------- ---------------------------------------------- -------------------
1   113        113   /home/oracle/rmanbak/fullbk_117_1_758985958    2011-08-12 13:25:58
2   114        114   /home/oracle/rmanbak/fullbk_118_1_758985958    2011-08-12 13:26:13
3   115        115   /home/oracle/rmanbak/fullbk_119_1_758986006    2011-08-12 13:26:46
4   117        117   /home/oracle/rmanbak/arch_121_1_758986045      2011-08-12 13:27:26
5   118        118   /home/oracle/rmanbak/arch_122_1_758986043      2011-08-12 13:27:25
6   119        119   /home/oracle/rmanbak/arch_123_1_758986047      2011-08-12 13:27:27
7   120        120   /home/oracle/rmanbak/c-921635118-20110812-02  2011-08-12 14:42:15


因为在第一个节点执行恢复操作,所以要用到第二个节点上的归档的备份(arch_122_1_758986043)和第二个节点的归档日志
使用scp命令拷贝到第一个节点
[oracle@rac2 ~]$ scp archive/2_4_758985143.dbf rac1:/home/oracle/archive/
[oracle@rac2 ~]$ scp rmanbak/arch_122_1_758986043 rac1:/home/oracle/rmanbak/

每个节点都启动到nomount状态
SQL> startup nomount                      
ORACLE instance started.                
                                        
Total System Global Area  218103808 bytes
Fixed Size                  1218580 bytes
Variable Size              83888108 bytes
Database Buffers          125829120 bytes
Redo Buffers                7168000 bytes

执行恢复:
如果连控制文件一起恢复那在rman里执行如下命令restore controlfile from '/home/oracle/rmanbak/c-921635118-20110812-02';

[oracle@rac1 ~]$ rman target /

Recovery Manager: Release 10.2.0.1.0 - Production on Fri Aug 12 14:33:47 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: SYK (DBID=921635118, not open)

RMAN> restore database;

Starting restore at 12-AUG-11
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=307 instance=syk1 devtype=DISK

skipping datafile 1; already restored to file +ASM_DATA/syk/datafile/system.256.729209147
skipping datafile 4; already restored to file +ASM_DATA/syk/datafile/users.259.729209149
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to +ASM_DATA/syk/datafile/sysaux.257.729209149
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/fullbk_118_1_758985958
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/fullbk_118_1_758985958 tag=HOT_DB_BK_LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00002 to +ASM_DATA/syk/datafile/undotbs1.258.729209149
restoring datafile 00005 to +ASM_DATA/syk/datafile/undotbs2.264.729209281
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/fullbk_119_1_758986006
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/fullbk_119_1_758986006 tag=HOT_DB_BK_LEVEL0
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 12-AUG-11

RMAN> recover database;

Starting recover at 12-AUG-11
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 4 is already on disk as file +ASM_RECOVER/syk/onlinelog/group_1.257.729209205
archive log thread 1 sequence 5 is already on disk as file +ASM_DATA/syk/onlinelog/group_2.262.729209207
archive log thread 2 sequence 4 is already on disk as file +ASM_DATA/syk/onlinelog/group_4.266.729209319
archive log thread 2 sequence 5 is already on disk as file +ASM_RECOVER/syk/onlinelog/group_3.259.729209317
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=2
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/arch_121_1_758986045
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/arch_121_1_758986045 tag=TAG20110812T132723
channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
archive log filename=/home/oracle/archive/1_2_758985143.dbf thread=1 sequence=2
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=2 sequence=2
channel ORA_DISK_1: restoring archive log
archive log thread=2 sequence=3
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/arch_122_1_758986043
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/arch_122_1_758986043 tag=TAG20110812T132723
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/home/oracle/archive/2_2_758985143.dbf thread=2 sequence=2
channel ORA_DISK_1: starting archive log restore to default destination
channel ORA_DISK_1: restoring archive log
archive log thread=1 sequence=3
channel ORA_DISK_1: reading from backup piece /home/oracle/rmanbak/arch_123_1_758986047
channel ORA_DISK_1: restored backup piece 1
piece handle=/home/oracle/rmanbak/arch_123_1_758986047 tag=TAG20110812T132723
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archive log filename=/home/oracle/archive/1_3_758985143.dbf thread=1 sequence=3
archive log filename=/home/oracle/archive/2_3_758985143.dbf thread=2 sequence=3
archive log filename=+ASM_DATA/syk/onlinelog/group_4.266.729209319 thread=2 sequence=4
archive log filename=+ASM_RECOVER/syk/onlinelog/group_1.257.729209205 thread=1 sequence=4
archive log filename=+ASM_DATA/syk/onlinelog/group_2.262.729209207 thread=1 sequence=5
archive log filename=+ASM_RECOVER/syk/onlinelog/group_3.259.729209317 thread=2 sequence=5
media recovery complete, elapsed time: 00:00:14
Finished recover at 12-AUG-11

RMAN> alter database open resetlogs;

database opened

RMAN>

恢复完成。此次是完全恢复。

你可能感兴趣的:(职场,rman,backup,休闲)