目录
RMAN備份
在CDB下进入RMAN进行备份
备份集
備份整個 CDB數據庫
備份的是cdb$root和所有的pdb和pdbseed
1.首先指定要備份的CDB的sid
export ORACLE_SID=CDB1
2.然后将数据库设为归档模式
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 4294963960 bytes
Fixed Size 9143032 bytes
Variable Size 973078528 bytes
Database Buffers 3305111552 bytes
Redo Buffers 7630848 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/oradata
Oldest online log sequence 15
Next log sequence to archive 17
Current log sequence 17
[oracle@oracle19c oradata]$ rman target /
Recovery Manager: Release 19.0.0.0.0 - Production on Sun Sep 10 18:58:42 2023
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.
connected to target database: CDB (DBID=2260625579, not open)
如果需要經常備份的話我們應該指定一個固定的備份目錄。
RMAN> backup database plus archivelog;--------备份 所有的数据文件,控制文件,spfile文件和归档日志文件
数据文件和归档日志文件都备份到了同一个地方:
以下模拟数据文件丢失,然后用刚才的备份恢复数据库:
1.删除一个pdbusers.dbf表空间文件,打开pdb1的时候报错
RMAN> select status from v$instance;
STATUS
------------
OPEN
RMAN> shutdown immediate;
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount--------需要将数据库启动到mount状态下恢复
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 838858864 bytes
Fixed Size 9140336 bytes
Variable Size 557842432 bytes
Database Buffers 268435456 bytes
Redo Buffers 3440640 bytes
RMAN> restore database;
Starting restore at 01-JAN-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=427 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=428 device type=DISK
skipping datafile 5; already restored to file /u01/app/oracle/oradata/CDB/pdbseed/system01.dbf
skipping datafile 8; already restored to file /u01/app/oracle/oradata/CDB/pdbseed/undotbs01.dbf
skipping datafile 6; already restored to file /u01/app/oracle/oradata/CDB/p