实验说明

环境:源主机和目标主机相同

[oracle@host01 ~]$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[oracle@host01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Wed Sep 3 00:59:15 2025
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> 

流程:归档模式下,将源主机的orcl库生成备份集,然后在目标主机上还原,数据未丢失。

1、在源主机上备份源库的参数文件控制文件数据文件归档日志文件,同时还需要用到源库正在使用的在线日志文件

2、在目标主机上安装同版本的数据库软件,各种配置路径和源主机相同(数据文件、快速恢复区、审计日志);新建一个简单的实例启动参数文件,通过. oraenv设置实例id和home目录;

3、将源主机上包含步骤1中的5类数据传输到目标主机上;

4、在目标主机上恢复数据:

        A.通过参数文件启动辅助实例;

        B.依次恢复参数文件、控制文件、数据文件,打开控制文件;

        C.将归档日志备份集注册到控制文件,将redo日志文件复制到默认的文件位置;

       D. 修复数据库,以resetlogs参数打开数据库;

5、重启数据库,验证数据是否丢失。

源主机操作

test表用于验证数据是否有丢失,备份数据文件前插入数据:

conn hr/hr

SQL> create table test(val nvarchar2(50) not null,adddate date default sysdate);

SQL> insert into test(val) values('this row insert bofore rman backup;');

SQL> commit;

SQL> alter system flush buffer_cache;

rman备份数据库:

RMAN\>backup database format '/u01/app/oracle/bak/dbbak_%d_%t_%s.bak';

备份数据文件后在插入数据,数据将存在于归档日志中:

SQL> insert into test(val) values('this row insert after rman backup');

归档生成

SQL> alter system switch logfile;

SQL> alter system switch logfile;

SQL> alter system switch logfile;

插入最后一条数据,未提交,数据在redo中,

SQL> insert into test(val) values('123123')

查看下日志序列信息

SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 25

Next log sequence to archive 27

Current log sequence 27

RMAN\>list backup;

备份归档日志,复制出当前在线日志,整理备份数据:

RMAN\>backup archivelog all format '/u01/app/oracle/bak/archbak_%d_%t_%s.bak';

cp /u01/app/oracle/fast_recovery_area/ORCL/autobackup/2025_09_02/o1_mf_s_1210730726_ncfdtpgf_.bkp  /u01/app/oracle/bak/

cp /u01/app/oracle/oradata/ORCL/redo0*  /u01/app/oracle/bak/

复制备份数据到目标主机:

scp -r /u01/app/oracle/bak/ 10.10.20.51:/orabak/

目标主机操作

.oraenv

        orcl

        /u01/app/oracle/product/19.3.0/dbhome_1

cat /u01/app/oracle/product/19.3.0/dbhome_1/dbs/initorcl.ora

db\_name\='ORCL'

remote\_login\_passwordfile\='EXCLUSIVE'

[oracle@host02 orabak]$ ll /orabak --备份数据目录

total 2038412

-rw-r-----. 1 oracle oinstall 168245760 Sep 2 02:10 archbak_ORCL_1210730725_17.bak

-rw-r-----. 1 oracle oinstall 1279213568 Sep 2 02:09 dbbak_ORCL_1210730655_15.bak

-rw-r-----. 1 oracle oinstall 10715136 Sep 2 02:10 o1_mf_s_1210730726_ncfdtpgf_.bkp

-rw-r-----. 1 oracle oinstall 209715712 Sep 2 02:10 redo01.log

-rw-r-----. 1 oracle oinstall 209715712 Sep 2 02:10 redo02.log

-rw-r-----. 1 oracle oinstall 209715712 Sep 2 02:10 redo03.log

RMAN操作:

rman target /

RMAN\>startup nomount

RMAN\>restore spfile from '/orabak/o1_mf_s_1210730726_ncfdtpgf_.bkp';

RMAN\>restore controlfile from '/orabak/o1_mf_s_1210730726_ncfdtpgf_.bkp';

RMAN\>alter database mount;

RMAN\>catalog start with '/orabak';

RMAN\>list backup;

cp redo* /u01/app/oracle/oradata/ORCL

RMAN\>restore database;

RMAN\>recover database;

RMAN\>alter database open resetlogs;

查询后数据未丢失

SQL> conn hr/hr

Connected.

SQL> select val,to_char(adddate,'hh24:mi:ss') from test order by 2 ;

VAL TO_CHAR(


this row insert bofore rman backup; 01:38:12

this row insert bofore rman backup; 01:38:13

this row insert bofore rman backup; 01:38:14

this row insert bofore rman backup; 01:38:14

this row insert bofore rman backup; 01:38:15

this row insert bofore rman backup; 01:38:15

this row insert bofore rman backup; 01:38:15

this row insert bofore rman backup; 01:38:16

this row insert after rman backup 02:04:32

this row insert after rman backup 02:04:34

this row insert after rman backup 02:04:34

VAL TO_CHAR(


this row insert by last 02:05:53

this row insert by last 02:05:54

this row insert by last 02:05:54

this row insert by last 02:05:55

123123 02:06:43

16 rows selected.

SQL>

源主机rman备份日志

RMAN\> backup database format '/u01/app/oracle/bak/dbbak\_%d\_%t\_%s.bak';

Starting backup at 02-SEP-25

using channel ORA\_DISK\_1

channel ORA\_DISK\_1: starting full datafile backup set

channel ORA\_DISK\_1: specifying datafile(s) in backup set

input datafile file number\=00001 name\=/u01/app/oracle/oradata/ORCL/system01.dbf

input datafile file number\=00003 name\=/u01/app/oracle/oradata/ORCL/sysaux01.dbf

input datafile file number\=00004 name\=/u01/app/oracle/oradata/ORCL/undotbs01.dbf

input datafile file number\=00007 name\=/u01/app/oracle/oradata/ORCL/users01.dbf

channel ORA\_DISK\_1: starting piece 1 at 02-SEP-25

channel ORA\_DISK\_1: finished piece 1 at 02-SEP-25

piece handle\=/u01/app/oracle/bak/dbbak\_ORCL\_1210730655\_15.bak tag\=TAG20250902T020415 comment\=NONE

channel ORA\_DISK\_1: backup set complete, elapsed time: 00:00:03

Finished backup at 02-SEP-25

Starting Control File and SPFILE Autobackup at 02-SEP-25

piece handle\=/u01/app/oracle/fast\_recovery\_area/ORCL/autobackup/2025\_09\_02/o1\_mf\_s\_1210730658\_ncfdrl8l\_.bkp comment\=NONE

Finished Control File and SPFILE Autobackup at 02-SEP-25

RMAN\> backup archivelog all format '/u01/app/oracle/bak/archbak\_%d\_%t\_%s.bak';

Starting backup at 02-SEP-25

current log archived

using channel ORA\_DISK\_1

channel ORA\_DISK\_1: starting archived log backup set

channel ORA\_DISK\_1: specifying archived log(s) in backup set

input archived log thread\=1 sequence\=7 RECID\=1 STAMP\=1210638472

input archived log thread\=1 sequence\=8 RECID\=2 STAMP\=1210638476

input archived log thread\=1 sequence\=9 RECID\=3 STAMP\=1210708056

input archived log thread\=1 sequence\=10 RECID\=4 STAMP\=1210708173

input archived log thread\=1 sequence\=11 RECID\=5 STAMP\=1210708202

input archived log thread\=1 sequence\=12 RECID\=6 STAMP\=1210728896

input archived log thread\=1 sequence\=13 RECID\=7 STAMP\=1210728898

input archived log thread\=1 sequence\=14 RECID\=8 STAMP\=1210728901

input archived log thread\=1 sequence\=15 RECID\=9 STAMP\=1210728902

input archived log thread\=1 sequence\=16 RECID\=10 STAMP\=1210728904

input archived log thread\=1 sequence\=17 RECID\=11 STAMP\=1210729151

input archived log thread\=1 sequence\=18 RECID\=12 STAMP\=1210729152

input archived log thread\=1 sequence\=19 RECID\=13 STAMP\=1210729156

input archived log thread\=1 sequence\=20 RECID\=14 STAMP\=1210730091

input archived log thread\=1 sequence\=21 RECID\=15 STAMP\=1210730183

input archived log thread\=1 sequence\=22 RECID\=16 STAMP\=1210730705

input archived log thread\=1 sequence\=23 RECID\=17 STAMP\=1210730707

input archived log thread\=1 sequence\=24 RECID\=18 STAMP\=1210730711

input archived log thread\=1 sequence\=25 RECID\=19 STAMP\=1210730712

input archived log thread\=1 sequence\=26 RECID\=20 STAMP\=1210730725

channel ORA\_DISK\_1: starting piece 1 at 02-SEP-25

channel ORA\_DISK\_1: finished piece 1 at 02-SEP-25

piece handle\=/u01/app/oracle/bak/archbak\_ORCL\_1210730725\_17.bak tag\=TAG20250902T020525 comment\=NONE

channel ORA\_DISK\_1: backup set complete, elapsed time: 00:00:01

Finished backup at 02-SEP-25

Starting Control File and SPFILE Autobackup at 02-SEP-25

piece handle\=/u01/app/oracle/fast\_recovery\_area/ORCL/autobackup/2025\_09\_02/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp comment\=NONE

Finished Control File and SPFILE Autobackup at 02-SEP-25

RMAN\>

目标机rman恢复日志

[oracle@host02 \~]\$ rman target /

Recovery Manager: Release 19.0.0.0.0 - Production on Tue Sep 2 02:17:53 2025

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

Oracle instance started

Total System Global Area     306183456 bytes

Fixed Size                     8895776 bytes

Variable Size                239075328 bytes

Database Buffers              50331648 bytes

Redo Buffers                   7880704 bytes

RMAN\> restore spfile from '/orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp';

Starting restore at 02-SEP-25

allocated channel: ORA\_DISK\_1

channel ORA\_DISK\_1: SID\=10 device type\=DISK

channel ORA\_DISK\_1: restoring spfile from AUTOBACKUP /orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp

channel ORA\_DISK\_1: SPFILE restore from AUTOBACKUP complete

Finished restore at 02-SEP-25

RMAN\> restore controlfile from '/orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp';

Starting restore at 02-SEP-25

allocated channel: ORA\_DISK\_1

channel ORA\_DISK\_1: SID\=246 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/ORCL/control01.ctl

output file name\=/u01/app/oracle/fast\_recovery\_area/ORCL/control02.ctl

Finished restore at 02-SEP-25

RMAN\> create pfile from spfile;

Statement processed

RMAN\> alter database mount;

released channel: ORA\_DISK\_1

Statement processed

RMAN\>

RMAN\> catalog start with '/orabak';

Starting implicit crosscheck backup at 02-SEP-25

allocated channel: ORA\_DISK\_1

channel ORA\_DISK\_1: SID\=246 device type\=DISK

Crosschecked 3 objects

Finished implicit crosscheck backup at 02-SEP-25

Starting implicit crosscheck copy at 02-SEP-25

using channel ORA\_DISK\_1

Finished implicit crosscheck copy at 02-SEP-25

searching for all files in the recovery area

cataloging files...

no files cataloged

searching for all files that match the pattern /orabak

List of Files Unknown to the Database

File Name: /orabak/dbbak\_ORCL\_1210730655\_15.bak

File Name: /orabak/archbak\_ORCL\_1210730725\_17.bak

File Name: /orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp

File Name: /orabak/redo01.log

File Name: /orabak/redo02.log

File Name: /orabak/redo03.log

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

cataloging files...

cataloging done

List of Cataloged Files

File Name: /orabak/dbbak\_ORCL\_1210730655\_15.bak

File Name: /orabak/archbak\_ORCL\_1210730725\_17.bak

File Name: /orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp

List of Files Which Were Not Cataloged

File Name: /orabak/redo01.log

RMAN-07529: Reason: catalog is not supported for this file type

File Name: /orabak/redo02.log

RMAN-07529: Reason: catalog is not supported for this file type

File Name: /orabak/redo03.log

RMAN-07529: Reason: catalog is not supported for this file type

RMAN\> list backup;

List of Backup Sets

BS Key  Type LV Size

15      Full    1.19G

List of Datafiles in backup set 15

File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name

1       Full 2421878    02-SEP-25              NO    /u01/app/oracle/oradata/ORCL/system01.dbf

3       Full 2421878    02-SEP-25              NO    /u01/app/oracle/oradata/ORCL/sysaux01.dbf

4       Full 2421878    02-SEP-25              NO    /u01/app/oracle/oradata/ORCL/undotbs01.dbf

7       Full 2421878    02-SEP-25              NO    /u01/app/oracle/oradata/ORCL/users01.dbf

Backup Set Copy #1 of backup set 15

Device Type Elapsed Time Completion Time Compressed Tag

DISK        00:00:01     02-SEP-25       NO         TAG20250902T020415

List of Backup Pieces for backup set 15 Copy #1 BP Key  Pc# Status      Piece Name ------- --- ----------- ---------- 15      1   EXPIRED     /u01/app/oracle/bak/dbbak\_ORCL\_1210730655\_15.bak

Backup Set Copy #2 of backup set 15

Device Type Elapsed Time Completion Time Compressed Tag

DISK        00:00:01     02-SEP-25       NO         TAG20250902T020415

List of Backup Pieces for backup set 15 Copy #2 BP Key  Pc# Status      Piece Name ------- --- ----------- ---------- 18      1   AVAILABLE   /orabak/dbbak\_ORCL\_1210730655\_15.bak

BS Key  Size

17      160.45M

List of Archived Logs in backup set 17

Thrd Seq     Low SCN    Low Time  Next SCN   Next Time

1    7       2211371    20-AUG-25 2270892    01-SEP-25

1    8       2270892    01-SEP-25 2270910    01-SEP-25

1    9       2270910    01-SEP-25 2377867    01-SEP-25

1    10      2377867    01-SEP-25 2384347    01-SEP-25

1    11      2384347    01-SEP-25 2384384    01-SEP-25

1    12      2384384    01-SEP-25 2419110    02-SEP-25

1    13      2419110    02-SEP-25 2419113    02-SEP-25

1    14      2419113    02-SEP-25 2419117    02-SEP-25

1    15      2419117    02-SEP-25 2419120    02-SEP-25

1    16      2419120    02-SEP-25 2419123    02-SEP-25

1    17      2419123    02-SEP-25 2419282    02-SEP-25

1    18      2419282    02-SEP-25 2419285    02-SEP-25

1    19      2419285    02-SEP-25 2419289    02-SEP-25

1    20      2419289    02-SEP-25 2420817    02-SEP-25

1    21      2420817    02-SEP-25 2421405    02-SEP-25

1    22      2421405    02-SEP-25 2421923    02-SEP-25

1    23      2421923    02-SEP-25 2421926    02-SEP-25

1    24      2421926    02-SEP-25 2421930    02-SEP-25

1    25      2421930    02-SEP-25 2421933    02-SEP-25

1    26      2421933    02-SEP-25 2421960    02-SEP-25

Backup Set Copy #1 of backup set 17

Device Type Elapsed Time Completion Time Compressed Tag

DISK        00:00:00     02-SEP-25       NO         TAG20250902T020525

List of Backup Pieces for backup set 17 Copy #1 BP Key  Pc# Status      Piece Name ------- --- ----------- ---------- 17      1   EXPIRED     /u01/app/oracle/bak/archbak\_ORCL\_1210730725\_17.bak

Backup Set Copy #2 of backup set 17

Device Type Elapsed Time Completion Time Compressed Tag

DISK        00:00:00     02-SEP-25       NO         TAG20250902T020525

List of Backup Pieces for backup set 17 Copy #2 BP Key  Pc# Status      Piece Name ------- --- ----------- ---------- 19      1   AVAILABLE   /orabak/archbak\_ORCL\_1210730725\_17.bak

BS Key  Type LV Size       Device Type Elapsed Time Completion Time

18      Full    10.20M     DISK        00:00:00     02-SEP-25

    BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20250902T020526 Piece Name: /orabak/o1\_mf\_s\_1210730726\_ncfdtpgf\_.bkp

SPFILE Included: Modification time: 02-SEP-25

SPFILE db\_unique\_name: ORCL

Control File Included: Ckp SCN: 2421973      Ckp time: 02-SEP-25

RMAN\> restore database;

Starting restore at 02-SEP-25

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/ORCL/system01.dbf

channel ORA\_DISK\_1: restoring datafile 00003 to /u01/app/oracle/oradata/ORCL/sysaux01.dbf

channel ORA\_DISK\_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORCL/undotbs01.dbf

channel ORA\_DISK\_1: restoring datafile 00007 to /u01/app/oracle/oradata/ORCL/users01.dbf

channel ORA\_DISK\_1: reading from backup piece /orabak/dbbak\_ORCL\_1210730655\_15.bak

channel ORA\_DISK\_1: piece handle\=/orabak/dbbak\_ORCL\_1210730655\_15.bak tag\=TAG20250902T020415

channel ORA\_DISK\_1: restored backup piece 1

channel ORA\_DISK\_1: restore complete, elapsed time: 00:00:03

Finished restore at 02-SEP-25

RMAN\> recover database;

Starting recover at 02-SEP-25

using channel ORA\_DISK\_1

starting media recovery

archived log for thread 1 with sequence 27 is already on disk as file /u01/app/oracle/oradata/ORCL/redo03.log

archived log file name\=/u01/app/oracle/oradata/ORCL/redo03.log thread\=1 sequence\=27

media recovery complete, elapsed time: 00:00:00

Finished recover at 02-SEP-25

RMAN\> alter database open resetlogs;

Statement processed

RMAN\>
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