Skip to content
Home » Oracle » How to Backup Oracle Home

How to Backup Oracle Home

I know there could already have OS backups of database servers, so we usually don't have to backup Oracle products by ourselves. However, if you don't have any OS backups or you want more protection on database servers, you might need to know how to backup Oracle homes before patching.

Of course, you may also consider to backup Oracle home periodically by scripts.

Backup Oracle Home

To tar or zip a directory recursively, you need to take care the path of target, either absolute or relative path works. The latter one is more common and easier to understand.

In this case, we choose to do it with the relative path, so we change the present working directory (PWD) to the upper level of the backup directory.

Here we set ORACLE_HOME, then change PWD to its upper directory by tailing double dots.

[root@test ~]# export ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1
[root@test ~]# cd $ORACLE_HOME/..
[root@test 19.3.0]# pwd

If the target you want to backup is Grid home, you should set ORACLE_HOME to the location of Grid home. For example:

[root@primary01 ~]# export ORACLE_HOME=/u01/app/19.3.0/grid

In this post, we introduce 3 ways to backup Oracle home.

  1. GNU tar Command
  2. UNIX tar Command
  3. zip Command

GNU tar Command

In Linux, we usually use tar command to backup Oracle homes. More precisely, we call such Oracle product as DB home compared to Grid home.

[root@test 19.3.0]# tar -zcvf /backup/homes/DB_HOME_`date +%Y%m%d`.tar.gz dbhome_1 > /backup/homes/DB_HOME_`date +%Y%m%d`_tar_backup.log
[root@test 19.3.0]# echo $?
[root@test 19.3.0]# ll /backup/homes/*.tar.gz
-rw-r--r-- 1 root root 3952582998 Jun 20 21:55 /backup/homes/DB_HOME_20220620.tar.gz

GUN tar in Linux has the ability to filter tar archive through gzip implicitly as long as you specify -z option in the command.

Let's see the flags we used.

  • -z: uses gzip to process the compression and decompression.
  • -c: creates an archive file.
  • -v: outputs the result verbosely.
  • -f: file is the archive.

For OS superusers like root, ownership, permission and timestamp are all preserved by default, you don't have to set option -p to demand it.

UNIX tar Command

In some Unix OS, like AIX, you might only have Unix tar command which does not have -z flag to filter and compress archive. In such case, you need to compress the tar file explicitly by gzip.

As usual, we switch PWD to the upper level of ORACLE_HOME, then issue the command.

[root@test 19.3.0]# tar -pcvf - dbhome_1 | gzip > /backup/homes/DB_HOME_`date +%Y%m%d`.tar.gz

It's also a compressed tar archive like GNU tar does.

zip Command

If you are only familiar with zip command, it also works for backing up Oracle home. As same as we did in tar command, we switch PWD to the upper level of Oracle home to keep its relative path only.

[root@test 19.3.0]# /usr/bin/zip -ry /backup/homes/DB_HOME_`date +%Y%m%d`.zip dbhome_1 > /backup/homes/DB_HOME_`date +%Y%m%d`_zip_backup.log
[root@test 19.3.0]# echo $?
[root@test 19.3.0]# ll /backup/homes/*.zip
-rw-r--r-- 1 root root 3532295017 Jun 20 22:07 /backup/homes/

Let's see the flags we used.

  • -r: finds files to be compressed recursively.
  • -y: keeps symbolic links as is and don't follow links.

Somewhile, the backup file may be needed to restore Oracle home.

Leave a Reply

Your email address will not be published. Required fields are marked *