RMAN详解

owner
2024-01-25 / 0 评论 / 53 阅读 / 正在检测是否收录...

RMAN详解

一、备份与RMAN备份的概念

  • 数据库完全备份:

    按归档模式分为归档和非归档
    归档模式
    打开状态,属于非一致性备份
    关闭状态,可以分为一致性和非一致性
    非归档模式
    打开状态,非一致性备份无效
    关闭状态,一致性备份,非一致性备份不被推荐

  • RMAN备份
    RMAN使用会话来完成备份操作,从RMAN客户端连接到服务器将产生一个服务器会话
    RMAN备份内容包括:整个数据库,表空间,数据文件,指定的数据文件,控制文件,归档日志文件,参数文件等
  • RMAN备份的类型
    完整备份(full)或增量备份(incremental)
    一致性备份(consistent)或不一致性备份(inconsistent)
    热备(open)或冷备(closed),冷备时数据库必须处于mount状态,冷备可以为一致性备份或非一致性备份
  • 完整备份
    一个或多个数据文件的一个完整副本,包含从备份开始处所有的数据块.完整备份不能作为增量的基础
  • 增量备份
    包含从最近一次备份以来被修改或添加的数据块.可以分为差异增量备份和累计增量备份
    差异增量备份仅仅包含n级或n级以下被修改过的数据块。备份数据量小,时间长。
    累计增量备份仅仅包含n-1级或n-1级以下被修改过的数据块。备份数据量大,恢复时间短。
    0级增量备份相当于一个完整备份,该备份包含所有已用的数据块文件,与完整备份的差异是完整备份不能用作级增量备份的基础
  • 一致性备份
    备份所包含的各个文件中的所有修改都具备相同的系统变化编号(system change number,SCN)。
    也就是说,备份所包含的各个文件中的所有数据均来自同一时间点。
    一致性数据库完全备份(consis-tent whole backup)进行还原(restore)后,不需要执行恢复操作(recovery)
  • 非一致性备份
    在数据库处于打开(open)状态时,或数据库异常关闭(shut down abnormally)后,对一个或多个数据库文件进行的备份。

    非一致性备份需要在还原之后进行恢复操作

  • 备份集与镜像副本
    备份集是包含一个或多个数据文件,归档日志文件的二进制文件的集合.备份集由备份片组成,一个备份集中可以包含一个或多个备份片
    可以通过filesperset参数来设置备份集中可包含的备份片数,也可以设定参数maxpiecesize来制定每个备份片的大小。备份集中空闲的数据块将不会被备份,因此备份集可以支持压缩。备份集支持增量备份,可以备份到磁盘或磁带。
  • 镜像副本
    是数据文件或归档日志文件等的完整拷贝,未经过任何压缩等处理,不能备份到磁带,也不支持增量备份。
    恢复时可以立即使用实现快速恢复。
    等同于操作系统的复制命令。
    可以作为级增量备份。
  • 备份路径
    可以备份到磁盘目录
    可以备份到磁带
    闪回区
  • 备份限制
    数据库必须处于mount或open状态
    不能备份联机日志
    在非归档模式下仅仅能作干净备份,即在干净关闭且启动到mount状态下备份
    在归档模式下,current状态下数据文件可以备份

二、使用RMAN进行备份

1、备份数据库

查看数据库当前工作模式,非ARCHIVELOG模式更改为ARCHIVELOG模式

SQL> select dbid,name,log_mode from v$database;------查看当前数据库是不是archivelog模式
      DBID NAME                        LOG_MODE
---------- --------------------------- ------------------------------------
2816063020 ORADB                       NOARCHIVELOG
SQL> shutdown immediate------关闭immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount------启动到nomount模式
ORACLE instance started.
Total System Global Area 1426059296 bytes
Fixed Size                  8896544 bytes
Variable Size             352321536 bytes
Database Buffers         1056964608 bytes
Redo Buffers                7876608 bytes
SQL> alter database mount;------挂载数据库
Database altered.
SQL> archive log list------归档日志列表
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /u01/app/oracle/product/19c/dbs/arch
Oldest online log sequence     16
Current log sequence           18
SQL> alter database archivelog;------更改数据库为归档日志模式
Database altered.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /u01/app/oracle/product/19c/dbs/arch
Oldest online log sequence     16
Next log sequence to archive   18
Current log sequence           18
SQL>

