
Oracle Database 12c Backup and Recovery Survival Guide

Now is the time to play with some backup and recovery scenarios. Due to the limitations of pages in this book, we will cover only a few scenarios. Remember that you have many scenarios available in the chapters of this book.
When executing an active duplication, RMAN automatically copies the server parameter file to the destination host from the source, restarts the auxiliary instance using the server parameter file, copies all necessary database files and archived redo logs over the network to the destination host, and recovers the destination database. Finally, RMAN will open the destination (target) database with the
RESETLOGS
option to be able to create all online redo logs.
The following steps are required:
Create a new virtual machine using Oracle database 12.1.0.1 and Oracle Linux 6.4 (without creating a database). Set up the virtual machine with a proper IP and HOSTNAME.
Follow the Oracle installation guide for Linux (http://docs.oracle.com/cd/E16655_01/install.121/e17720/toc.htm), and prepare this machine for the installation of the Oracle database. When creating the Oracle user, please create it to use the password oracle
.
Clone the newly created virtual machine and give to it a new IP and HOSTNAME. It will be used as the auxiliary server (target).
Create a non-CDB database called (in the Virtual Machine created in step 1) orcl
using DBCA. This will be the source database.
If the source database is open, archiving must be enabled. If the source database is not open, the database does not require instance recovery.
In the auxiliary server, create the same directory structure used by the source database created in step 3. For example:
mkdir /u01/app/oracle/fast_recovery_area
mkdir /u01/app/oracle/fast_recovery_area/orcl
mkdir /u01/app/oracle/admin/orcl/adump
mkdir /u01/app/oracle/oradata/orcl
The steps for the active duplication will be:
In the auxiliary server (target), create a new password file to be used by the cloned database (connected as the OS user Oracle).
$ orapwd file=/u01/app/oracle/product/12.1/db_1/dbs/orapworcl password=oracle entries=10
Add the auxiliary database information to the source database TNSNAMES.ORA
file (located at $ORACLE_HOME/network/admin
). For example:
ORCL_DEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST=172.28.10.62) (PORT = 1521) (CONNECT_DATA) (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
Remember to replace the example IP address used above for the correct IP of your virtual machine (auxiliary server).
Create the LISTENER.ORA
file in the auxiliary server. For example:
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (ORACLE_HOME = /u01/app/oracle/product/12.1/db_1) (SID_NAME = orcl) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 172.28.10.62) (PORT = 1521)) (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC) (KEY = EXTPROC1521)) ) ) ADR_BASE_LISTENER = /u01/app/oracle
Remember to replace the example IP address used above for the correct IP of your virtual machine (auxiliary server)
Add source and auxiliary databases to the auxiliary TNSNAMES.ORA
file. For example:
LISTENER_ORCL = (ADDRESS = (PROTOCOL = TCP) (HOST = 172.28.10.62) (PORT = 1521)) ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 172.29.62.11) (PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) ORCL_DEST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = 172.28.10.62) (PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
Remember to replace example IP addresses by the ones you used on your virtual machines.
Create a basic PFILE
for the auxiliary database. To make it easy, create a PFILE
from SPFILE
in the source database and copy it to the auxiliary database.
Using SQL*Plus, start up the auxiliary database in NOMOUNT
mode; for example:
SQL> STARTUP NOMOUNT
Start the LISTENER
for the auxiliary database; for example:
$ lsnrctl start
In the auxiliary server, start your RMAN session connecting to the source database and the auxiliary database; for example:
$ rman TARGET sys/oracle@orcl auxiliary sys/oracle@orcl_dest
Run the DUPLICATE command to make the magic happen, for example:
RMAN> DUPLICATE DATABASE TO ORCL FROM ACTIVE DATABASE SPFILE NOFILENAMECHECK;
RMAN uses the pull method (using backup sets) by default.
You can also use COMPRESSED BACKUPSET
when performing an active duplication. In this case the DUPLICATE
command would be:
DUPLICATE TARGET DATABASE TO orcl FROM ACTIVE DATABASE PASSWORD FILE USING COMPRESSED BACKUPSET;
By default, when the active duplication is completed, the new database will be open; if you do not want the database to be open, after the duplication, please use the following command:
RMAN> DUPLICATE DATABASE TO ORCL FROM ACTIVE DATABASE SPFILE NOFILENAMECHECK NOOPEN;
If you want to duplicate a PDB, please create a multitenant container database called orcl
with a PDB called pdborcl
using DBCA, and follow all steps in the previous scenario and replace the
DUPLICATE
command with the following one:
RMAN> DUPLICATE TARGET DATABASE TO orcl PLUGGABLE DATABASE pdborcl FROM ACTIVE DATABASE PASSWORD FILE SPFILE NOFILENAMECHECK;
The root and seed database are automatically included in the duplication. The auxiliary instance must have been started with an initialization parameter file that includes the declaration enable_pluggable_database=TRUE
.
Perform the following steps:
Take an RMAN backup of the USERS tablespace:
RMAN> BACKUP TABLESPACE users;
Create a new directory called abc
in the disk group DATA
. Once you create the directory, create an alias called +DATA/abc/users.f
. This alias will point to the ASM datafile in which the USERS
tablespace is stored:
ASMCMD> mkdir +DATA1/abc ASMCMD> mkalias TBSJFV.354.323232323 +DATA1/abc/users.f
Backup the ASM metadata for the DATA
disk group:
ASMCMD> md_backup –g data1
The md_backup
command will produce a restore script named ambr_backup_intermediate_file
in the current directory. You'll need this file to perform the restore operation later.
Drop the disk group DATA to simulate the failure. You can use the dismount force clause to dismount the disk group and then force drop it:
SQL> ALTER DISKGROUP data1 DISMOUNT FORCE; SQL> DROP DISKGROUP data1 FORCE INCLUDING CONTENTS;
Edit the
ambr_backup_intermideate_file
to remove the au_size
entry. Once you make the change and save the restore file, run the md_restore
command to restore the ASM metadata for the dropped disk group:
ASMCMD> md_restore –b ambr_backup_intermediate_file –t full –g data
Once you restore the ASM metadata for the disk group, you must restore the USERS
tablespace that was in the dropped disk group. You can use the backup that you made earlier of the USERS
tablespace for this:
RMAN> RESTORE TABLESPACE users;
We are running this scenario with the assumption that you have a current backup of your database and all archived redo log files since your last backup are available. To recover your SYSTEM
tablespace, please follow these steps:
Connect to RMAN:
$ rman target /
Start your DB in mount mode and restore your SYSTEM
tablespace:
RMAN> STARTUP MOUNT; RMAN> RESTORE TABLESPACE SYSTEM;
Recover and open your DB:
RMAN> RECOVER TABLESPACE SYSTEM; RMAN> ALTER DATABASE OPEN;
If you do not have a current backup of your database and all archive redo log files are unavailable, you should perform a point-in-time recovery of your database and open it using the RESETLOGS
option.
We are running this scenario with the assumption that you have a current image copy of the datafile 7 on the FRA. To recover your datafile 7 from the FRA, perform the following steps:
Create a copy backup of your database.
Let's first put the datafile offline to simulate that we lost the datafile:
SQL> ALTER DATABASE DATAFILE 7 OFFLINE;
Now let's do the trick; we will switch to the copy of the datafile available on our FRA:
$ rman target / RMAN> SWITCH DATAFILE 7 TO COPY; RMAN> RECOVER DATAFILE 7;
All you need to do now is to put the datafile online and you are ready to go, without losing your time waiting for a backup to be retrieved from tape.
RMAN> ALTER DATABASE DATAFILE 7 ONLINE;
Remember to switch from datafile copy in the FRA to disk again; if not, you will have issues again.
$ rman target / RMAN> BACKUP AS COPY DATAFILE 7 FORMAT '/Data/data/test3_tbs_01.dbf'; RMAN> SWITCH DATAFILE 7 TO COPY; RMAN> RECOVER DATAFILE 7; RMAN> ALTER DATABASE DATAFILE 7 ONLINE;
Change the font size
Change margin width
Change background colour