Linux 平台误删 home oracle 根目录的解决方法
每个用户的创建,都会涉及到如下几个文件:
/etc/passwd (用户)
/etc/group (用户组)
/etc/shadow (密钥文件)
/home/username (家目录)
/etc/skel/.* (骨架文件)
在创建用户的时候,会在/etc/passwd,/etc/group,/etc/shadow三个文件中添加用户的信息,创建一个/home 下的用户根目录,然后把所有的骨架文件复制到用户的根目录下。
[oracle@dg1 ~]$ cat /etc/passwd|grep oracle
oracle:x:502:507::/home/oracle:/bin/bash
[oracle@dg1 ~]$
[oracle@dg1 ~]$ cat /etc/group |grepoinstall
oinstall:x:507:
[oracle@dg1 ~]$ cat /etc/group |grep dba
dba:x:502:oracle
asmdba:x:506:oracle
[oracle@dg1 ~]$
[root@dg1 ~]# cat /etc/shadow |grep oracle
oracle:$6$7xDE3ZWD$jOnuSzTwfdWoR9JMVr33IIJhDJ/vGnCL5XGpCEMBx3XPiov0NnxRBvDIhflBTWPzXSNZ.HbqEoIt7PAxuF9R70:15595:0:99999:7:::
[root@dg1 ~]#
当我们删除/home/oracle这个用户的根目录之后,用户的配置信息还存在系统的配置文件中,所以只需要还原骨架文件,在修改一下环境变量的信息,就可以了。
3 示例
--数据库正常运行:
[root@zw /]# ps -ef|grep ora
root 1958 1936 0 Jan06 ? 00:00:22 hald-addon-storage: polling /dev/hdc
oracle 7962 1 0 02:41 ? 00:00:00 /u01/app/oracle/product/11.2.0.3/db_1/bin/tnslsnr LISTENER -inherit
root 22201 22140 0 19:59 pts/2 00:00:00 su - oracle
oracle 22202 22201 0 19:59 pts/2 00:00:00 -bash
oracle 22347 22202 0 20:18 pts/2 00:00:00 rlwrap sqlplus / as sysdba
oracle 22348 22347 0 20:18 pts/4 00:00:00 sqlplus as sysdba
oracle 22640 1 0 21:08 ? 00:00:00 ora_pmon_ogg02
oracle 22642 1 0 21:08 ? 00:00:00 ora_psp0_ogg02
oracle 22644 1 0 21:08 ? 00:00:00 ora_vktm_ogg02
oracle 22648 1 0 21:08 ? 00:00:00 ora_gen0_ogg02
oracle 22650 1 0 21:08 ? 00:00:00 ora_diag_ogg02
oracle 22652 1 0 21:08 ? 00:00:00 ora_dbrm_ogg02
oracle 22654 1 0 21:08 ? 00:00:00 ora_dia0_ogg02
oracle 22656 1 0 21:08 ? 00:00:00 ora_mman_ogg02
oracle 22658 1 0 21:08 ? 00:00:00 ora_dbw0_ogg02
直接把/home/oracle 目录删掉,我这里直接move。
[root@zw /]# cd /home
[root@zw home]# ls
oracle
[root@zw home]# mv oracle oracle.bak
[root@zw home]# ll
total 4
drwx------ 3 oracle dba 4096 Jan 7 19:25 oracle.bak
[root@zw home]#
[root@zw home]# su - oracle
su: warning: cannot change directory to /home/oracle: No such file or directory
-bash-3.2$
-bash-3.2$ sqlplus / as sysdba
-bash: sqlplus: command not found
-bash-3.2$
可以看到切换到oracle用户有警告,sqlplus已经不能使用了!
开始恢复:
--创建目录:
[root@zw home]# pwd
/home
[root@zw home]# mkdir oracle
[root@zw home]# ll
total 8
drwxr-xr-x 2 root root 4096 Jan 7 21:22 oracle
drwx------ 3 oracle dba 4096 Jan 7 19:25 oracle.bak
[root@zw home]# chown -R oracle:dba oracle
[root@zw home]# ll
total 8
drwxr-xr-x 2 oracle dba 4096 Jan 7 21:22 oracle
drwx------ 3 oracle dba 4096 Jan 7 19:25 oracle.bak
[root@zw home]#
--复制骨架文件:
[root@zw home]# cp /etc/skel/.* /home/oracle/
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.mozilla'
[root@zw home]#
[root@dg1 home]# ls -la /home/oracle
[root@zw home]# ls -la /home/oracle
total 28
drwxr-xr-x 2 oracle dba 4096 Jan 7 21:23 .
drwxr-xr-x 4 root root 4096 Jan 7 21:22 ..
-rw-r--r-- 1 root root 33 Jan 7 21:23 .bash_logout
-rw-r--r-- 1 root root 176 Jan 7 21:23 .bash_profile
-rw-r--r-- 1 root root 124 Jan 7 21:23 .bashrc
-rw-r--r-- 1 root root 515 Jan 7 21:23 .emacs
[root@zw home]# chown -R oracle:dba /home/oracle
[root@zw home]# cd /home/oracle
[root@dg1 oracle]# ls -la
total 28
drwxr-xr-x 2 oracle dba 4096 Jan 7 21:23 .
drwxr-xr-x 4 root root 4096 Jan 7 21:22 ..
-rw-r--r-- 1 oracle dba 33 Jan 7 21:23 .bash_logout
-rw-r--r-- 1 oracle dba 176 Jan 7 21:23 .bash_profile
-rw-r--r-- 1 oracle dba 124 Jan 7 21:23 .bashrc
-rw-r--r-- 1 oracle dba 515 Jan 7 21:23 .emacs
//修改oracle 用户的环境变量:
[root@zw oracle]# cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# Oracle Settings
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.3/db_1
export ORACLE_SID=ogg02
#export NLS_LANG=american_america.zhs16gbk
#PATH=$PATH:$HOME/bin
alias sqlplus="rlwrap sqlplus"
alias rman="rlwrap rman"
export PATH=$ORACLE_HOME/bin:$PATH
export PATH
[root@zw oracle]# . ./.bash_profile --使文件生效
切换一下用户看有没有问题
[root@zw home]# cd oracle
[oracle@zw ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Wed Jan 7 21:31:28 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
恢复成功!