备份数据库

创建RMAN路径

[oracle@oradb ~]$ mkdir /u01/app/oracle/rmanbak/
[oracle@oradb ~]$

开始备份

[oracle@oradb ~]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Sun Apr 11 22:48:36 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ORADB (DBID=2816063020, not open)
RMAN> backup database format '/u01/app/oracle/rmanbak/whole_%d_%U';------备份整个数据库
Starting backup at 11-APR-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=273 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT01.DBF
input datafile file number=00003 name=/u01/app/oracle/oradata/ORADB/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/ORADB/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT03.DBF
input datafile file number=00005 name=/u01/app/oracle/product/19coradatahr.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/ORADB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/rmanbak/whole_ORADB_02vs2eb4_1_1 tag=TAG20210411T224908 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
Finished backup at 11-APR-21

Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-00 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21

RMAN> backup as compressed backupset database format '/u01/app/oracle/rmanbak/whole_%d_%U';------备份整个数据库并压缩备份集
Starting backup at 11-APR-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting compressed full datafile backup s·et
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT01.DBF
input datafile file number=00003 name=/u01/app/oracle/oradata/ORADB/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/ORADB/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT03.DBF
input datafile file number=00005 name=/u01/app/oracle/product/19coradatahr.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/ORADB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/rmanbak/whole_ORADB_04vs2efb_1_1 tag=TAG20210411T225123 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
Finished backup at 11-APR-21

Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-01 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21

RMAN>
2、备份数据文件
RMAN> backup as copy datafile 4 format '/u01/app/oracle/rmanbak/df_%d_%U';------备份类型为镜像备份
Starting backup at 11-APR-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
output file name=/u01/app/oracle/rmanbak/df_ORADB_data_D-ORADB_I-2816063020_TS-UNDOTBS1_FNO-4_0avs2fem tag=TAG20210411T230806 RECID=1 STAMP=1069628896
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-03 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN> list copy;
specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================
Key     File S Completion Time Ckp SCN    Ckp Time        Sparse
------- ---- - --------------- ---------- --------------- ------
1       4    A 11-APR-21       2942179    11-APR-21       NO
        Name: /u01/app/oracle/rmanbak/df_ORADB_data_D-ORADB_I-2816063020_TS-UNDOTBS1_FNO-4_0avs2fem
        Tag: TAG20210411T230806
RMAN> backup datafile 4,5 format '/u01/app/oracle/rmanbak/df_%d_%U';------备份类型为备份集
Starting backup at 11-APR-21
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=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/product/19coradatahr.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/rmanbak/df_ORADB_0cvs2fj3_1_1 tag=TAG20210411T231027 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-04 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN>
3、备份表空间
RMAN> backup tablespace users  format '/u01/app/oracle/rmanbak/tb_%d_%U';
Starting backup at 11-APR-21
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=00007 name=/u01/app/oracle/oradata/ORADB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/rmanbak/tb_ORADB_08vs2fbf_1_1 tag=TAG20210411T230623 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-02 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN> backup tablespace temp;------零时表空间不需要备份
Starting backup at 11-APR-21
using channel ORA_DISK_1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 04/11/2021 23:11:22
RMAN-20202: Tablespace not found in the recovery catalog
RMAN-06019: could not translate tablespace name "TEMP"
RMAN>
4、备份控制文件
RMAN> configure controlfile autobackup on;------自动备份控制文件置为on状态,将自动备份控制文件和参数文件
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
RMAN> backup current controlfile;------单独备份控制文件及参数文件
Starting backup at 11-APR-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/0evs2fqn_1_1 tag=TAG20210411T231431 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-05 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN> backup datafile 4 include current controlfile;------备份数据文件时包含控制文件
Starting backup at 11-APR-21
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=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/0gvs2frf_1_1 tag=TAG20210411T231455 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/0hvs2fri_1_1 tag=TAG20210411T231455 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-06 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN> backup spfile format '/u01/app/oracle/rmanbak/sp_%d_%U';------单独备份SPFile
Starting backup at 11-APR-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/rmanbak/sp_ORADB_0jvs2fv6_1_1 tag=TAG20210411T231654 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-07 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN> backup copies 2 device type disk spfile;------
Starting backup at 11-APR-21
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21 with 2 copies and tag TAG20210411T231716
piece handle=/u01/app/oracle/product/19c/dbs/0lvs2fvs_1_1 comment=NONE
piece handle=/u01/app/oracle/product/19c/dbs/0lvs2fvs_1_2 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-08 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN>

