注意事项

  1. 一般情况下备份ORACLE_HOME不需要停库和监听,但官方建议如果能停尽量,且一般打补丁都是需要停库,所以建议还是在停库和监听后再备份ORACLE_HOME.
  2. 备份应当由root或者oracle用户执行,强烈建议用root,否则可能会遇到未知报错.
  3. tar备份时切记使用-p参数保留文件属性.
  4. 还原备份时必须关库和监听.

实施步骤

1.切换到root
[oracle@ora11 ~]# su - root
[root@ora11 ~]# export ORACLE_HOME=/u01/app/oracle/product/11.2

2.切换到ORACLE_HOME所在的目录,注意是到那个目录
[root@ora11 ~]# cd ${ORACLE_HOME}/..
[root@ora11 product]# ll
drwxrwxr-x 78 oracle oinstall 4096 Dec 19 18:09 11.2

3.备份ORACLE_HOME
[root@ora11 product]# tar -pcvf ORACLE_HOME_$(date +%F).tar 11.2
[root@ora11 product]# ll
total 4941340
drwxrwxr-x 78 oracle oinstall       4096 Dec 19 18:09 11.2
-rw-r--r--  1 root   root     5059921920 Dec 23 13:28 ORACLE_HOME_2023-12-23.tar

4.备份中央目录,中央目录很重要,尤其是打补丁的时候,所以一定要备份
[root@ora11 product]# more /etc/oraInst.loc
inventory_loc=/u01/app/oraInventory
inst_group=oinstall
[root@ora11 product]# cp -rp /u01/app/oraInventory /u01/app/oraInventory_$(date +%F)
[root@ora11 product]# ll /u01/app/
total 0
drwxrwxr-x 9 oracle oinstall 125 Apr  9  2023 oracle
drwxrwx--- 5 oracle oinstall  89 Dec 20 10:05 oraInventory
drwxrwx--- 6 oracle oinstall 109 Dec 23 13:29 oraInventory_2023-12-23

5.还原备份(必须关库和监听)
[root@ora11 ~]# cd ${ORACLE_HOME}/..
[root@ora11 product]# mv 11.2 11.2_$(date +%F)
[root@ora11 product]# ll
total 4941340
drwxrwxr-x 78 oracle oinstall       4096 Dec 19 18:09 11.2_2023-12-23
-rw-r--r--  1 root   root     5059921920 Dec 23 13:28 ORACLE_HOME_2023-12-23.tar
[root@ora11 product]# tar -pxvf ORACLE_HOME_2023-12-23.tar