Complete Database Recovery

本文为数据文件缺失而进行的全库或表空间级完全恢复,未涉及控制文件及SPFILE恢复

Performing Complete Recovery of the Whole Database

在整库恢复后会依据控制文件记录重建原来配置的临时表空间,但可能会无法创建成功

After restore and recovery of a whole database, when the database is open, missing temporary tablespaces that were recorded in the control file are re-created with their previous creation size, AUTOEXTEND, and MAXSIZE attributes.

If the temp files were created as Oracle-managed files, then they are re-created in the current DB_CREATE_FILE_DEST location. Otherwise, they are re-created at their previous locations.

If a temp file exists at the location recorded in the RMAN repository but has an invalid header, then RMAN does not re-create the temp file. If RMAN cannot re-create the file due to an I/O error or some other cause, then the error is reported in the alert log and the database open operation continues.

To restore and recover the whole database:

  1. Start RMAN and connect to a target database

RMAN displays the database status when it connects: not started, not mounted, not open (when the database is mounted but not open), or none (when the database is open).

  1. If the database is not mounted, then mount but do not open the database.

STARTUP MOUNT;

  1. Restore and recover the database. Do one of the following:

If you are restoring all data files to their original locations:

RMAN> RESTORE DATABASE;

RMAN> RECOVER DATABASE;

If you manually allocate channels:

RUN { ALLOCATE CHANNEL c1 DEVICE TYPE sbt;

 RESTORE DATABASE;

 RECOVER DATABASE;}

If you are restoring some data files to new locations:

RUN{ SET NEWNAME FOR DATAFILE 2 TO '/disk2/df2.dbf';

  SET NEWNAME FOR DATAFILE 3 TO '/disk2/df3.dbf';

  SET NEWNAME FOR DATAFILE 4 TO '/disk2/df4.dbf';

  RESTORE DATABASE;

  SWITCH DATAFILE ALL;

  RECOVER DATABASE;}

  1. Examine the output to see if media recovery was successful. If so, open the database.

ALTER DATABASE OPEN;

Performing Complete Recovery of a Tablespace

非系统表空间要在MOUNT或OPEN下进行,系统表空间只能在MOUNT下进行。另外数据文件的恢复类似表空间

To restore and recover a tablespace:

  1. Start RMAN and connect to a target database
  2. If the database is open, then take the tablespace requiring recovery offline.

ALTER TABLESPACE users OFFLINE IMMEDIATE;

  1. Restore and recover the tablespace. Do one of the following:

If you are restoring data files to their original locations:

RMAN> RESTORE TABLESPACE users;

RMAN> RECOVER TABLESPACE users;

If you are restoring some data files to new locations:

RUN{

  SET NEWNAME FOR DATAFILE '/disk1/oracle/dbs/users01.f' TO '/disk2/users01.f';

  SET NEWNAME FOR DATAFILE '/disk1/oracle/dbs/users02.f' TO '/disk2/users02.f';

  SET NEWNAME FOR DATAFILE '/disk1/oracle/dbs/users03.f' TO '/disk2/users03.f';

  RESTORE TABLESPACE users;

  SWITCH DATAFILE ALL;   # update control file with new file names

  RECOVER TABLESPACE users;

}

  1. Examine the output to see if recovery was successful. If so, bring the recovered tablespace back online.

ALTER TABLESPACE users ONLINE;

Performing Complete Recovery After Switching to a Copy

如果有镜像备份可以不进行restore直接switch使用

If you have image copies of the inaccessible data files in the fast recovery area, then you can use the SWITCH DATAFILE ... TO COPY command to point the control file at the data file copy and then use RECOVER to recover lost changes.

You can also use the SWITCH DATABASE TO COPY command to point the control file at a copy of the whole database. Because you do not need to restore backups, this recovery technique takes less time than traditional restore and recovery.

  1. Switching to a Data File Copy

To switch to a data file copy and perform recovery:

  1. Start RMAN and connect to a target database
  2. If the database is open, then take the tablespace requiring recovery offline.

ALTER DATABASE DATAFILE 4 OFFLINE;

  1. Switch the offline data file to the latest copy.

SWITCH DATAFILE 4 TO COPY;

  1. Recover the data file with the RECOVER DATAFILE command.

RECOVER DATAFILE 4;

  1. Examine the output to see if recovery was successful. If so, bring the recovered data file back online.

ALTER DATABASE DATAFILE 4 ONLINE;

  1. Switching to a Database Copy

To switch to a database copy and perform recovery:

  1. Start RMAN and connect to a target database
  2. Mount the database.
  3. Switch the database to the latest copy.

SWITCH DATABASE TO COPY;

  1. Recover the database with the RECOVER DATABASE command.

RECOVER DATABASE;

  1. Examine the output to see if recovery was successful. If so, open the database.

ALTER DATABASE OPEN;

Performing Complete Recovery of CDBs

You can back up and recover a whole multitenant container database (CDB)root only, or one or more pluggable databases (PDBs).

  1. Performing Complete Recovery of a Whole CDB

