Linux 平台誤刪 home oracle 根目錄的解決方案

來源:互聯網
上載者:User

標籤:


 


1  背景說明

正常情況下,我們在安裝Oracle資料庫的時候,都會建立一個oracle的使用者。 其根目錄就是/home/oracle.

    並且根據Oracle 的OFA的架構,也是建議使用/u01 這樣的目錄來單獨安裝oracle的軟體,包括存放資料檔案。

 

    關於OFA可以參考如下串連:

Oracle OFA(Optimal Flexible Architecture)說明

http://blog.csdn.net/tianlesoftware/article/details/7086104

 

但實際上,總會存在那麼一些不按照官網的建議來建立和管理的資料庫,這些年見過太多。Dave 是一直建議嚴格按照Oracle 的標準來,因為這個是通用的標準,如果每家公司都有自己的標準,那每次換人管理,都會是很麻煩的,也是容易出問題的。

 

    俗話說:鐵打的營盤,流水的兵,DBA的崗位總會有波動,規則不一樣,就會埋下坑,至於最後是誰踩上,就是人品了。

 

    昨晚一朋友就出現這個問題,單一實例的資料庫,非歸檔,無備份。刪除了整個/home/oracle 目錄,如果是按照OFA來的,這個倒也不是很嚴重的事情,關鍵是/home/oracle 下還有幾個資料檔案,折騰了很久,把資料還原出來了。

 

    馬上就過年了,防火,防盜,防宕庫,居然還犯下這麼低級的錯誤,這是不想要年終獎的節奏啊,這個就不多說,DBA 就是一個心細的活,需要慢慢曆練。

 

    這篇Blog 主要看下誤刪除/home/oracle 目錄的解決方案。這裡不涉及資料檔案恢複問題,以後在整理。

 

 

2  linux使用者建立說明

 

在安裝oracle 資料庫的時候,我們都會建立使用者和組。

 

Oracle 安裝參考:

64位 linux 平台下Oracle 安裝文檔

http://blog.csdn.net/tianlesoftware/article/details/6062816

 

 

groupadd oinstall

groupadd dba

groupadd oper

useradd -g oinstall -G dba oracle

 

這裡是用linux的命令來建立的。 和資料庫建立一樣,我們一般都是通過OUI來建立執行個體,其實也是可以通過靜默的方式來建立。

 

所以我們在講這個故障的處理之前,需要瞭解linux 手工建立使用者和組的方法。

 

 

每個使用者的建立,都會涉及到如下幾個檔案:

/etc/passwd (使用者)

/etc/group (使用者組)

/etc/shadow (密鑰檔案)

/home/username (家目錄)

/etc/skel/.* (骨架檔案)

 

 

在建立使用者的時候,會在/etc/passwd,/etc/group,/etc/shadow三個檔案中添加使用者的資訊,建立一個/home 下的使用者根目錄,然後把所有的骨架檔案複製到使用者的根目錄下。

 

[[email protected] ~]$ cat /etc/passwd|grep oracle

oracle:x:502:507::/home/oracle:/bin/bash

[[email protected] ~]$

 

[[email protected] ~]$ cat /etc/group |grepoinstall

oinstall:x:507:

[[email protected] ~]$ cat /etc/group |grep dba

dba:x:502:oracle

asmdba:x:506:oracle

[[email protected] ~]$

 

[[email protected] ~]# cat /etc/shadow |grep oracle

oracle:$6$7xDE3ZWD$jOnuSzTwfdWoR9JMVr33IIJhDJ/vGnCL5XGpCEMBx3XPiov0NnxRBvDIhflBTWPzXSNZ.HbqEoIt7PAxuF9R70:15595:0:99999:7:::

[[email protected] ~]#

 

當我們刪除/home/oracle這個使用者的根目錄之後,使用者的配置資訊還存在系統的設定檔中,所以只需要還原骨架檔案,在修改一下環境變數的資訊,就可以了。

 

 

3  樣本

 

 

--資料庫正常運行:

[[email protected] ~]$ ps -ef|grep ora

root     1388  1347  0 Aug26 ?        00:00:37 hald-addon-storage: polling/dev/sr0 (every 2 sec)

oracle   9946     1  0 00:49 ?        00:00:05 ora_pmon_dave

oracle   9948     1  0 00:49 ?        00:00:11 ora_psp0_dave

oracle   9950     1  2 00:49 ?        00:16:17 ora_vktm_dave

oracle   9954     1  0 00:49 ?        00:00:01 ora_gen0_dave

oracle   9956     1  0 00:49 ?        00:00:01 ora_diag_dave

oracle   9958     1  0 00:49 ?        00:00:01 ora_dbrm_dave

oracle   9960     1  0 00:49 ?        00:00:14 ora_dia0_dave

oracle   9962     1  0 00:49 ?        00:00:01 ora_mman_dave

