Linux服务器根目录被误删后,找回oracle数据文件进行异机恢复
前两天,看见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/
Linux服务器根目录被误删后,找回oracle数据文件进行异机恢复相关推荐
- Oracle RMAN备份和异机恢复
RMAN备份 备份策略 每周日2点数据库全备 每天4点备份归档 以下仅为备份脚本, 没有定时任务脚本 准备工作 查看数据库是否处于归档模式: archive log list; 进入sqlpuls: ...
- linux mysql异机备份_Linux环境下oracle数据库Rman备份异机恢复
备份的数据库和要恢复的数据库OS和数据库的版本均一致,恢复的目录也均一致! 备份数据库: RMAN> backup format '/home/oracle/scripts/full_prod. ...
- oracle查看数据被谁删掉了,oracle数据文件被误删恢复
----数据文件被误恢复方法有两种.如果发现数据文件被删除咯,此时数据库是open状态,可以直接通过句柄恢复,如果发现数据库已经宕机了,就只能用其他方式咯.具体方法,如下: 1.利用句柄恢复数据文件 ...
- oracle ora 19698,RMAN异机还原遭遇ORA-19698错误案例
实验环境: 操作系统 :Oracle Linux Server release 5.7 64 bit 数据库版本:Oracle Database 10g Release 10.2.0.4.0 - ...
- 增加linux服务器根目录空间大小方法
增加linux服务器根目录空间大小方法,由于没做分区照成存储空间不足 步骤: 1.df -hl --查看系统文件分配和使用情况 Filesystem Size Used Avail Use% Moun ...
- linux dump命令 异机,Oracle 11.2.0.4 从单实例,使用RMAN 异机恢复到RAC
Oracle 11.2.0.4从单实例,使用RMAN异机恢复到RAC 注意: (1)迁移的2个db版本版本要一致.包括小版本. (2)RMAN异机恢复的时候,db_name必须相同.如果说要想改成其他 ...
- 快速找出Linux服务器上不该存在恶意或后门文件
转载来源 :如何快速找出Linux服务器上不该存在恶意或后门文件 :https://www.2cto.com/article/201805/748965.html 如何快速找出Linux服务器上不该存 ...
- oracle物理文件删除如何恢复,Oracle数据文件物理删除后的恢复
做系统管理的都是这样,难免会误删文件,某天要是把某个Oracle数据文件删除,那该如何恢复呢?(这里数据库是OPEN的,并且未关闭) 建立测试表空间 创建测试用户 插入测试数据 删除数据文件 恢复数据 ...
- oracle故障一例,Oracle 10g异机恢复后EM无法启动故障处理一例
之前在自己的测试环境上做了个异机恢复,原来的库上是配置过EM的,但是在恢复的库上去启动EM就报错了,下面看具体解决过程: PS:原主机名为zlm,恢复出来的主机名为bak [root@bak ~]# ...
最新文章
- Xen虚拟化之一:Xen环境组件详解
- c语言实战1200例 pdf6,C语言程序设计6.6.2.pdf
- 关于计算机 硬件方方面的整理
- Mybatis框架的连接池配置
- qtablewidget固定一列滚动_简单易懂,最全滚动轴承基本知识汇总
- [笔记][原创]74HC595芯片使用方法介绍
- 数据库系统概念第六版 第八章练习题 2 3 9
- 计算机图形学红绿蓝组合颜色,二、颜色_计算机图形学(部分章节二)_ppt_大学课件预览_高等教育资讯网...
- 数据归档方案(带流程图)
- 985高校计算机专业炉气分数,【原创】外地985高校专业录取分数解析(一)
- java基础jdk,jre,jvm作业-答案
- android 指纹比对方法,指纹识别功能方面对比_手机Android频道-中关村在线
- mac 10.11 brew php71,MAC OS X 10.11.4下载-OS X 10.11正式版下载 V10.11.6-PC6苹果网
- 心脑血管应该注意那些?
- ViewFlipper实现带索引效果的自动播放也可手动滑动的广告栏
- 个人奋斗动力源的一些感想
- spring中读不到配置文件问题
- ctfshow SSRF web351-web360 wp
- RASA如何处理多意图
- 【财务数字化管理】金蝶ERP系统助力企业数字化转型