Oracle RMAN 异机恢复
作者:互联网
目录
- 1.1.1 创建测试数据
- 1.1.2 开启归档
- 1.1.3 全备
- 1.1.4 传输备份
- 1.1.5 异机完善相关目录
- 1.1.6 异机安装数据库软件及监听
- 1.1.7 异机启动nomount
- 1.1.8 恢复控制文件
- 1.1.9 启动mount恢复数据
- 1.1.10 RECOVER 数据
- 1.1.11 Open 验证数据
1.1 RMAN 全备
1.1.1 创建测试数据
SQL> create user liu identified by liu;
SQL> grant dba to liu;
SQL> conn liu/liu
Connected.
SQL> exit
SQL >CREATE TABLE EMP
( ID VARCHAR2(20) NOT NULL
, NAME VARCHAR2(20)
, CONSTRAINT EMP_PK PRIMARY KEY ( ID ) ENABLE );
1.1.2 开启归档
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 826753024 bytes
Fixed Size 2257760 bytes
Variable Size 536874144 bytes
Database Buffers 285212672 bytes
Redo Buffers 2408448 bytes
Database mounted.
SQL> alter system set log_archive_dest_1='location=/u01/archivelog';
System altered.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archivelog
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4
SQL>
1.1.3 全备
[oracle@leo1 backup]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Thu Jun 10 02:44:08 2021
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=486657568)
RMAN>
run
{
allocate channel f1 device type disk;
allocate channel f2 device type disk;
allocate channel f3 device type disk;
allocate channel f4 device type disk;
sql 'alter system archive log current';
sql 'alter system archive log current';
sql 'alter system archive log current';
BACKUP AS COMPRESSED BACKUPSET DATABASE format '/u01/backup/full_%d_%T_%U.bak';
backup as compressed backupset archivelog all format '/u01/backup/arch_%d_%T_%U.arc';
backup current controlfile format '/u01/backup/control_%d_%T_%U.ctl';
sql "create pfile=''/u01/backup/pfile.ora'' from spfile";
release channel f1;
release channel f2;
release channel f3;
release channel f4;
}
using target database control file instead of recovery catalog
allocated channel: f1
channel f1: SID=33 device type=DISK
allocated channel: f2
channel f2: SID=34 device type=DISK
allocated channel: f3
channel f3: SID=35 device type=DISK
allocated channel: f4
channel f4: SID=36 device type=DISK
sql statement: alter system archive log current
sql statement: alter system archive log current
sql statement: alter system archive log current
Starting backup at 10-JUN-21
channel f1: starting compressed full datafile backup set
channel f1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf
channel f1: starting piece 1 at 10-JUN-21
channel f2: starting compressed full datafile backup set
channel f2: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/prod/sysaux01.dbf
channel f2: starting piece 1 at 10-JUN-21
channel f3: starting compressed full datafile backup set
channel f3: specifying datafile(s) in backup set
input datafile file number=00003 name=/u01/app/oracle/oradata/prod/undotbs01.dbf
channel f3: starting piece 1 at 10-JUN-21
channel f4: starting compressed full datafile backup set
channel f4: specifying datafile(s) in backup set
including current control file in backup set
channel f4: starting piece 1 at 10-JUN-21
channel f4: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_040112k1_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f4: backup set complete, elapsed time: 00:00:01
channel f4: starting compressed full datafile backup set
channel f4: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf
channel f4: starting piece 1 at 10-JUN-21
channel f4: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_050112k3_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f4: backup set complete, elapsed time: 00:00:01
channel f4: starting compressed full datafile backup set
channel f4: specifying datafile(s) in backup set
including current SPFILE in backup set
channel f4: starting piece 1 at 10-JUN-21
channel f4: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_060112k4_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f4: backup set complete, elapsed time: 00:00:01
channel f3: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_030112k1_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f3: backup set complete, elapsed time: 00:00:06
channel f2: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_020112k1_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f2: backup set complete, elapsed time: 00:00:28
channel f1: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/full_PROD_20210610_010112k1_1_1.bak tag=TAG20210610T024416 comment=NONE
channel f1: backup set complete, elapsed time: 00:00:38
Finished backup at 10-JUN-21
Starting backup at 10-JUN-21
current log archived
channel f1: starting compressed archived log backup set
channel f1: specifying archived log(s) in backup set
input archived log thread=1 sequence=4 RECID=1 STAMP=1074825855
channel f1: starting piece 1 at 10-JUN-21
channel f2: starting compressed archived log backup set
channel f2: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=2 STAMP=1074825855
channel f2: starting piece 1 at 10-JUN-21
channel f3: starting compressed archived log backup set
channel f3: specifying archived log(s) in backup set
input archived log thread=1 sequence=6 RECID=3 STAMP=1074825856
channel f3: starting piece 1 at 10-JUN-21
channel f4: starting compressed archived log backup set
channel f4: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=4 STAMP=1074825896
channel f4: starting piece 1 at 10-JUN-21
channel f2: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/arch_PROD_20210610_080112l8_1_1.arc tag=TAG20210610T024456 comment=NONE
channel f2: backup set complete, elapsed time: 00:00:00
channel f1: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/arch_PROD_20210610_070112l8_1_1.arc tag=TAG20210610T024456 comment=NONE
channel f1: backup set complete, elapsed time: 00:00:01
channel f3: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/arch_PROD_20210610_090112l8_1_1.arc tag=TAG20210610T024456 comment=NONE
channel f3: backup set complete, elapsed time: 00:00:01
channel f4: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/arch_PROD_20210610_0a0112l8_1_1.arc tag=TAG20210610T024456 comment=NONE
channel f4: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JUN-21
Starting backup at 10-JUN-21
channel f1: starting full datafile backup set
channel f1: specifying datafile(s) in backup set
including current control file in backup set
channel f1: starting piece 1 at 10-JUN-21
channel f1: finished piece 1 at 10-JUN-21
piece handle=/u01/backup/control_PROD_20210610_0b0112l9_1_1.ctl tag=TAG20210610T024457 comment=NONE
channel f1: backup set complete, elapsed time: 00:00:01
Finished backup at 10-JUN-21
sql statement: create pfile=''/u01/backup/pfile.ora'' from spfile
released channel: f1
released channel: f2
released channel: f3
released channel: f4
RMAN>exit
1.1.4 传输备份
传输备份至要恢复的主机上
传输密码文件至异机
1.1.5 异机完善相关目录
根据备份的参数文件(pfile)完善异机目录
归档log_archive_dest_1 路径
闪回db_recovery_file_dest 路径
审计audit_file_dest 路径
[oracle@leo2 backup]$ pwd
/u01/backup
[oracle@leo2 backup]$ more pfile.ora
prod.__db_cache_size=348127232
prod.__java_pool_size=4194304
prod.__large_pool_size=8388608
prod.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
prod.__pga_aggregate_target=335544320
prod.__sga_target=494927872
prod.__shared_io_pool_size=0
prod.__shared_pool_size=125829120
prod.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/prod/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/u01/app/oracle/oradata/prod/control01.ctl','/u01/app/oracle/fast_recovery_area/prod/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='prod'
*.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=prodXDB)'
*.log_archive_dest_1='location=/u01/archivelog'
*.memory_target=830472192
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
[oracle@leo2 backup]$
[oracle@leo2 backup]$ mkdir -p /u01/app/oracle/admin/prod/adump
[oracle@leo2 backup]$ mkdir -p /u01/app/oracle/fast_recovery_area/
[oracle@leo2 backup]$ mkdir -p /u01/archivelog
[oracle@leo2 backup]$ mkdir -p /u01/app/oracle/oradata/prod/
1.1.6 异机安装数据库软件及监听
1.1.7 异机启动nomount
异机利用pfile启动至nomount
[oracle@leo2backup]$ cp pfile.ora /u01/app/oracle/product/11.2.0/dbhome_1/dbs/initprod.ora
[oracle@leo2 backup]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jun 10 03:26:52 2021
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1027182592 bytes
Fixed Size 2259680 bytes
Variable Size 872416544 bytes
Database Buffers 146800640 bytes
Redo Buffers 5705728 bytes
1.1.8 恢复控制文件
RMAN> restore controlfile from '/u01/backup/control_PROD_20210610_0b0112l9_1_1.ctl';
output file 中的目录是由pfile文件中controlfile 参数指定的。
1.1.9 启动mount恢复数据
RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1
RMAN> catalog start with '/u01/backup/';
RMAN>
run
{
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
allocate channel c4 device type disk;
restore database;
SWITCH DATAFILE ALL;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
}
allocated channel: c1
channel c1: SID=1 device type=DISK
allocated channel: c2
channel c2: SID=20 device type=DISK
allocated channel: c3
channel c3: SID=21 device type=DISK
allocated channel: c4
channel c4: SID=22 device type=DISK
Starting restore at 10-JUN-21
channel c1: starting datafile backup set restore
channel c1: specifying datafile(s) to restore from backup set
channel c1: restoring datafile 00004 to /u01/app/oracle/oradata/prod/users01.dbf
channel c1: reading from backup piece /u01/backup/full_PROD_20210610_050112k3_1_1.bak
channel c2: starting datafile backup set restore
channel c2: specifying datafile(s) to restore from backup set
channel c2: restoring datafile 00003 to /u01/app/oracle/oradata/prod/undotbs01.dbf
channel c2: reading from backup piece /u01/backup/full_PROD_20210610_030112k1_1_1.bak
channel c3: starting datafile backup set restore
channel c3: specifying datafile(s) to restore from backup set
channel c3: restoring datafile 00002 to /u01/app/oracle/oradata/prod/sysaux01.dbf
channel c3: reading from backup piece /u01/backup/full_PROD_20210610_020112k1_1_1.bak
channel c4: starting datafile backup set restore
channel c4: specifying datafile(s) to restore from backup set
channel c4: restoring datafile 00001 to /u01/app/oracle/oradata/prod/system01.dbf
channel c4: reading from backup piece /u01/backup/full_PROD_20210610_010112k1_1_1.bak
channel c1: piece handle=/u01/backup/full_PROD_20210610_050112k3_1_1.bak tag=TAG20210610T024416
channel c1: restored backup piece 1
channel c1: restore complete, elapsed time: 00:00:01
channel c2: piece handle=/u01/backup/full_PROD_20210610_030112k1_1_1.bak tag=TAG20210610T024416
channel c2: restored backup piece 1
channel c2: restore complete, elapsed time: 00:00:07
channel c3: piece handle=/u01/backup/full_PROD_20210610_020112k1_1_1.bak tag=TAG20210610T024416
channel c3: restored backup piece 1
channel c3: restore complete, elapsed time: 00:00:35
channel c4: piece handle=/u01/backup/full_PROD_20210610_010112k1_1_1.bak tag=TAG20210610T024416
channel c4: restored backup piece 1
channel c4: restore complete, elapsed time: 00:00:55
Finished restore at 10-JUN-21
released channel: c1
released channel: c2
released channel: c3
released channel: c4
RMAN>
1.1.10 RECOVER 数据
在11g官方文档error messages中对错误描述如下:
RMAN-06054: media recovery requesting unknown archived log for thread string with sequence string and starting SCN of string
Cause: Media recovery is requesting a log whose existence is not recorded in the recovery catalog or target database control file.
Action: If a copy of the log is available, then add it to the recovery catalog and/or control file via a CATALOG command and then retry the RECOVER command. If not, then a point-in-time recovery up to the missing log is the only alternative and database can be opened using ALTER DATABASE OPEN RESETLOGS command.
可见,出先此错误的原因是恢复需要的日志记录在控制文件或恢复目录中找不到。解决方法分两种情况:
1.如果相关的日志存在且可用的话,就将此日志记录添加到控制文件或恢复目录中。
2.如果相关的日志已经被删除了或不可用了,那么就按照错误的提示scn将数据库恢复到此scn,本案例是964755。也就是说此时数据库只能进行不完全恢复了,在打开数据库时得使用resetlogs打开。
1.1.11 Open 验证数据
标签:10,set,异机,Oracle,RMAN,piece,backup,channel,u01 来源: https://blog.51cto.com/u_11298469/2899435