异机使用完全备份恢复指定的PDB

来源:这里教程网 时间:2026-03-03 17:45:34 作者:

#恢复spfile,创建pfile并修改参数文件,再创建spfile

[oracle@ray103 dbs]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jul 14 14:51:20 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database (not started)
RMAN> startup nomount
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/19.3.0/dbhome_1/dbs/initraysuen.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area    1073737800 bytes
Fixed Size                     8904776 bytes
Variable Size                276824064 bytes
Database Buffers             784334848 bytes
Redo Buffers                   3674112 bytes
RMAN> restore spfile to '/u01/app/oracle/product/19.3.0/dbhome_1/dbs/spfileraysuen.ora' from '/u01/app/oracle/rman/spfile_c-3765622762-20220714-02';
Starting restore at 14-JUL-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /u01/app/oracle/rman/spfile_c-3765622762-20220714-02
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 14-JUL-22
RMAN> create pfile from spfile;
using target database control file instead of recovery catalog
Statement processed
#编辑pfile文件
[oracle@ray103 dbs]$ vi initraysuen.ora
[oracle@ray103 dbs]$ rm -f spfileraysuen.ora
oracle@ray103 dbs]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jul 14 15:11:41 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DUMMY (not mounted)
RMAN> shutdown immediate
using target database control file instead of recovery catalog
Oracle instance shut down
[oracle@ray103 dbs]$ sqlplus /nolog
SQL*Plus: Release 19.0.0.0.0 - Production on Thu Jul 14 15:14:13 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1191178288 bytes
Fixed Size                  9134128 bytes
Variable Size             385875968 bytes
Database Buffers          788529152 bytes
Redo Buffers                7639040 bytes
SQL> create spfile from pfile;
File created.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1191178288 bytes
Fixed Size                  9134128 bytes
Variable Size             385875968 bytes
Database Buffers          788529152 bytes
Redo Buffers                7639040 bytes
SQL>

#恢复控制文件

[oracle@ray103 oracle]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jul 14 15:19:51 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database: RAYSUEN (not mounted)
RMAN> restore controlfile from '/u01/app/oracle/backup/ctl_20220714_RAYSUEN_db_14_1.bak';
Starting restore at 14-JUL-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/RAYSUEN/current01.ora
output file name=/u01/app/oracle/oradata/RAYSUEN/current02.ora
Finished restore at 14-JUL-22
RMAN> sql 'alter database mount';
sql statement: alter database mount
released channel: ORA_DISK_1

#把备份文件信息读入控制文件

RMAN> catalog start with '/u01/app/oracle/backup/';
searching for all files that match the pattern /u01/app/oracle/backup/
List of Files Unknown to the Database
=====================================
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_7_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_8_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_9_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_10_1.bak
File Name: /u01/app/oracle/backup/arc_20220714_RAYSUEN_12_1.bak
File Name: /u01/app/oracle/backup/ctl_20220714_RAYSUEN_db_14_1.bak
File Name: /u01/app/oracle/backup/spfile_c-3765622762-20220714-02
Do you really want to catalog the above files (enter YES or NO)? yes
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_7_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_8_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_9_1.bak
File Name: /u01/app/oracle/backup/incr0_20220714_RAYSUEN_10_1.bak
File Name: /u01/app/oracle/backup/arc_20220714_RAYSUEN_12_1.bak
File Name: /u01/app/oracle/backup/ctl_20220714_RAYSUEN_db_14_1.bak
File Name: /u01/app/oracle/backup/spfile_c-3765622762-20220714-02
RMAN>
RMAN> list backup;

#恢复cdb和pdb

