Oracle用户目录误删除的恢复
当我们在安装Oracle软件前,必须先创建oracle用户组,如oinstall,dba,oper等,并且必须创建oracle用户
在创建完用户账户后,会自动在/home文件夹下,增加一个以用户名命名的文件夹,里面就是存放该用户的一些环境变量等信息
当我们在做文件清理的时候,如果不小心执行了rm -rf /home/oracle,那么该如何恢复这些文件呢?
其实在创建用户的过程中,还会对几个目录进行修改,大致有以下几个:
/etc/passwd --用户密码
/etc/shadow --密钥文件
/etc/group --用户组
/etc/skel/.* --骨架文件
看一下这些文件中和oracle用户相关的内容:
[oracle@ora11g ~]$ cat /etc/passwd |grep oracle
oracle:x:54321:54321::/home/oracle:/bin/bash
[oracle@ora11g ~]$ cat /etc/shadow |grep oracle
cat: /etc/shadow: Permission denied
[oracle@ora11g ~]$ su - root
Password:
[root@ora11g ~]# cat /etc/shadow |grep oracle
oracle:$1$J8eXSYtR$xHRcqxnw3ReD9o7VyNAWf/:16511:0:99999:7:::
[root@ora11g ~]# cat /etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:
games:x:20:
gopher:x:30:
dip:x:40:
ftp:x:50:
lock:x:54:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
nscd:x:28:
floppy:x:19:
vcsa:x:69:
pcap:x:77:
slocate:x:21:
ntp:x:38:
dbus:x:81:
audio:x:63:gdm
avahi:x:70:
rpc:x:32:
mailnull:x:47:
smmsp:x:51:
sshd:x:74:
oprofile:x:16:
rpcuser:x:29:
nfsnobody:x:65534:
xfs:x:43:
stapdev:x:101:
stapusr:x:102:
stap-server:x:155:
haldaemon:x:68:
avahi-autoipd:x:156:
gdm:x:42:
sabayon:x:86:
oinstall:x:54321:
dba:x:54322:oracle
[root@ora11g ~]# cd /etc/skel
[root@ora11g skel]# ls -la
total 64
drwxr-xr-x 3 root root 4096 Mar 17 16:11 .
drwxr-xr-x 96 root root 12288 May 4 10:00 ..
-rw-r--r-- 1 root root 33 Jun 2 2011 .bash_logout
-rw-r--r-- 1 root root 176 Jun 2 2011 .bash_profile
-rw-r--r-- 1 root root 124 Jun 2 2011 .bashrc
-rw-r--r-- 1 root root 515 Jun 21 2011 .emacs
drwxr-xr-x 4 root root 4096 Feb 1 2012 .mozilla
[root@ora11g skel]# cd /home/oracle
[root@ora11g oracle]# ls -la
total 44
drwx------ 4 oracle oinstall 4096 May 4 10:22 .
drwxr-xr-x 3 root root 4096 Mar 17 16:49 ..
-rw------- 1 oracle oinstall 2381 May 4 10:20 .bash_history
-rw-r--r-- 1 oracle oinstall 33 Mar 17 16:49 .bash_logout
-rw-r--r-- 1 oracle oinstall 328 Mar 18 13:01 .bash_profile
-rw-r--r-- 1 oracle oinstall 124 Mar 17 16:49 .bashrc
-rw-r--r-- 1 oracle oinstall 515 Mar 17 16:49 .emacs
drwxr-xr-x 4 oracle oinstall 4096 Mar 17 16:49 .mozilla
drwxr-xr-x 3 oracle oinstall 4096 Mar 17 17:06 .oracle
-rw------- 1 oracle oinstall 1408 Mar 18 13:01 .viminfo
可以看到/etc/skel目录下的几个文件同/home/oracle目录下的文件时相同的
[root@ora11g oracle]# cd .oracle
[root@ora11g .oracle]# ls -la
total 12
drwxr-xr-x 3 oracle oinstall 4096 Mar 17 17:06 .
drwx------ 4 oracle oinstall 4096 May 4 10:22 ..
drwxr-xr-x 2 oracle oinstall 4096 Mar 17 17:18 logs
[root@ora11g .oracle]#
[root@ora11g .oracle]# cd logs
[root@ora11g logs]# ll
total 260
-rw-r--r-- 1 oracle oinstall 41693 Mar 17 17:06 installActions2015-03-17_05-03-57PM.log
-rw-r--r-- 1 oracle oinstall 33118 Mar 17 17:09 installActions2015-03-17_05-08-08PM.log
-rw-r--r-- 1 oracle oinstall 33118 Mar 17 17:13 installActions2015-03-17_05-12-54PM.log
-rw-r--r-- 1 oracle oinstall 33118 Mar 17 17:17 installActions2015-03-17_05-15-29PM.log
-rw-r--r-- 1 oracle oinstall 33118 Mar 17 17:17 installActions2015-03-17_05-17-07PM.log
-rw-r--r-- 1 oracle oinstall 33118 Mar 17 17:18 installActions2015-03-17_05-17-49PM.log
-rw-r--r-- 1 oracle oinstall 33147 Mar 17 17:18 installActions2015-03-17_05-18-26PM.log
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:06 oraInstall2015-03-17_05-03-57PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:06 oraInstall2015-03-17_05-03-57PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:09 oraInstall2015-03-17_05-08-08PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:09 oraInstall2015-03-17_05-08-08PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:13 oraInstall2015-03-17_05-12-54PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:13 oraInstall2015-03-17_05-12-54PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:17 oraInstall2015-03-17_05-15-29PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:17 oraInstall2015-03-17_05-15-29PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:17 oraInstall2015-03-17_05-17-07PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:17 oraInstall2015-03-17_05-17-07PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:18 oraInstall2015-03-17_05-17-49PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:18 oraInstall2015-03-17_05-17-49PM.out
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:18 oraInstall2015-03-17_05-18-26PM.err
-rw-r--r-- 1 oracle oinstall 0 Mar 17 17:18 oraInstall2015-03-17_05-18-26PM.out
/home/oracle/.oracle/logs目录中存放的是在用OUI安装oracle软件时生成的一些日志信息
好,现在了解了大致的目录结构,那么当我们由于误操作删除了/home/oracle目录后,恢复其实就很容易了
即只需要把/etc/skel目录下的文件全都拷贝到原目录下,应该就可以解决这个问题了,下面我们来看一下测试过程
在数据库正常运行的情况下,把/home/oracle目录删除,为了提高可恢复性,把具有危险操作的rm -rf操作替换成mv更名操作
[oracle@ora11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon May 4 11:17:21 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 507513936 bytes
Database Buffers 322961408 bytes
Redo Buffers 2371584 bytes
Database mounted.
Database opened.
SQL> host
[oracle@ora11g ~]$ ps -ef | grep oracle
root 3402 3289 0 10:22 pts/2 00:00:00 su - oracle
oracle 3403 3402 0 10:22 pts/2 00:00:00 -bash
root 3587 3433 0 10:56 pts/2 00:00:00 su - oracle
oracle 3588 3587 0 10:56 pts/2 00:00:00 -bash
root 24415 3618 0 11:14 pts/2 00:00:00 su - oracle
oracle 24416 24415 0 11:14 pts/2 00:00:00 -bash
oracle 24453 24416 0 11:17 pts/2 00:00:00 sqlplus as sysdba
oracle 24463 1 0 11:17 ? 00:00:00 ora_pmon_ora11g
oracle 24467 1 0 11:17 ? 00:00:00 ora_psp0_ora11g
oracle 24471 1 2 11:17 ? 00:00:02 ora_vktm_ora11g
oracle 24477 1 0 11:17 ? 00:00:00 ora_gen0_ora11g
oracle 24481 1 0 11:17 ? 00:00:00 ora_diag_ora11g
oracle 24485 1 0 11:17 ? 00:00:00 ora_dbrm_ora11g
oracle 24489 1 0 11:17 ? 00:00:00 ora_dia0_ora11g
oracle 24493 1 0 11:17 ? 00:00:00 ora_mman_ora11g
oracle 24497 1 0 11:17 ? 00:00:00 ora_dbw0_ora11g
oracle 24501 1 0 11:17 ? 00:00:00 ora_lgwr_ora11g
oracle 24505 1 0 11:17 ? 00:00:00 ora_ckpt_ora11g
oracle 24509 1 0 11:17 ? 00:00:00 ora_smon_ora11g
oracle 24513 1 0 11:17 ? 00:00:00 ora_reco_ora11g
oracle 24517 1 0 11:17 ? 00:00:00 ora_mmon_ora11g
oracle 24521 1 0 11:17 ? 00:00:00 ora_mmnl_ora11g
oracle 24525 1 0 11:17 ? 00:00:00 ora_d000_ora11g
oracle 24529 1 0 11:17 ? 00:00:00 ora_s000_ora11g
oracle 24543 24453 0 11:17 ? 00:00:01 oracleora11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
oracle 24547 1 0 11:17 ? 00:00:00 ora_arc0_ora11g
oracle 24551 1 0 11:17 ? 00:00:00 ora_arc1_ora11g
oracle 24555 1 0 11:17 ? 00:00:00 ora_arc2_ora11g
oracle 24559 1 0 11:17 ? 00:00:00 ora_arc3_ora11g
oracle 24563 1 0 11:17 ? 00:00:00 ora_qmnc_ora11g
oracle 24591 1 0 11:18 ? 00:00:00 ora_q000_ora11g
oracle 24595 1 0 11:18 ? 00:00:00 ora_q001_ora11g
oracle 24599 1 0 11:18 ? 00:00:00 ora_cjq0_ora11g
oracle 24665 24453 0 11:19 pts/2 00:00:00 /bin/bash
oracle 24684 24665 0 11:19 pts/2 00:00:00 ps -ef
oracle 24685 24665 0 11:19 pts/2 00:00:00 grep oracle
[oracle@ora11g ~]$ exit
[root@ora11g ~]# cd /home
[root@ora11g home]# mv /home/oracle /home/oracle_bak
[root@ora11g home]# ls -la
total 20
drwxr-xr-x 3 root root 4096 May 4 11:33 .
drwxr-xr-x 26 root root 4096 May 4 10:00 ..
drwx------ 4 oracle oinstall 4096 May 4 11:30 oracle_bak
[root@ora11g home]# mkdir oracle
[root@ora11g home]# chown oracle:oinstall oracle
[root@ora11g home]# ls -la
total 24
drwxr-xr-x 4 root root 4096 May 4 11:33 .
drwxr-xr-x 26 root root 4096 May 4 10:00 ..
drwxr-xr-x 2 oracle oinstall 4096 May 4 11:33 oracle
drwx------ 4 oracle oinstall 4096 May 4 11:30 oracle_bak
[root@ora11g home]# cd /etc/skel
[root@ora11g skel]# ls -la
total 64
drwxr-xr-x 3 root root 4096 Mar 17 16:11 .
drwxr-xr-x 96 root root 12288 May 4 11:07 ..
-rw-r--r-- 1 root root 33 Jun 2 2011 .bash_logout
-rw-r--r-- 1 root root 176 Jun 2 2011 .bash_profile
-rw-r--r-- 1 root root 124 Jun 2 2011 .bashrc
-rw-r--r-- 1 root root 515 Jun 21 2011 .emacs
drwxr-xr-x 4 root root 4096 Feb 1 2012 .mozilla
[root@ora11g skel]# cp .* /home/oracle/
cp: omitting directory `.'
cp: omitting directory `..'
cp: omitting directory `.mozilla'
[root@ora11g skel]# cd /home/oracle
[root@ora11g oracle]# ls -la
total 28
drwxr-xr-x 2 oracle oinstall 4096 May 4 11:33 .
drwxr-xr-x 4 root root 4096 May 4 11:33 ..
-rw-r--r-- 1 root root 33 May 4 11:33 .bash_logout
-rw-r--r-- 1 root root 176 May 4 11:33 .bash_profile
-rw-r--r-- 1 root root 124 May 4 11:33 .bashrc
-rw-r--r-- 1 root root 515 May 4 11:33 .emacs
注意权限,必须是oracle用户,oinstall组的
[root@ora11g oracle]# chown oracle:oinstall /home/oracle -R
[root@ora11g oracle]# ls -la
total 28
drwxr-xr-x 2 oracle oinstall 4096 May 4 11:33 .
drwxr-xr-x 4 root root 4096 May 4 11:33 ..
-rw-r--r-- 1 oracle oinstall 33 May 4 11:33 .bash_logout
-rw-r--r-- 1 oracle oinstall 176 May 4 11:33 .bash_profile
-rw-r--r-- 1 oracle oinstall 124 May 4 11:33 .bashrc
-rw-r--r-- 1 oracle oinstall 515 May 4 11:33 .emacs
[root@ora11g oracle]# su - oracle
[oracle@ora11g ~]$ sqlplus / as sysdba
-bash: sqlplus: command not found
[oracle@ora11g ~]$ vi .bash_profile
添加以下环境变量的内容:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=ora11g
export PATH=$PATH:$ORACLE_HOME/bin
[oracle@ora11g ~]$ . .bash_profile
[oracle@ora11g ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Mon May 4 11:36:31 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
oracle用户又可以继续登录了