【RMAN】RMAN备份
1、RMAN只备份CDB
只备份CDB数据库需要具有SYSDBA或SYSBACKUP权限用户连接到CDB的root环境下,执行backup database root命令即可完成对CDB的备份,方法如下:
RMAN> backup database root; Starting backup at 08-JUL-21 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=72 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=00001 name=/u01/app/oracle/oradata/T1/system01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/T1/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/T1/undotbs01.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/T1/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708.bak tag=TAG20210708T150300 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 08-JUL-21 Starting Control File and SPFILE Autobackup at 08-JUL-21 piece handle=/u01/app/backup/backupset/c-2888150031-20210708-04.ctl comment=NONE Finished Control File and SPFILE Autobackup at 08-JUL-21
查看备份
RMAN> list backupset;
RMAN> list backupset; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 7 Full 1.14G DISK 00:00:02 08-JUL-21 BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20210708T150300 Piece Name: /u01/app/backup/backupset/T1_20210708.bak List of Datafiles in backup set 7 File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 1 Full 2147117 08-JUL-21 NO /u01/app/oracle/oradata/T1/system01.dbf 3 Full 2147117 08-JUL-21 NO /u01/app/oracle/oradata/T1/sysaux01.dbf 4 Full 2147117 08-JUL-21 NO /u01/app/oracle/oradata/T1/undotbs01.dbf 7 Full 2147117 08-JUL-21 NO /u01/app/oracle/oradata/T1/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 8 Full 17.95M DISK 00:00:00 08-JUL-21 BP Key: 8 Status: AVAILABLE Compressed: NO Tag: TAG20210708T150303 Piece Name: /u01/app/backup/backupset/c-2888150031-20210708-04.ctl SPFILE Included: Modification time: 08-JUL-21 SPFILE db_unique_name: T1 Control File Included: Ckp SCN: 2147126 Ckp time: 08-JUL-21
2、rman备份cdb及所有pdb
备份整个CDB数据库及其下面的所有PDB类似于非CDB数据库方法相同,使用具有SYSDBA或SYSBACKUP权限用户连接到CDB的root环境下面,然后执行backup database命令即可完成整个CDB的备份,方法如下:
RMAN> backup database; Starting backup at 08-JUL-21 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=72 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=00001 name=/u01/app/oracle/oradata/T1/system01.dbf input datafile file number=00003 name=/u01/app/oracle/oradata/T1/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/T1/undotbs01.dbf input datafile file number=00007 name=/u01/app/oracle/oradata/T1/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708_1077376375.bak tag=TAG20210708T151255 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00010 name=/u01/app/oracle/oradata/T1/pdb/sysaux01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/T1/pdb/system01.dbf input datafile file number=00011 name=/u01/app/oracle/oradata/T1/pdb/undotbs01.dbf input datafile file number=00012 name=/u01/app/oracle/oradata/T1/pdb/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708_1077376382.bak tag=TAG20210708T151255 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/app/oracle/oradata/T1/pdbseed/sysaux01.dbf input datafile file number=00005 name=/u01/app/oracle/oradata/T1/pdbseed/system01.dbf input datafile file number=00008 name=/u01/app/oracle/oradata/T1/pdbseed/undotbs01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708_1077376398.bak tag=TAG20210708T151255 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 Finished backup at 08-JUL-21 Starting Control File and SPFILE Autobackup at 08-JUL-21 piece handle=/u01/app/backup/backupset/c-2888150031-20210708-05.ctl comment=NONE Finished Control File and SPFILE Autobackup at 08-JUL-21
查看备份
RMAN> list backupset;
RMAN> list backup; List of Backup Sets =================== BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 9 Full 1.14G DISK 00:00:04 08-JUL-21 BP Key: 9 Status: AVAILABLE Compressed: NO Tag: TAG20210708T151255 Piece Name: /u01/app/backup/backupset/T1_20210708_1077376375.bak List of Datafiles in backup set 9 File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 1 Full 2163200 08-JUL-21 NO /u01/app/oracle/oradata/T1/system01.dbf 3 Full 2163200 08-JUL-21 NO /u01/app/oracle/oradata/T1/sysaux01.dbf 4 Full 2163200 08-JUL-21 NO /u01/app/oracle/oradata/T1/undotbs01.dbf 7 Full 2163200 08-JUL-21 NO /u01/app/oracle/oradata/T1/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 10 Full 496.66M DISK 00:00:09 08-JUL-21 BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20210708T151255 Piece Name: /u01/app/backup/backupset/T1_20210708_1077376382.bak List of Datafiles in backup set 10 Container ID: 3, PDB Name: PDB File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 9 Full 2164523 08-JUL-21 2165833 NO /u01/app/oracle/oradata/T1/pdb/system01.dbf 10 Full 2164523 08-JUL-21 2166235 NO /u01/app/oracle/oradata/T1/pdb/sysaux01.dbf 11 Full 2164523 08-JUL-21 2165014 NO /u01/app/oracle/oradata/T1/pdb/undotbs01.dbf 12 Full 2164523 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdb/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 11 Full 556.83M DISK 00:00:10 08-JUL-21 BP Key: 11 Status: AVAILABLE Compressed: NO Tag: TAG20210708T151255 Piece Name: /u01/app/backup/backupset/T1_20210708_1077376398.bak List of Datafiles in backup set 11 Container ID: 2, PDB Name: PDB$SEED File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 5 Full 2131222 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdbseed/system01.dbf 6 Full 2131222 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdbseed/sysaux01.dbf 8 Full 2131222 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdbseed/undotbs01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 12 Full 17.95M DISK 00:00:01 08-JUL-21 BP Key: 12 Status: AVAILABLE Compressed: NO Tag: TAG20210708T151333 Piece Name: /u01/app/backup/backupset/c-2888150031-20210708-05.ctl SPFILE Included: Modification time: 08-JUL-21 SPFILE db_unique_name: T1 Control File Included: Ckp SCN: 2173421 Ckp time: 08-JUL-21
3、备份单个或多个pdb
- 在CDB根(root)使用BACKUP PLUGGABLE DATABASE命令备份一个或多个PDB数据库。
RMAN> backup pluggable database pdb; Starting backup at 08-JUL-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=00010 name=/u01/app/oracle/oradata/T1/pdb/sysaux01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/T1/pdb/system01.dbf input datafile file number=00011 name=/u01/app/oracle/oradata/T1/pdb/undotbs01.dbf input datafile file number=00012 name=/u01/app/oracle/oradata/T1/pdb/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708_1077376824.bak tag=TAG20210708T152024 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 08-JUL-21 Starting Control File and SPFILE Autobackup at 08-JUL-21 piece handle=/u01/app/backup/backupset/c-2888150031-20210708-06.ctl comment=NONE Finished Control File and SPFILE Autobackup at 08-JUL-21
查看备份
BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 13 Full 521.05M DISK 00:00:02 08-JUL-21 BP Key: 13 Status: AVAILABLE Compressed: NO Tag: TAG20210708T152024 Piece Name: /u01/app/backup/backupset/T1_20210708_1077376824.bak List of Datafiles in backup set 13 Container ID: 3, PDB Name: PDB File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name ---- -- ---- ---------- --------- ----------- ------ ---- 9 Full 2182713 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdb/system01.dbf 10 Full 2182713 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdb/sysaux01.dbf 11 Full 2182713 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdb/undotbs01.dbf 12 Full 2182713 08-JUL-21 NO /u01/app/oracle/oradata/T1/pdb/users01.dbf BS Key Type LV Size Device Type Elapsed Time Completion Time ------- ---- -- ---------- ----------- ------------ --------------- 14 Full 17.95M DISK 00:00:00 08-JUL-21 BP Key: 14 Status: AVAILABLE Compressed: NO Tag: TAG20210708T152027 Piece Name: /u01/app/backup/backupset/c-2888150031-20210708-06.ctl SPFILE Included: Modification time: 08-JUL-21 SPFILE db_unique_name: T1 Control File Included: Ckp SCN: 2182722 Ckp time: 08-JUL-21
- 在PDB中使用BACKUP DATABASE备份当前连接的PDB数据库,前提条件是需要配置好TNSNAMES.ORA文件。
[oracle@T1 network]$ rman target sys/oracle@pdb Recovery Manager: Release 19.0.0.0.0 - Production on Thu Jul 8 15:26:21 2021 Version 19.3.0.0.0 Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved. connected to target database: T1:PDB (DBID=172092073) RMAN> backup database; Starting backup at 08-JUL-21 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=72 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=00010 name=/u01/app/oracle/oradata/T1/pdb/sysaux01.dbf input datafile file number=00009 name=/u01/app/oracle/oradata/T1/pdb/system01.dbf input datafile file number=00011 name=/u01/app/oracle/oradata/T1/pdb/undotbs01.dbf input datafile file number=00012 name=/u01/app/oracle/oradata/T1/pdb/users01.dbf channel ORA_DISK_1: starting piece 1 at 08-JUL-21 channel ORA_DISK_1: finished piece 1 at 08-JUL-21 piece handle=/u01/app/backup/backupset/T1_20210708_1077377200.bak tag=TAG20210708T152639 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03 Finished backup at 08-JUL-21
恢复
1、整体数据库恢复(cdb和所有pdb)
19c数据库加强了RMAN恢复的功能,恢复的方式基本同以前的模式一样,如果是在一个全新的异地进行恢复
操作步骤:
- 首先准备同版本系统和数据库软件,仅安装数据库软件;
- 备份完将所有备份介质传到异地服务器B(如果两台机器是内连网络,可以考虑结合NFS服务从一开始就备份到服务器B上)。
- 通过RMAN命令或者拷贝原始库的控制文件到新库上,修改参数文件、创建数据文件路径等,启动CDB数据库到mount状态,声明恢复目录
- restore还原数据文件
- recover恢复到故障时间点
- 其他调整
2、单个pdb数据库恢复
恢复单个PDB的前提是CDB已经能够正常启动,在CDB启动的情况下在RMAN中采用restore pluggable database pdb名称指定单个PDB数据库进行恢复,如下:
RMAN>restore pluggable database pdb; ... RMAN>recover pluggable database pdb; ... 最后,使用restlogs方式打开数据库 SQL>alter pluggable database pdb pdb resetlogs;
3、恢复pdb数据文件
数据库在open的时候,会对当前的数据的所有数据文件进行检查。如果数据文件出现异常,则从报错中获取数据文件id,到rman下进行还原和恢复后方能正常启动数据库。(还原的前提是你有数据库的rman备份数据,包括:数据文件备份、归档日志备份、还可能用到redo文件)
当CDB在打开的时候,数据库不会检查pdb中的数据文件。
RMAN>restore datafile datafile_id; ... RMAN>recover datafile datafile_id; ... 最后,再次打开数据库 SQL>alter database open;