注:在备份system01.dbf或system表空间时将会自动备份控制文件和参数文件,即使自动备份控制文件参数为off

5、备份归档日志文件

备份归档日志时仅仅备份归档过的数据文件(不备份联机重做日志文件)

备份归档日志时总是对归档日志做完整备份

RMAN对归档日志备份前会自动做一次日志切换,且从一组归档日志中备份未损坏的归档日志

RMAN会自动判断哪些归档日志需要进行备份

归档日志的备份集不能包含其它类型的文件

RMAN>  backup
2> format '/u01/app/oracle/rmanbak/lf_%d_%U'
3> archivelog all delete input;------delete input删除所有已经备份过的归档日志
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
RMAN> backup archivelog all delete input format '/u01/app/oracle/rmanbak/lf_%d_%U';------此种写法实现了上述相同的功能
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
RMAN> backup archivelog sequence between 50 and 120 thread 1 delete input;------
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
RMAN> backup archivelog from time "sysdate-15" until time "sysdate-7";-------
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
RMAN> backup format'/u01/app/oracle/rmanbak/lf_%d_%U' archivelog from sequence =80 delete input;------
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
------执行下面的命令,并观察备份列出的信息,可以看到使用plus archivelog时使用了上面描述的步骤来进行备份
RMAN> backup database plus archivelog format'/u01/app/oracle/rmanbak/lg_%d_%U'delete input;
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
Starting backup at 11-APR-21
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=00002 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT01.DBF
input datafile file number=00003 name=/u01/app/oracle/oradata/ORADB/sysaux01.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/ORADB/system01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/ORADB/undotbs01.dbf
input datafile file number=00008 name=/u01/app/oracle/oradata/ORADB/ORA_TEST_DAT03.DBF
input datafile file number=00005 name=/u01/app/oracle/product/19coradatahr.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/ORADB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 11-APR-21
channel ORA_DISK_1: finished piece 1 at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/0nvs2goa_1_1 tag=TAG20210411T233018 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
Finished backup at 11-APR-21
Starting backup at 11-APR-21
using channel ORA_DISK_1
specification does not match any archived log in the repository
backup cancelled because there are no files to backup
Finished backup at 11-APR-21
Starting Control File and SPFILE Autobackup at 11-APR-21
piece handle=/u01/app/oracle/product/19c/dbs/c-2816063020-20210411-09 comment=NONE
Finished Control File and SPFILE Autobackup at 11-APR-21
RMAN>

使用plus archivelog时备份数据库完成的动作(backup database plus archivelog)
1.首先执行alter system archive log current命令(对当前日志归档)
2.执行backup archivelog all命令(对所有归档日志进行备份)
3.执行backup database命令中指定的数据文件、表空间等
4.再次执行alter system archive log current
5.备份在备份操作期间产生的新的归档日志

三、总结

数据文件的备份集对于未使用的块可以执行增量备份,可以跳过未使用过的数据块来进行压缩备份
对于控制文件、归档日志文件、spfile文件则是简单的拷贝,并对其进行打包压缩而已

四、RMAN异机恢复

恢复前准备

恢复首先配置跟源库相同的Oracle环境

测试环境待恢复数据库的ORACLE_SID为orcl

查询源库ORCL的DBID并记录

select name,dbid from v$database;