To recover a whole CDB:

When you recover a whole CDB, you recover the root and all PDBs in a single operation.

  1. Connect to the root as a common user with the SYSDBA or SYSBACKUP privilege
  2. If the database is not mounted, then mount but do not open the database.

STARTUP MOUNT;

  1. Restore and recover the database. Do one of the following:

If you are restoring all data files to their original locations:

RESTORE DATABASE;

RECOVER DATABASE;

If you manually allocate channels:

RUN{

  ALLOCATE CHANNEL c1 DEVICE TYPE sbt;

  RESTORE DATABASE;

  RECOVER DATABASE;}

If you are restoring some data files to new locations:

RUN{  

  SET NEWNAME FOR DATAFILE 2 TO '/disk2/df2.dbf';

  SET NEWNAME FOR DATAFILE 3 TO '/disk2/df3.dbf';

  SET NEWNAME FOR DATAFILE 4 TO '/disk2/df4.dbf';

  RESTORE DATABASE;

  SWITCH DATAFILE ALL;

  RECOVER DATABASE;}

  1. Examine the output to see if media recovery was successful. If so, open the database.

ALTER DATABASE OPEN;

  1. Performing Complete Recovery of the Root

You might consider recovering only the root if a data corruption or user error occurs that affects only the root. However, Oracle strongly recommends that you recover all PDBs after recovering the root to prevent metadata inconsistencies among the root and the PDBs. In this case, it might be preferable to perform a complete recovery of the whole CDB.

To recover the root:

  1. Start RMAN and connect to the root as a common user with the SYSDBA or SYSBACKUP privilege.
  2. Place the CDB in mounted mode.

SHUTDOWN IMMEDIATE

STARTUP MOUNT

  1. Restore and recover the root with the following commands:

RESTORE DATABASE ROOT;

RECOVER DATABASE ROOT;

  1. (Strongly recommended) Recover all PDBs, including the CDB seed.

Issue the RESTORE PLUGGABLE DATABASE and RECOVER PLUGGABLE DATABASE commands.

RESTORE PLUGGABLE DATABASE 'PDB$SEED', sales, hr;

RECOVER PLUGGABLE DATABASE 'PDB$SEED', sales, hr;

  1. Open the CDB and all PDBs.

ALTER DATABASE OPEN;

ALTER PLUGGABLE DATABASE ALL OPEN;

  1. Performing Complete Recovery of PDBs with RMAN

There are two approaches to recovering a PDB with RMAN:

  1. Connect to the root and then use the RESTORE PLUGGABLE DATABASE and RECOVER PLUGGABLE DATABASE commands. This approach enables you to recover multiple PDBs with a single command.
  2. Connect to the PDB and use the RESTORE DATABASE and RECOVER DATABASE commands. This approach recovers only a single PDB and enables you to use the same commands used for recovering non-CDB databases.

To recover one or more PDBs while connected to the root:

  1. Start RMAN and connect to the root as a common user with the SYSDBA or SYSBACKUP privilege.
  2. Close the PDBs that you want to recover.

ALTER PLUGGABLE DATABASE sales, hr CLOSE;

  1. If any data files are missing, an error occurs and you cannot close a PDB. You must then connect to the PDB to which the missing data file belongs, take the missing data file offline, and then close the PDB.

ALTER PLUGGABLE DATABASE DATAFILE 12 OFFLINE;

Note: If the data files that store the SYSTEM tablespace of a PDB are missing, then follow the recovery steps described in Performing Complete Recovery of Tablespaces or Data Files in a PDB with RMAN.

  1. Issue the RESTORE PLUGGABLE DATABASE and RECOVER PLUGGABLE DATABASE commands.

RESTORE PLUGGABLE DATABASE 'pdb$seed', sales, hr;

RECOVER PLUGGABLE DATABASE 'pdb$seed', sales, hr;

  1. If any data files were taken offline in Step 2, make these data files online.

Connect to the PDB to which the missing data file belongs and then make the data file online. The following command makes the data file 12 online:

ALTER DATABASE DATAFILE 12 ONLINE;

  1. Examine the output to see if media recovery was successful. If so, open the PDBs.

ALTER PLUGGABLE DATABASE sales, hr OPEN;

To connect to and recover one PDB:

  1. Start RMAN and connect to the PDB as a local user with SYSDBA system privilege.
  2. Close the PDB.

ALTER PLUGGABLE DATABASE CLOSE;

  1. If any data files are missing, an error occurs and you cannot close the PDB. You must take the missing data file offline and then close the PDB.

ALTER DATABASE DATAFILE 12 OFFLINE;

Note: If the data files that store the SYSTEM tablespace of a PDB are missing, then follow the recovery steps described in Performing Complete Recovery of Tablespaces or Data Files in a PDB with RMAN.

  1. Issue the RESTORE DATABASE and RECOVER DATABASE commands.

RESTORE DATABASE;

RECOVER DATABASE;

  1. If any data files were taken offline in Step 2, make these data files online.

ALTER DATABASE DATAFILE 12 ONLINE;

  1. Open the PDB.

