前两天,看见ITPUB微信公众一篇文章,服务器误删文件后,恢复mysql的过程,今天模拟该环境,进行oracle数据库的恢复。具体如下:
reference ITPUB分享文章: http://mp.weixin.qq.com/
1.linux系统中删除根目录数据
---在卸载数据库时,有条命令
rm -rf $ORACLE_HOME/*
如果没有给$ORACLE_HOME设置环境变量,就变成
rm -rf /* 咯
----如何是用root用户做的删除,那么意味着根目录下所有文件都将被删。linux也就此宕机,这里不讨论如何修复linux,只是恢复oracle相关文件到另一台linux系统中,然后启动该数据库
2.挂载原删除磁盘到新linux系统中
----首先,将被删数据的linux硬盘挂载到另一台linux中
/*
这里可以直接使用linux自带的debugfs进行查看,当然使用后面的工具也可以实现
----使用debugfs查看oracle目录在哪个分区
# fdisk -l ---先查看有哪些分区
# debugfs
debugfs 1.41.12 (17-May-2010)
debugfs: open /dev/sdc
debugfs: lsdel
debugfs: ls -d
*/
3.准备进行数据恢复
第一步:使用extundelete恢复
----可以使用extundelete直接恢复oracle所在分区被删数据
yum -y install e2fsprogs e2fsprogs-libs e2fsprogs-devel
bunzip2 extundelete-0.2.4.tar.bz2
tar xvf extundelete-0.2.4.tar
cd extundelete-0.2.4
./configure
make && make install
extundelete /dev/mapper/vg_xuan1-lv_root --inode 2 --查看被删的数据
----开始恢复被删数据
# extundelete /dev/mapper/vg_xuan1-lv_root --restore-all
----恢复了部分数据,但是oracle所在目录恢复失败
第二步:使用ext3grep恢复
# df -hT ---原磁盘分区格式为ext4的,估计不能完成数据的恢复,不过还是试一试吧
tar zxf ext3grep-0.10.2.tar.gz
cd ext3grep-0.10.2
./configure
make && make install
----确实不行
ext3grep /dev/vgdata/LogVol00 --dump-names --扫描被删除文件
ext3grep /dev/vgdata/LogVol00 --restore-all --恢复所有被删文件
ext3grep /dev/vgdata/LogVol00 --restore-file u01/oracle/user01.dbf --恢复指定文件
第三步:再次使用extundelete进行恢复
----这里直接恢复数据文件、参数文件、控制文件(这里其实只要恢复数据文件后,就能open数据库,但是能恢复其他文件最好一并恢复吧)
extundelete /dev/mapper/vg_xuan1-lv_root --inode 2 --查看被删除的数据
extundelete /dev/sdb1 --restore-file user01.dbf --恢复单个文件
extundelete /dev/mapper/vg_xuan1-lv_root --restore-directory /u01/app/ --恢复单个目录
extundelete /dev/sdb1 --restore-all --恢复所有误删文件
----这次使用恢复目录方式恢复
[root@xuanDG2 zhong]# extundelete /dev/mapper/vg_xuan1-lv_root --restore-directory /u01/app/oracle
NOTICE: Extended attributes are not restored.
WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.
The partition should be unmounted to undelete any files without further data loss.
If the partition is not currently mounted, this message indicates
it was improperly unmounted, and you should run fsck before continuing.
If you decide to continue, extundelete may overwrite some of the deleted
files and make recovering those files impossible. You should unmount the
file system and check it with fsck before using extundelete.
Would you like to continue? (y/n)
y
Loading filesystem metadata ... 400 groups loaded.
Loading journal descriptors ... 30517 descriptors loaded.
Searching for recoverable inodes in directory /u01/app/oracle ...
27686 recoverable inodes found.
Looking through the directory structure for deleted files ...
Unable to restore inode 1572879 (u01/app/oracle/product): Space has been reallocated.
Unable to restore inode 2625899 (u01/app/oracle/diag/rdbms/orcl/orcl/lck/AM_994187642_3287667720.lck): No data found.
27357 recoverable inodes still lost.
----数据文件控制文件日志文件已经找回
[root@xuanDG2 zhong]# ls RECOVERED_FILES/u01/app/oracle/oradata/orcl/
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
----接下来恢复密码文件和参数文件
[root@xuanDG2 zhong]# extundelete /dev/mapper/vg_xuan1-lv_root --restore-directory /u01/app/oracle/product/11.2.0/db_1/dbs/
NOTICE: Extended attributes are not restored.
WARNING: EXT3_FEATURE_INCOMPAT_RECOVER is set.
The partition should be unmounted to undelete any files without further data loss.
If the partition is not currently mounted, this message indicates
it was improperly unmounted, and you should run fsck before continuing.
If you decide to continue, extundelete may overwrite some of the deleted
files and make recovering those files impossible. You should unmount the
file system and check it with fsck before using extundelete.
Would you like to continue? (y/n)
y
Loading filesystem metadata ... 400 groups loaded.
Loading journal descriptors ... 30517 descriptors loaded.
Searching for recoverable inodes in directory /u01/app/oracle/product/11.2.0/db_1/dbs/ ...
27686 recoverable inodes found.
Looking through the directory structure for deleted files ...
Unable to restore inode 1590870 (u01/app/oracle/product/11.2.0/db_1/dbs/lkORCL): Space has been reallocated.
Unable to restore inode 1590871 (u01/app/oracle/product/11.2.0/db_1/dbs/hc_orcl.dat): Space has been reallocated.
27680 recoverable inodes still lost.
----密码文件和参数文件也找回(不是必须)
[root@xuanDG2 zhong]# ls RECOVERED_FILES/u01/app/oracle/product/11.2.0/db_1/dbs/
init.ora orapworcl spfileorcl.ora
。。。。。。。。
其他的是否需要恢复,自己衡量
4.接下来启动数据库
----启动数据库有两种方式,一种是,在新linux中安装数据库软件,不创建数据库,然后将恢复的数据拷贝到相应目录文件中,最后启动数据库。另外一种是新创建一个和原linux中数据库环境一致的场景,然后删除参数文件、控制文件、数据文件,将恢复的数据拷贝到相应位置再启动数据库。 这里建议使用第二种方式
4.1 第一种方式启库
----思路,安装数据库软件,不创建数据库
1.安装数据库软件
2.创建必要目录
mkdir -p $ORACLE_BASE/fast_recovery_area/orcl
mkdir -p $ORACLE_BASE/admin/orcl/adump
mkdir -p $ORACLE_BASE/admin/orcl/dpdump
mkdir -p $ORACLE_BASE/admin/orcl/pfile
mkdir -p $ORACLE_BASE/oradata/orcl
3.拷贝数据文件日志文件控制文件
cp /zhong/RECOVERED_FILES/u01/app/oracle/oradata/orcl/* /u01/app/oracle/oradata/orcl/.
cp /u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/fast_recovery_area/orcl/control02.ctl
4.拷贝参数文件密码文件
cp /zhong/RECOVERED_FILES/u01/app/oracle/product/11.2.0/db_1/dbs/* /u01/app/oracle/product/11.2.0/db_1/dbs/.
5.准备启库
sqlplus / as sysdba
startup nomount
alter database mount;
alter database open;
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
-------------------- ------------------------------------
orcl OPEN
6.创建监听
vim /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
# (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.22)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_listener=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)))
lsnrctl start
alter system register;
lsnrctl status
7.配置tns
vim /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.22)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
sqlplus sys/sys@orcl as sysdba
----创建EM(貌似不行)
emctl start dbconsole
----先清理一下
emca -deconfig dbcontrol db
emca -repos drop
----开始创建
emca -repos create
emca -config dbcontrol db
4.2 第二种方式启库
4.2.1 先创建数据库
----这里贴一个配置环境脚本
#!/bin/bash
#1.关闭防火墙
service iptables stop
service ip6tables stop
chkconfig iptables off
chkconfig ip6tables off
#2.添加用户 用户组
groupadd -g 1000 oinstall
groupadd -g 1001 dba
groupadd -g 1002 oper
useradd -u 1000 -g oinstall -G dba,oper oracle
#3.设置用户密码
echo "111111" |passwd --stdin oracle
#4.创建所需目录
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01
chmod -R 775 /u01
#5.配置node1 grid环境变量
#6.配置node1 oracle环境变量
echo "
export ORACLE_SID=orcl
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/db_1
export TNS_ADMIN=\$ORACLE_HOME/network/admin
# export ORACLE_HOSTNAME=node1.test.com
# export ORACLE_UNQNAME=orcl
export PATH=\$PATH:\$ORACLE_HOME/bin
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
export NLS_LANG=american_america.ZHS16GBK
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'
export EDITOR=vi
export LANG=en_US.UTF-8
umask 022
" >> ~oracle/.bash_profile
echo "
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
" >> ~oracle/.bashrc
#7.配置limits资源限制
echo "
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
" >> /etc/security/limits.conf
#8.配置内核参数
echo "
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1052045312
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
" >> /etc/sysctl.conf
sysctl -p
#9.添加hosts文件
echo "
#node1
192.168.11.22 xuanDG2
" >> /etc/hosts
#10.yum安装包
yum -y install binutils compat-libcap1 compat-libstdc++-33.i686 compat-libstdc++-33 gcc gcc-c++ glibc.i686 glibc glibc-devel.i686 glibc-devel ksh libgcc.i686 libgcc libstdc++.i686 libstdc++ libstdc++-devel.i686 libstdc++-devel libaio
.i686 libaio libaio-devel.i686 libaio-devel make sysstat elfutils-libelf-devel
#11.关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#12.修改tmpfs
sed -i '/tmpfs/d' /etc/fstab
echo "tmpfs /dev/shm tmpfs defaults,size=2G 0 0" >>/etc/fstab
mount -o remount /dev/shm
----数据库如何创建,这里不在过多介绍,要注意的就是,创建数据库时,环境最好和原数据库环境一致(数据库目录、SID、字符集.....)
4.2.2 删除数据库相关文件
----删除之前先关闭db组件
emctl stop dbconsole
lsnrctl stop
shut abort
----删除数据文件、控制文件、日志文件
[oracle@xuanDG2 ~]$ cd /u01/app/oracle/oradata/orcl/
[oracle@xuanDG2 orcl]$ ls
control01.ctl redo02.log sysaux01.dbf temp01.dbf users01.dbf
redo01.log redo03.log system01.dbf undotbs01.dbf
[oracle@xuanDG2 orcl]$ rm -rf *
[oracle@xuanDG2 orcl]$ ls
[oracle@xuanDG2 orcl]$
----删除参数文件
[oracle@xuanDG2 orcl]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
hc_orcl.dat init.ora lkORCL orapworcl spfileorcl.ora
[oracle@xuanDG2 orcl]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[oracle@xuanDG2 dbs]$ ls
hc_orcl.dat init.ora lkORCL orapworcl spfileorcl.ora
[oracle@xuanDG2 dbs]$ rm -rf *
4.2.3 拷贝恢复数据到相应目录
----拷贝数据文件、控制文件、日志文件
cp /zhong/RECOVERED_FILES/u01/app/oracle/oradata/orcl/* /u01/app/oracle/oradata/orcl/.
cp /u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/fast_recovery_area/orcl/control02.ctl
[oracle@xuanDG2 ~]$ ls /u01/app/oracle/oradata/orcl/
control01.ctl redo01.log redo03.log system01.dbf undotbs01.dbf
example01.dbf redo02.log sysaux01.dbf temp01.dbf users01.dbf
----拷贝参数文件、密钥文件
cp /zhong/RECOVERED_FILES/u01/app/oracle/product/11.2.0/db_1/dbs/* /u01/app/oracle/product/11.2.0/db_1/dbs/.
4.2.4 准备启库
sqlplus / as sysdba
startup nomount
alter database mount;
alter database open;
----下面是一些检查
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
SQL> select name,open_mode from v$database;
NAME OPEN_MODE
--------- --------------------
ORCL READ WRITE
select name from v$datafile;
select name from v$tempfile;
select member from v$logfile;
show paraemter undo
show parameter control_files
select userenv('language') from dual;
select * from nls_database_parameters;
4.2.5 启动监听
cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
# (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.22)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
SID_LIST_listener=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=orcl)
(SID_NAME=orcl)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)))
lsnrctl start
alter system register;
lsnrctl status
----配置tns
vim /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.11.22)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
sqlplus sys/sys@orcl as sysdba
4.2.6 启动EM
emctl start dbconsole
emctl stop dbconsole
----em能启动,但是不能访问咯
----这里重新配置em服务
emca -config dbcontrol db -repos recreate
/*
----如果不行,就先删除
emca -deconfig dbcontrol db
emca -repos drop
----然后再创建
emca -repos create
emca -config dbcontrol db
*/
----重建后,em可以正常访问咯
emctl status dbconsole
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30130773/viewspace-2125973/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/30130773/viewspace-2125973/