How to Backup Oracle Home and Inventory

During any patching activity like PSU and OJVM it is good to take backup of Oracle home and oraInventory so that you can restore ORACLE_HOME and INVENTORY in case of any issues.

Steps to Backup ORACLE_HOME and oraInventory

STEP 1: Login to database and shut it down.

bash-4.2$ ps -ef|grep pmo
oracle 95688 1 0 Sep16 ? 00:00:13 ora_pmon_orcl
oracle 112983 112972 0 08:07 pts/0 00:00:00 grep pmo

SQL> select name,open_mode from v$database;
NAME OPEN_MODE
--------------
ORCL READ WRITE

SQL> Connect / as sysdba
Connected.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.

STEP 2: Stop Listener

bash-4.2$ ps -ef|grep tns
root 64 2 0 Aug12 ? 00:00:00 [netns]
oracle 99219 1 0 Sep16 ? 00:00:16 /scratch/oracle/app/product/12.1.0/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle 120210 112972 0 09:17 pts/0 00:00:00 grep tns
bash-4.2$

bash-4.2$ lsnrctl stop
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 17-SEP-2019 10:00:08
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orahow.com)(PORT=1521)))
The command completed successfully

STEP 3: Take Backup of ORACLE_HOME

bash-4.2$ pwd
/scratch/oracle/app/product/12.1.0

bash-4.2$ ls -lrt
drwxr-xr-x 73 oracle dba 4096 Sep 16 10:34 dbhome_1

bash-4.2$ tar -zcvf dbhome_1_bkp09172019.tar dbhome_1

You can also take backup in background using nohup.
bash-4.2$ nohup tar -zcvf dbhome_1_bkp09172019.tar dbhome_1 &

You can also take backup in different location/path.
bash-4.2$ nohup tar -zcvf /scratch/oracle/dbhome_1_bkp09172019.tar dbhome_1 &

STEP 4: Backup oraInventory

bash-4.2$ cat /etc/oraInst.loc
inventory_loc=/scratch/oracle/oraInventory
inst_group=dba

bash-4.2$ cd /scratch/oracle
bash-4.2$ ls -lrt
drwxr-xr-x 4 oracle dba 4096 Jun 26 16:37 app
drwxrwx--- 5 oracle dba 4096 Sep 16 10:52 oraInventory

bash-4.2$ tar -zcvf oraInventory_bkp09172019.tar oraInventory

STEP 5: Backup of oracle home and inventory is completed. Now you can start the listener and the database.

Restore Oracle home and inventory from backup

STEP 1: Shutdown Listener.

STEP 2: Shutdown the Database.

STEP 3: Restore oraInventory and ORACLE_HOME from backup.

 bash-4.2$ tar -xvf oraInventory_bkp09172019.tar
bash-4.2$ mv  oraInventory  oraInventory_bkp09172019
bash-4.2$ tar -xvf dbhome_1_bkp09172019.tar
bash-4.2$ mv  dbhome_1 dbhome_1_bkp09172019

STEP 4: Start the listener and the database.

 bash-4.2$ lsnrctl start
bash-4.2$ sqlplus / as sysdba
SQL> startup

You can take backup of ORACLE_HOME and oraInventory before any critical database activities like patching.