oracle   9964     1  0 00:49 ?        00:00:02 ora_dbw0_dave

 

 

 

直接把/home/oracle 目錄刪掉,我這裡直接move。

 

[[email protected] ~]# cd /home

[[email protected] home]# ls

oracle

[[email protected] home]# mv oracle oracle.bak

[[email protected] home]# ls

oracle.bak

[[email protected] home]#

 

[[email protected] home]# su - oracle

su: warning: cannot change directory to/home/oracle: No such file or directory

-bash-4.1$

 

-bash-4.1$ sqlplus / as sysdba

-bash: sqlplus: command not found

-bash-4.1$

 

-bash-4.1$ whoami

oracle

-bash-4.1$ pwd

/home

-bash-4.1$

 

 

 

 

開始恢複:

 

--建立目錄:

[[email protected] home]# pwd

/home

[[email protected] home]# mkdir oracle

[[email protected] home]# chown oracle:oinstalloracle

[[email protected] home]# ll

total 8

drwxr-xr-x  2 oracle oinstall 4096 Aug 27 14:17 oracle

drwx------. 25 oracle oinstall 4096 Aug 2623:08 oracle.bak

[[email protected] home]#

 

--複製骨架檔案:

[[email protected] ~]# cp /etc/skel/.* /home/oracle/

cp: omitting directory `/etc/skel/.‘

cp: omitting directory `/etc/skel/..‘

cp: omitting directory `/etc/skel/.gnome2‘

cp: omitting directory `/etc/skel/.mozilla‘

[[email protected] ~]#

 

[[email protected] home]# ls -la /home/oracle

total 24

drwxr-xr-x 2 root root 4096 Aug 27 14:47 .

drwxr-xr-x. 4 root root 4096 Aug 27 14:47..

-rw-r--r-- 1 root root   18 Aug 27 14:47.bash_logout

-rw-r--r-- 1 root root  176 Aug 27 14:47.bash_profile

-rw-r--r-- 1 root root  124 Aug 27 14:47.bashrc

-rw-r--r-- 1 root root  121 Aug 27 14:47.kshrc

[[email protected] home]#

 

[[email protected] home]# chown -R oracle:oinstall/home/oracle

[[email protected] home]# cd /home/oracle

[[email protected] oracle]# ls -la

total 24

drwxr-xr-x 2 oracle oinstall 4096 Aug 27 14:47 .

drwxr-xr-x. 4 root   root    4096 Aug 27 14:47 ..

-rw-r--r-- 1 oracle oinstall   18 Aug 2714:47 .bash_logout

-rw-r--r-- 1 oracle oinstall  176 Aug 2714:47 .bash_profile

-rw-r--r-- 1 oracle oinstall  124 Aug 2714:47 .bashrc

-rw-r--r-- 1 oracle oinstall  121 Aug 2714:47 .kshrc

[[email protected] oracle]#

 

 

//修改oracle 使用者的環境變數:

[[email protected] ~]$ cat .bash_profile

# .bash_profile

 

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

    .~/.bashrc

fi

 

# User specific environment and startupprograms

 

PATH=$PATH:$HOME/bin

 

export PATH

 

 

# Oracle Settings

TMP=/tmp; export TMP

TMPDIR=$TMP; export TMPDIR

 

ORACLE_HOSTNAME=dave; exportORACLE_HOSTNAME

ORACLE_UNQNAME=dave; export ORACLE_UNQNAME

ORACLE_BASE=/u01/app/oracle; exportORACLE_BASE

ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1;exportORACLE_HOME

ORACLE_SID=dave; export ORACLE_SID

 

PATH=/u01:/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

 

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;exportLD_LIBRARY_PATH

CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;exportCLASSPATH

[[email protected] ~]$

 

 

恢複正常。 但如果有資料檔案,那麼恢複就比這裡更複雜。

 

 

 

 

 

 

 

 

--------------------------------------------------------------------------------------------

著作權,文章禁止轉載,否則追究法律責任!

 

AboutDave:

--------------------------------------------------------------------------------------------

QQ:     251097186

Email:    [email protected]

Blog:    http://blog.csdn.net/tianlesoftware

Weibo:    http://weibo.com/tianlesoftware

Twitter:  http://twitter.com/tianlesoftware

Facebook: http://www.facebook.com/tianlesoftware

Linkedin: http://cn.linkedin.com/in/tianlesoftware

 

Dave 的QQ群:

--------------------------------------------------------------------------------------------

注意:加群必須註明資料表空間和資料檔案關係 | 不要重複加群

CNDBA_1: 62697850 (空)    CNDBA_2: 62697716 (滿)  CNDBA_3: 283816689

CNDBA_4: 391125754   CNDBA_5:104207940    CNDBA_6: 62697977   CNDBA_7: 142216823(滿)

Linux 平台誤刪 home oracle 根目錄的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.