恢复cdb$root
run {
set newname for database to '/u01/app/oracle/oradata/RAYSUEN/%b';
restore database root ;
}
恢复PDB$SEED
run {
set newname for database to '/u01/app/oracle/oradata/RAYSUEN/pdbseed/%b';
restore database "PDB$SEED";
}
恢复pdb:rmanpdb
run {
set newname for database to '/u01/app/oracle/oradata/RAYSUEN/rmanpdb/%b';
restore database rmanpdb;
}
#恢复cdb
RMAN> run {
2> set newname for database to '/u01/app/oracle/oradata/RAYSUEN/%b';
3> restore database root ;
4> }
executing command: SET NEWNAME
Starting restore at 14-JUL-22
using channel ORA_DISK_1
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/RAYSUEN/system.261.1105292797
channel ORA_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/RAYSUEN/sysaux.263.1105292821
channel ORA_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/RAYSUEN/undotbs1.265.1105292839
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/RAYSUEN/users.269.1105292891
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/incr0_20220714_RAYSUEN_7_1.bak
channel ORA_DISK_1: errors found reading piece handle=/u01/app/oracle/rman/incr0_20220714_RAYSUEN_7_1.bak
channel ORA_DISK_1: failover to piece handle=/u01/app/oracle/backup/incr0_20220714_RAYSUEN_7_1.bak tag=TAG20220714T142334
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:05
Finished restore at 14-JUL-22
RMAN> run {
2> set newname for database to '/u01/app/oracle/oradata/RAYSUEN/pdbseed/%b';
3> restore database "PDB$SEED";
4> }
executing command: SET NEWNAME
Starting restore at 14-JUL-22
using channel ORA_DISK_1
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/RAYSUEN/pdbseed/system.262.1105292813
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/RAYSUEN/pdbseed/sysaux.264.1105292835
channel ORA_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/RAYSUEN/pdbseed/undotbs1.266.1105292845
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/incr0_20220714_RAYSUEN_10_1.bak
channel ORA_DISK_1: errors found reading piece handle=/u01/app/oracle/rman/incr0_20220714_RAYSUEN_10_1.bak
channel ORA_DISK_1: failover to piece handle=/u01/app/oracle/backup/incr0_20220714_RAYSUEN_10_1.bak tag=TAG20220714T142334
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:36
Finished restore at 14-JUL-22
RMAN> run {
2> set newname for database to '/u01/app/oracle/oradata/RAYSUEN/rmanpdb/%b';
3> restore database rmanpdb;
4> }
executing command: SET NEWNAME
Starting restore at 14-JUL-22
using channel ORA_DISK_1
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 00012 to /u01/app/oracle/oradata/RAYSUEN/rmanpdb/system.279.1109946625
channel ORA_DISK_1: restoring datafile 00013 to /u01/app/oracle/oradata/RAYSUEN/rmanpdb/sysaux.280.1109946625
channel ORA_DISK_1: restoring datafile 00014 to /u01/app/oracle/oradata/RAYSUEN/rmanpdb/undotbs1.278.1109946625
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/incr0_20220714_RAYSUEN_8_1.bak
channel ORA_DISK_1: errors found reading piece handle=/u01/app/oracle/rman/incr0_20220714_RAYSUEN_8_1.bak
channel ORA_DISK_1: failover to piece handle=/u01/app/oracle/backup/incr0_20220714_RAYSUEN_8_1.bak tag=TAG20220714T142334
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:46
Finished restore at 14-JUL-22
switch database root to copy;
switch database "PDB$SEED" to copy;
switch database rmanpdb to copy;
RMAN> switch database root to copy;
datafile 1 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/system.261.1105292797"
datafile 3 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/sysaux.263.1105292821"
datafile 5 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/undotbs1.265.1105292839"
datafile 7 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/users.269.1105292891"
RMAN> switch database "PDB$SEED" to copy;
datafile 2 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/pdbseed/system.262.1105292813"
datafile 4 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/pdbseed/sysaux.264.1105292835"
datafile 6 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/pdbseed/undotbs1.266.1105292845"
RMAN> switch database rmanpdb to copy;
datafile 12 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/rmanpdb/system.279.1109946625"
datafile 13 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/rmanpdb/sysaux.280.1109946625"
datafile 14 switched to datafile copy "/u01/app/oracle/oradata/RAYSUEN/rmanpdb/undotbs1.278.1109946625"
recover database skip forever tablespace RAYPDB:SYSTEM,RAYPDB:SYSAUX,RAYPDB:UNDOTBS1,RAYPDB:USERS;RAYPDB:temp01
RMAN> recover database skip forever tablespace RAYPDB:SYSTEM,RAYPDB:SYSAUX,RAYPDB:UNDOTBS1,RAYPDB:USERS;RAYPDB:temp01
Starting recover at 14-JUL-22
using channel ORA_DISK_1
Executing: alter database datafile 8 offline drop
Executing: alter database datafile 9 offline drop
Executing: alter database datafile 10 offline drop
Executing: alter database datafile 11 offline drop
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=35
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/rman/arc_20220714_RAYSUEN_21_1.bak
channel ORA_DISK_1: errors found reading piece handle=/u01/app/oracle/rman/arc_20220714_RAYSUEN_21_1.bak
channel ORA_DISK_1: failover to piece handle=/u01/app/oracle/backup/arc_20220714_RAYSUEN_21_1.bak tag=TAG20220714T163116
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
archived log file name=/u01/app/oracle/arch1_35_1105292778.dbf thread=1 sequence=35
unable to find archived log
archived log thread=1 sequence=36
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/14/2022 16:44:50
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 36 and starting SCN of 2319857
#这里应为redo的指向到了磁盘组,需要rename redo日志文件位置
RMAN> select member from v$logfile;
MEMBER                                                                          
--------------------------------------------------------------------------------
+DATA01/RAYSUEN/ONLINELOG/group_1.258.1105292783
+DATA01/RAYSUEN/ONLINELOG/group_2.259.1105292787
+DATA01/RAYSUEN/ONLINELOG/group_3.260.1105292791
SQL> select 'alter database rename file '||chr(39)||MEMBER||chr(39)||' to '||chr(39)||member||chr(39)||';' from gv$logfile b;
'ALTERDATABASERENAMEFILE'||CHR(39)||MEMBER||CHR(39)||'TO'||CHR(39)||MEMBER||CHR(
--------------------------------------------------------------------------------
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_1.258.1105292783' to '/u01/app/oracle/oradata/RAYSUEN/group_1.258.1105292783';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_2.259.1105292787' to '/u01/app/oracle/oradata/RAYSUEN/group_2.259.1105292787';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_3.260.1105292791' to '/u01/app/oracle/oradata/RAYSUEN/group_3.260.1105292791';
#编辑sql,并执行rename的sql语句
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_1.258.1105292783' to '/u01/app/oracle/oradata/RAYSUEN/redo01.log';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_2.259.1105292787' to '/u01/app/oracle/oradata/RAYSUEN/redo02.log';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_3.260.1105292791' to '/u01/app/oracle/oradata/RAYSUEN/redo03.log’;
SQL> alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_1.258.1105292783' to '/u01/app/oracle/oradata/RAYSUEN/redo01.log';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_2.259.1105292787' to '/u01/app/oracle/oradata/RAYSUEN/redo02.log';
alter database rename file '+DATA01/RAYSUEN/ONLINELOG/group_3.260.1105292791' to '/u01/app/oracle/oradata/RAYSUEN/redo03.log';
Database altered.
SQL>
Database altered.
SQL>
Database altered.
#以resetlogs的方式启动数据库
SQL> alter database open resetlogs;
Database altered.
SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 RAYPDB                         MOUNTED
         4 RMANPDB                        MOUNTED
#RAYPDB没有恢复,open失败,可以删除这个pdb
SQL> alter pluggable database RAYPDB open;
alter pluggable database RAYPDB open
*
ERROR at line 1:
ORA-01147: SYSTEM tablespace file 8 is offline
SQL> drop pluggable database RAYPDB including datafiles;
Pluggable database dropped.
SQL> SQL> alter pluggable database RMANPDB open;
Pluggable database altered.
SQ>

#更新切换temp表空间

Set linesize 300
Col datafile_path for a100
select t.con_id,t.ts#,t.name tablespace_name,tp.name datafile_path from v$tablespace t,V$TEMPFILE tp where t.ts#=tp.ts# and t.con_id=tp.con_id order by t.ts#,datafile_path;
    CON_ID        TS# TABLESPACE_NAME      DATAFILE_PATH
---------- ---------- -------------------- ----------------------------------------------------------------------------------------------------
         2          3 TEMP                 +DATA01/RAYSUEN/DF837B992FC72AB6E0536538A8C00D08/TEMPFILE/temp.268.1105292847
         4          3 TEMP                 +DATA01/RAYSUEN/E3AAEB6E55B60ECDE0536538A8C0FCB9/TEMPFILE/temp.281.1109946665
         1          3 TEMP                 +DATA01/RAYSUEN/TEMPFILE/temp.267.1105292847
SQL> show pdbs
    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         4 RMANPDB                        READ WRITE NO
SQL> create temporary tablespace TEMP02 tempfile '/u01/app/oracle/oradata/RAYSUEN/temp02_01.dbf' size 32M reuse autoextend on next 5M Maxsize 32767M;
Tablespace created.
SQL> alter database default temporary tablespace TEMP02;
Database altered.
SQL> drop tablespace TEMP including contents and datafiles;
Tablespace dropped.
#切换到pdb,切换pdb的temp表空间
SQL> alter session set container=RMANPDB;
Session altered.
SQL> create temporary tablespace TEMP02 tempfile '/u01/app/oracle/oradata/RAYSUEN/rmanpdb/temp02_01.dbf' size 32M reuse autoextend on next 5M Maxsize 32767M;
Tablespace created.
SQL> alter database default temporary tablespace TEMP02;
Database altered.
SQL> drop tablespace TEMP including contents and datafiles;
Tablespace dropped.
SQL> Set linesize 300
SQL> Col datafile_path for a100
SQL> select t.con_id,t.ts#,t.name tablespace_name,tp.name datafile_path from v$tablespace t,V$TEMPFILE tp where t.ts#=tp.ts# and t.con_id=tp.con_id order by t.ts#,datafile_path;
    CON_ID        TS# TABLESPACE_NAME      DATAFILE_PATH
---------- ---------- -------------------- ----------------------------------------------------------------------------------------------------
         2          3 TEMP                 +DATA01/RAYSUEN/DF837B992FC72AB6E0536538A8C00D08/TEMPFILE/temp.268.1105292847
         4          4 TEMP02               /u01/app/oracle/oradata/RAYSUEN/rmanpdb/temp02_01.dbf
         1          5 TEMP02               /u01/app/oracle/oradata/RAYSUEN/temp02_01.dbf

相关推荐