[oracle@localhost ~]$ sqlplus / as sysdba------以sysdba身份进入sqlplus
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Apr 14 16:29:22 2021
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> select name,dbid from v$database;------执行查询DBID语句
NAME                              DBID
--------------------------- ----------
ORCL                        1597556564------记录这个需要恢复的库的DBID
SQL>
开始恢复
[oracle@localhost ~]$ export ORACLE_SID=orcl------设置ORACLE_SID为即将恢复的数据库的SID
[oracle@localhost ~]$ rman target /------启动rman从当前ORACLE_SID
Recovery Manager: Release 19.0.0.0.0 - Production on Wed Apr 14 15:54:58 2021
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/19c/db_1/dbs/initorcl.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             780140544 bytes
Redo Buffers                   7868416 bytes
RMAN> set dbid=1597556564;------设置DBID为源库的DBID
executing command: SET DBID
RMAN> restore spfile to pfile '/u01/app/oracle/product/19c/db_1/dbs/spfile_orcl.ora' from '/rmanbak/orcl/spfile_bak/spf_4_1';------恢复pfile文件 从备份的spfile文件
Starting restore at 14-APR-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=11 device type=DISK
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /rmanbak/orcl/spfile_bak/spf_4_1
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 14-APR-21
RMAN> shutdown immediate;------正常关闭immediate
Oracle instance shut down
RMAN> startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/spfile_orcl.ora';
------启动数据库到nomount状态 使用刚刚恢复出来的pfile文件
'此处启动命令可能会报错,最下边给出解决方案'
Oracle instance started
Total System Global Area    2466249672 bytes
Fixed Size                     8899528 bytes
Variable Size                536870912 bytes
Database Buffers            1912602624 bytes
Redo Buffers                   7876608 bytes
RMAN> restore controlfile from '/rmanbak/orcl/controlfile_bak/cntrl_3_1';
------执行恢复控制文件 从备份的控制文件
Starting restore at 14-APR-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=261 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/ORCL/controlfile/o1_mf_j7bmpnh4_.ctl
output file name=/u01/app/oracle/fast_recovery_area/ORCL/controlfile/o1_mf_j7bmpnjz_.ctl
Finished restore at 14-APR-21
RMAN> alter database mount;------修改数据库为mount模式
released channel: ORA_DISK_1
Statement processed
RMAN> crosscheck backup;------检查数据库有效性
Starting implicit crosscheck backup at 14-APR-21
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=261 device type=DISK
Crosschecked 2 objects
Finished implicit crosscheck backup at 14-APR-21
Starting implicit crosscheck copy at 14-APR-21
using channel ORA_DISK_1
Finished implicit crosscheck copy at 14-APR-21
searching for all files in the recovery area
cataloging files...
no files cataloged
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/database_bak/db_ORCL_02vs920f_1_1 RECID=1 STAMP=1069844495
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/database_bak/db_ORCL_01vs920f_1_1 RECID=2 STAMP=1069844495
Crosschecked 2 objects
RMAN> catalog start with '/rmanbak';------将备份的目录导入到控制文件中
searching for all files that match the pattern /rmanbak
List of Files Unknown to the Database
=====================================
File Name: /rmanbak/orcl.tar.gz
File Name: /rmanbak/orcl/controlfile_bak/cntrl_3_1
File Name: /rmanbak/orcl/log/backupall_20210414103821.log
File Name: /rmanbak/orcl/log/backupall_20210414104042.log
File Name: /rmanbak/orcl/log/backupall_20210414110132.log
File Name: /rmanbak/orcl/spfile_bak/spf_4_1
Do you really want to catalog the above files (enter YES or NO)? yes------输入yes确认
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /rmanbak/orcl/controlfile_bak/cntrl_3_1
File Name: /rmanbak/orcl/spfile_bak/spf_4_1
List of Files Which Were Not Cataloged
=======================================
File Name: /rmanbak/orcl.tar.gz
  RMAN-07517: Reason: The file header is corrupted
File Name: /rmanbak/orcl/log/backupall_20210414103821.log
  RMAN-07517: Reason: The file header is corrupted
File Name: /rmanbak/orcl/log/backupall_20210414104042.log
  RMAN-07517: Reason: The file header is corrupted
File Name: /rmanbak/orcl/log/backupall_20210414110132.log
  RMAN-07517: Reason: The file header is corrupted