ALTER PLUGGABLE DATABASE OPEN;

  1. Performing Complete Recovery of Tablespaces or Data Files in a PDB with RMAN

Because tablespaces in different PDBs can have the same name, to eliminate ambiguity you must connect directly to a PDB to recover one or more of its tablespaces. In contrast, because data file numbers and paths are unique across the CDB, you can connect to either the root or a PDB to recover PDB data files.

To restore and recover a non-SYSTEM tablespace in a PDB:

  1. Start RMAN and connect to a target database
  2. If the database is open, then take the tablespace requiring recovery offline.

ALTER TABLESPACE users OFFLINE IMMEDIATE;

  1. Restore and recover the tablespace. Do one of the following:

RMAN> RESTORE TABLESPACE users;

RMAN> RECOVER TABLESPACE users;

  1. Examine the output to see if recovery was successful. If so, bring the recovered tablespace back online.

ALTER TABLESPACE users ONLINE;

To restore and recover the SYSTEM tablespace in a PDB:

  1. Start RMAN and connect to the root as a common user with the SYSDBA or SYSBACKUP privilege
  2. Shut down the CDB and restart it in mount mode.

SHUTDOWN IMMEDIATE;

STARTUP MOUNT;

  1. Restore and recover the data files that store the SYSTEM tablespace of the affected PDB.

RESTORE DATAFILE 2,3;

RECOVER DATAFILE 2,3;

  1. Open all the PDBs in the CDB.

ALTER PLUGGABLE DATABASE ALL OPEN READ WRITE;

To recover non-SYSTEM data files in a PDB:

  1. Do one of the following:

Start RMAN and connect to the root as a common user with the SYSDBA or SYSBACKUP privilege

Start RMAN and connect to the PDB as a local user with the SYSDBA privilege

  1. Issue the RESTORE DATAFILE and RECOVER DATAFILE commands.

RESTORE DATAFILE 10, 13;

RECOVER DATAFILE 10, 13;

  1. Performing Complete Recovering of CDBs After Switching to a Copy

To switch a data file in a CDB, connect to the root and use the same steps that you would use for a non-CDB

To switch a data file in a PDB, use one of the following techniques:

  1. Connect to the root and use the SWITCH ... PLUGGABLE DATABASE or SWITCH DATAFILE command. This enables you to switch the data files for one or more PDBs.
  2. Connect to the PDB and use the SWITCH DATABASE or SWITCH DATAFILE command to switch data files in that PDB.

Performing Complete Recovery of Application Containers

1. Performing Complete Recovery of the Application Root

Use one of the following approaches to perform complete recovery of the application root:

  1. Connect to the application root and use the RESTORE DATABASE and RECOVER DATABASE commands
  2. Connect to the CDB root and use the RESTORE PLUGGABLE DATABASE and RECOVER PLUGGABLE DATABASE commands

To connect to and recover the application root:

  1. Start RMAN and connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.
  2. Close the application container whose application root needs recovery.

ALTER DATABASE CLOSE;

  1. Restore and recover the application root using the following commands:

RESTORE DATABASE ROOT;

RECOVER DATABASE ROOT;

  1. Open the application root.

ALTER DATABASE OPEN;

To recover the application root when connected to the root in a CDB

  1. Start RMAN and connect to the CDB root as a common user with the SYSDBA or SYSBACKUP privilege.
  2. Close the application container that must be recovered.

ALTER PLUGGABLE DATABASE hr_appcont CLOSE;

  1. Restore and recover the application root.

RESTORE PLUGGABLE DATABASE hr_appcont;

RECOVER PLUGGABLE DATABASE hr_appcont;

  1. Open the application root.

ALTER PLUGGABLE DATABASE hr_appcont OPEN;

2. Performing Complete Recovery of the Application Root and Application PDBs

To perform complete recovery of the application root and all its application PDBs:

  1. Start RMAN and connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.
  2. Close the application container that must be recovered.

ALTER DATABASE CLOSE;

  1. Restore and recover the application container (application root and all application PDBs) using the following commands.

RESTORE DATABASE;

RECOVER DATABASE;

  1. Open the application root and all the application PDBs.

ALTER DATABASE OPEN;

ALTER PLUGGABLE DATABASE ALL OPEN;

  1. Performing Complete Recovery of Application PDBs

To perform complete recovery of an application PDB:

  1. Start RMAN and establish one of the following types of connections:

Connect to the application root as an application common user with the SYSDBA or SYSBACKUP privilege.

Connect to the CDB root as a common user with the SYSDBA or SYSBACKUP privilege.

  1. Close the application PDB for which complete recovery is required.

ALTER PLUGGABLE DATABASE hr_appcont_pdb1 CLOSE;

  1. Restore and recover the application PDB.

RESTORE PLUGGABLE DATABASE hr_appcont_pdb1;

RECOVER PLUGGABLE DATABASE hr_appcont_pdb1;

  1. Open the application PDB.

ALTER PLUGGABLE DATABASE hr_appcont_pdb1 OPEN;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值