Oracle CDB PDB的备份与恢复
PDB的备份与恢复:一:备份恢复整个CDB:备份整个多租户容器数据库(CDB)类似于备份非CDB数据库。备份整个CDB时,RMAN会备份根容器以及所有可插拔数据库(PDB)和归档重做日志。备份整个CDB后,可以从CDB备份中恢复整个CDB,或者仅恢复根容器,或者恢复一个或多个PDB。1.连接至根容器[oracle@server1]$ rman target /2.备份整个CDBRMAN>BA
PDB的备份与恢复:
一:备份恢复整个CDB:
-
备份整个多租户容器数据库(CDB)类似于备份非CDB数据库。
-
备份整个CDB时,RMAN会备份根容器以及所有可插拔数据库(PDB)和归档重做日志。
-
备份整个CDB后,可以从CDB备份中恢复整个CDB,或者仅恢复根容器,或者恢复一个或多个PDB。
1.连接至根容器
[oracle@server1]$ rman target /
2.备份整个CDB
RMAN>BACKUP DATABASE;
RMAN>BACKUP DATABASE PLUS ARCHIVELOG; //包含归档
3.利用该备份恢复整个CDB
RMAN>restore database
RMAN>recover database
4.利用该备份仅恢复根容器
RMAN>restore database root
RMAN>recover database root
5.利用该备份恢复一个或多个PDB
RMAN>restore pluggable database pdb1 / pdb1,pdb2
RMAN>recover pluggable database pdb1 / pdb1,pdb2
二:备份恢复根容器:
1.备份
RMAN>backup database root //只备份根容器
2.恢复
startup force mount //启动到mount模式
RMAN>restore database root //恢复根容器
RMAN>recover database root
三:备份恢复整个PDB:
-
连接到根容器,然后使用
BACKUP PLUGGABLE DATABASE PDB_NAME
命令。这种方法使您可以使用单个命令备份多个PDB。当您连接到根并备份PDB时,该备份对根和该特定PDB可见,但对其他PDB不可见。
-
连接到PDB并使用
BACKUP DATABASE
命令。这种方法仅备份单个PDB,并使您能够使用与备份非CDB相同的命令。连接到任何PDB时创建的备份在连接到根容器时可见。
方法1:连接到根容器备份一个或多个PDB:
1.连接至根容器
[oracle@server1 admin]$ rman target /
2.备份
RMAN>BACKUP PLUGGABLE DATABASE pdb1, pdb3;
3.恢复
RMAN>alter pluggable database pdb1 close; //如果该PDB处于read write,需要将其close
RMAN>restore pluggable database pdb1
RMAN>recover pluggable database pdb1
方法2:在连接到PDB时备份一个PDB:
1.连接至指定PDB
[oracle@server1 admin]$ rman target sys/oracle@pdb1 //使用tnsname通过网络连接
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Sep 2 11:11:48 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL:PDB1 (DBID=6001799, not open)
2.备份
RMAN> backup database
3.恢复
RMAN>restore database
RMAN>recover database
四:备份恢复PDB中的指定表空间:
-
备份PDB中指定表空间,只能连接至指定PDB进行备份
-
连接至根容器无法备份PDB的表空间
1.连接至指定PDB
[oracle@server1 admin]$ rman target sys/oracle@pdb1 //使用tnsname通过网络连接
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Sep 2 11:11:48 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL:PDB1 (DBID=6001799, not open)
2.备份
RMAN> backup tablespace users,sysaux;
3.恢复
RMAN> restore tablespace users,sysaux;
RMAN> recover tablespace users,sysaux;
五:备份恢复PDB中的指定数据文件:
-
连接到根容器,则可以使用一个命令从多个PDB中备份数据文件。
-
连接到PDB,则只能备份该PDB中的数据文件。
方法1:连接到根容器备份
1.连接至根容器
[oracle@server1]$ rman target /
2.查看PDB数据文件号 //可以查看到所有的PDB数据文件
RMAN> report schema;
using target database control file instead of recovery catalog
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 800 SYSTEM YES /oracle/app/oradata/orcl/system01.dbf
3 480 SYSAUX NO /oracle/app/oradata/orcl/sysaux01.dbf
4 70 UNDOTBS1 YES /oracle/app/oradata/orcl/undotbs01.dbf
5 250 PDB$SEED:SYSTEM NO /oracle/app/oradata/orcl/pdbseed/system01.dbf
6 330 PDB$SEED:SYSAUX NO /oracle/app/oradata/orcl/pdbseed/sysaux01.dbf
7 5 USERS NO /oracle/app/oradata/orcl/users01.dbf
8 100 PDB$SEED:UNDOTBS1 NO /oracle/app/oradata/orcl/pdbseed/undotbs01.dbf
9 250 PDB1:SYSTEM NO /oracle/app/oradata/orcl/pdb1/system01.dbf
10 350 PDB1:SYSAUX NO /oracle/app/oradata/orcl/pdb1/sysaux01.dbf
11 100 PDB1:UNDOTBS1 NO /oracle/app/oradata/orcl/pdb1/undotbs01.dbf
12 5 PDB1:USERS NO /oracle/app/oradata/orcl/pdb1/users01.dbf
13 250 SALESPDB:SYSTEM YES /oracle/app/oradata/orcl/salespdb/system01.dbf
14 350 SALESPDB:SYSAUX NO /oracle/app/oradata/orcl/salespdb/sysaux01.dbf
15 100 SALESPDB:UNDOTBS1 YES /oracle/app/oradata/orcl/salespdb/undotbs01.dbf
16 5 SALESPDB:USERS NO /oracle/app/oradata/orcl/salespdb/users01.dbf
25 360 PDB3:SYSTEM YES /oracle/app/oradata/orcl/pdb3/system01.dbf
26 350 PDB3:SYSAUX NO /oracle/app/oradata/orcl/pdb3/sysaux01.dbf
27 180 PDB3:UNDOTBS1 YES /oracle/app/oradata/orcl/pdb3/undotbs01.dbf
28 5 PDB3:USERS NO /oracle/app/oradata/orcl/pdb3/users01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 33 TEMP 32767 /oracle/app/oradata/orcl/temp01.dbf
2 64 PDB$SEED:TEMP 32767 /oracle/app/oradata/orcl/pdbseed/temp012020-08-13_15-42-08-254-PM.dbf
3 64 PDB1:TEMP 32767 /oracle/app/oradata/orcl/pdb1/temp01.dbf
4 64 SALESPDB:TEMP 32767 /oracle/app/oradata/orcl/salespdb/temp01.dbf
5 64 PDB3:TEMP 32767 /oracle/app/oradata/orcl/pdb3/temp01.dbf
3.备份
RMAN> BACKUP DATAFILE 11, 12;
4.恢复
RMAN>restore datafile 11,12
方法2: 连接至某个PDB备份
1.连接至某个PDB
[oracle@server1]$ rman target sys/oracle@pdb1 //使用tnsname通过网络连接
Recovery Manager: Release 12.2.0.1.0 - Production on Wed Sep 2 11:11:48 2020
Copyright (c) 1982, 2017, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL:PDB1 (DBID=6001799, not open)
2.查看数据文件号 //查看当前PDB数据文件
RMAN> report schema;
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
9 250 SYSTEM NO /oracle/app/oradata/orcl/pdb1/system01.dbf
10 350 SYSAUX NO /oracle/app/oradata/orcl/pdb1/sysaux01.dbf
11 100 UNDOTBS1 NO /oracle/app/oradata/orcl/pdb1/undotbs01.dbf
12 5 USERS NO /oracle/app/oradata/orcl/pdb1/users01.dbf
3.备份
RMAN> backup datafile 11, 12;
4.恢复
RMAN>restore databfile 11,12
六:CDB与PDB的增量备份
6.1.整个CDB增量备份:
CDB级别的增量备份包含所有PDB发生的变化
0级:
RMAN> backup as backupset incremental level=0 database
1级:
RMAN> backup as backupset incremental level=1 database
1c级:
RMAN> backup as backupset incremental level=1 cumulative database
6.2.根容器增量备份:
仅对根容器进行增量备份
0级:
RMAN> backup as backupset incremental level=0 database root;
1级:
RMAN> backup as backupset incremental level=1 database root;
1c级:
RMAN> backup as backupset incremental level=1 cumulative database root;
6.3.单个或多个PDB增量备份
0级备份:
RMAN> backup as backupset incremental level=0 pluggable database pdb1;
RMAN> backup as backupset incremental level=0 pluggable database pdb1,pdb3;
RMAN> list backup of pluggable database pdb1;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
24 Incr 0 546.22M DISK 00:00:15 02-SEP-20
BP Key: 24 Status: AVAILABLE Compressed: NO Tag: TAG20200902T203447
Piece Name: /oracle/app/fast_recovery_area/orcl/ORCL/ACBE83275D4E2D26E0531F61A8C06B8F/backupset/2020_09_02/o1_mf_nnnd0_TAG20200902T203447_hnz4c84c_.bkp
List of Datafiles in backup set 24
Container ID: 3, PDB Name: PDB1
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
9 0 Incr 1957090 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/system01.dbf
10 0 Incr 1961722 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/sysaux01.dbf
11 0 Incr 1957090 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/undotbs01.dbf
12 0 Incr 1961722 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/users01.dbf
1级差异性备份:
SQL> alter session set container=pdb1;
Session altered.
SQL> create table test as select * from dba_objects;
RMAN> backup as backupset incremental level=1 pluggable database pdb1;
RMAN> backup as backupset incremental level=1 pluggable database pdb1,pdb3;
RMAN> list backup of pluggable database pdb1;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
26 Incr 1 11.82M DISK 00:00:01 02-SEP-20
BP Key: 26 Status: AVAILABLE Compressed: NO Tag: TAG20200902T204108
Piece Name: /oracle/app/fast_recovery_area/orcl/ORCL/ACBE83275D4E2D26E0531F61A8C06B8F/backupset/2020_09_02/o1_mf_nnnd1_TAG20200902T204108_hnz4q4tb_.bkp
List of Datafiles in backup set 26
Container ID: 3, PDB Name: PDB1
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
9 1 Incr 2176329 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/system01.dbf
10 1 Incr 2176329 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/sysaux01.dbf
11 1 Incr 2176329 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/undotbs01.dbf
12 1 Incr 2176329 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/users01.dbf
1级累积性备份
RMAN> backup as backupset incremental level=1 cumulative pluggable database pdb1;
RMAN> backup as backupset incremental level=1 cumulative pluggable database pdb1,pdb3;
RMAN> list backup of pluggable database pdb1;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
28 Incr 1 11.82M DISK 00:00:01 02-SEP-20
BP Key: 28 Status: AVAILABLE Compressed: NO Tag: TAG20200902T204325
Piece Name: /oracle/app/fast_recovery_area/orcl/ORCL/ACBE83275D4E2D26E0531F61A8C06B8F/backupset/2020_09_02/o1_mf_nnnd1_TAG20200902T204325_hnz4vfyp_.bkp
List of Datafiles in backup set 28
Container ID: 3, PDB Name: PDB1
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
9 1 Incr 2176431 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/system01.dbf
10 1 Incr 2176431 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/sysaux01.dbf
11 1 Incr 2176431 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/undotbs01.dbf
12 1 Incr 2176431 02-SEP-20 NO /oracle/app/oradata/orcl/pdb1/users01.dbf
七:查看备份集信息:
1.查看所有PDB以及根容器的备份信息
RMAN>list backup
2.只查看根容器
RMAN> list backup of database root;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7 Full 1.01G DISK 00:00:41 02-SEP-20
BP Key: 7 Status: AVAILABLE Compressed: NO Tag: TAG20200902T093922
Piece Name: /oracle/app/fast_recovery_area/orcl/ORCL/backupset/2020_09_02/o1_mf_nnndf_TAG20200902T093922_hnxxyb91_.bkp
List of Datafiles in backup set 7
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
1 Full 1917772 02-SEP-20 NO /oracle/app/oradata/orcl/system01.dbf
3 Full 1917772 02-SEP-20 NO /oracle/app/oradata/orcl/sysaux01.dbf
4 Full 1917772 02-SEP-20 NO /oracle/app/oradata/orcl/undotbs01.dbf
7 Full 1917772 02-SEP-20 NO /oracle/app/oradata/orcl/users01.dbf
3.查看某个PDB备份集信息
RMAN> list backup of pluggable database salespdb;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10 Full 478.82M DISK 00:00:29 02-SEP-20
BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20200902T093922
Piece Name: /oracle/app/fast_recovery_area/orcl/ORCL/ACBED227AE170CB3E0531F61A8C09640/backupset/2020_09_02/o1_mf_nnndf_TAG20200902T093922_hnxy2j2s_.bkp
List of Datafiles in backup set 10
Container ID: 6, PDB Name: SALESPDB
File LV Type Ckp SCN Ckp Time Abs Fuz SCN Sparse Name
---- -- ---- ---------- --------- ----------- ------ ----
13 Full 1932712 02-SEP-20 NO /oracle/app/oradata/orcl/salespdb/system01.dbf
14 Full 1932712 02-SEP-20 NO /oracle/app/oradata/orcl/salespdb/sysaux01.dbf
15 Full 1932712 02-SEP-20 NO /oracle/app/oradata/orcl/salespdb/undotbs01.dbf
16 Full 1932712 02-SEP-20 NO /oracle/app/oradata/orcl/salespdb/users01.dbf
4.查看某个PDB的指定表空间或数据文件备份
RMAN> list backup of pluggable database salespdb tablespace sysaux;
RMAN> list backup of pluggable database salespdb datafile 14;
更多推荐
所有评论(0)