RMAN> crosscheck backup;------再次检查数据库有效性
using channel ORA_DISK_1
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/database_bak/db_ORCL_02vs920f_1_1 RECID=1 STAMP=1069844495
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/database_bak/db_ORCL_01vs920f_1_1 RECID=2 STAMP=1069844495
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/controlfile_bak/cntrl_3_1 RECID=3 STAMP=1069862926
crosschecked backup piece: found to be 'AVAILABLE'
backup piece handle=/rmanbak/orcl/spfile_bak/spf_4_1 RECID=4 STAMP=1069862926
Crosschecked 4 objects
RMAN> restore database preview summary;------预览数据库恢复详细信息
Starting restore at 14-APR-21
using channel ORA_DISK_1
List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
2       B  F  A DISK        14-APR-21       1       1       YES        TAG20210414T110135
1       B  F  A DISK        14-APR-21       1       1       YES        TAG20210414T110135

archived logs generated after SCN 2243398 not found in repository
recovery will be done up to SCN 2243398
Media recovery start SCN is 2243398
Recovery must be done beyond SCN 2243398 to clear datafile fuzziness
Finished restore at 14-APR-21
RMAN> restore database;------执行数据库恢复 重新存放数据库
Starting restore at 14-APR-21
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 00003 to /u01/app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_j7bmnbjn_.dbf
channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_j7bmo4rx_.dbf
channel ORA_DISK_1: reading from backup piece /rmanbak/orcl/database_bak/db_ORCL_02vs920f_1_1
channel ORA_DISK_1: piece handle=/rmanbak/orcl/database_bak/db_ORCL_02vs920f_1_1 tag=TAG20210414T110135
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:25
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/datafile/o1_mf_system_j7bmlmbb_.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_j7bmo3o8_.dbf
channel ORA_DISK_1: reading from backup piece /rmanbak/orcl/database_bak/db_ORCL_01vs920f_1_1
channel ORA_DISK_1: piece handle=/rmanbak/orcl/database_bak/db_ORCL_01vs920f_1_1 tag=TAG20210414T110135
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:55
Finished restore at 14-APR-21
RMAN> recover database;------执行数据库恢复 恢复数据库、
'该条恢复命令也许会报错。就跳过执行下一条'
Starting recover at 14-APR-21
using channel ORA_DISK_1
starting media recovery
unable to find archived log
archived log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/14/2021 16:12:13
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 7 and starting SCN of 2243398
RMAN> recover database until scn 2243398;------执行数据库恢复 上条不成功执行该条恢复语句
Starting recover at 14-APR-21
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-APR-21
RMAN> exit------恢复完成 退出
Recovery Manager complete.
[oracle@localhost ~]$ sqlplus / as sysdba------进入sqlplus 以sysdba身份
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Apr 14 16:14:56 2021
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> alter database open resetlogs;------用open resetlogs 打开数据库
Database altered.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
[oracle@localhost ~]$ sqlplus------执行sqlplus命令
SQL*Plus: Release 19.0.0.0.0 - Production on Wed Apr 14 16:17:06 2021
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle.  All rights reserved.
Enter user-name: owner------使用源库中创建的用户登录
Enter password:
Last Successful login time: Wed Apr 14 2021 10:35:23 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL> select table_name from user_tables;------查询当前用户下的所有表
TABLE_NAME
--------------------------------------------------------------------------------
USERSINFO
USERSID
SQL> select * from usersinfo;------验证表中的数据
   USER_ID SEX              AGE
---------- --------- ----------
     10001 男                21
     10002 女                18
SQL> select * from usersid;------验证表中的数据
   USER_ID NAME
---------- ------------------------------
     10002 李四
     10001 张三
SQL>
恢复过程中出现过的问题

执行startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/spfile_orcl.ora';命令的时候也许会报错

RMAN> startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/spfile_orcl.ora';
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 04/14/2021 16:02:17
RMAN-04014: startup failed: ORA-01261: Parameter db_create_file_dest destination string cannot be translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory
RMAN> startup nomount pfile='/u01/app/oracle/product/19c/db_1/dbs/spfile_orcl.ora';
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 04/14/2021 16:03:20
RMAN-04014: startup failed: ORA-01261: Parameter db_recovery_file_dest destination string cannot be translated
ORA-01262: Stat failed on a file destination directory
Linux-x86_64 Error: 2: No such file or directory

报错中告知找不到参数(db_create_file_dest、db_recovery_file_dest)所指定的文件或目录,检查恢复的pfile文件中该参数指定的位置应该是不存在的,创建上目录再执行startup nomount pfile="" 就没问题了

0

评论 (0)

取消