无归档,无备份,rm误删除所有数据文件恢复

  恢复的原理,请查看关于该恢复主题的第一篇博文:
http://fly1116.blog.51cto.com/8301004/1337681
  恢复过程使用的fly.sh脚本,及其他脚本的简要介绍,请看关于该恢复主题的第二篇博文:

http://fly1116.blog.51cto.com/8301004/1338316


在数据库非归档状态,没有任何的备份情况下,通过操作系统命令rm,误删除了所有数据文件,要如何恢复呢
1、数据库版本11.1.0.7.0和数据库处于非归档状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release11.1.0.7.0- 64bit Production
PL/SQL Release11.1.0.7.0- Production
CORE   11.1.0.7.0     Production
TNSforLinux: Version11.1.0.7.0- Production
NLSRTL Version11.1.0.7.0- Production
SQL> archive log list;
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            /archivelog
Oldest online log sequence    45
Current log sequence          47
SQL>

2、在fly用户下创建fly表,表记录为:2256800

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
SQL> conn fly/fly
Connected.
SQL> create table flyasselect * from dba_objects;
Table created.
SQL> insert into fly select * from fly;
70525rows created.
SQL> /
141050rows created.
SQL> /
282100rows created.
SQL> /
564200rows created.
SQL> /
1128400rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from fly;
COUNT(*)
----------
2256800

3、查看所有数据文件,以及删除所有数据文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
oracle@fly007 :~> cat fly.sh
#!/bin/bash
rman target sys/oracle<<EOF1>/dev/null
crosscheck archivelog all;
deletenoprompt expired archivelog all;
quit
EOF
if[ -f fly_datafile.sh ];then
rm fly_datafile.sh
fi
sqlplus /nolog<<EOF
conn sys/oracleassysdba
@fly.sql
EOF
chmod u+x fly_datafile.sh
oracle@fly007 :~> cat fly.sql
setecho on
col file_name format a80
col name format a100
setlinesize200
select file_name from dba_data_files;
select name from v$archived_log where nameisnotnull;
setecho off
setheading off
setnewpage none
setfeedback off
settermout off
settrimspool on
spool fly_datafile.sh
select'rm'||' '||file_name from dba_data_files;
select'rm'||' '||name from v$archived_log where nameisnotnull;
spool off
quit
oracle@fly007 :~> ./fly.sh
SQL*Plus: Release11.1.0.7.0- Production on Mon Dec921:11:292013
Copyright (c)1982,2008, Oracle.  All rights reserved.
SQL> Connected.
SQL> SQL> col file_name format a80
SQL> col name format a100
SQL>setlinesize200
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/home/oracle/oradata/fly/datafiles/fly01.dbf
/home/oracle/oradata/APPLE/datafile/users02.dbf
/home/oracle/oradata/APPLE/datafile/o1_mf_users_8mfvsbdd_.dbf
/home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf
/home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf
/home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf
/home/oracle/oradata/APPLE/datafile/o1_mf_example_8mfvwlmk_.dbf
/home/oracle/oradata/APPLE/datafile/example02.dbf
/home/oracle/oradata/APPLE/datafile/example03.dbf
/home/oracle/oradata/APPLE/datafile/example04.dbf
/home/oracle/oradata/APPLE/datafile/example05.dbf
/home/oracle/oradata/APPLE/datafile/system03.dbf
/home/oracle/oradata/APPLE/datafile/sysaux03.dbf
13rows selected.
SQL> select name from v$archived_log where nameisnotnull;
no rows selected
SQL>setecho off
Disconnected from Oracle Database 11g Enterprise Edition Release11.1.0.7.0- 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing options
oracle@fly007 :~> cat fly_datafile.sh
rm /home/oracle/oradata/fly/datafiles/fly01.dbf
rm /home/oracle/oradata/APPLE/datafile/users02.dbf
rm /home/oracle/oradata/APPLE/datafile/o1_mf_users_8mfvsbdd_.dbf
rm /home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf
rm /home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf
rm /home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf
rm /home/oracle/oradata/APPLE/datafile/o1_mf_example_8mfvwlmk_.dbf
rm /home/oracle/oradata/APPLE/datafile/example02.dbf
rm /home/oracle/oradata/APPLE/datafile/example03.dbf
rm /home/oracle/oradata/APPLE/datafile/example04.dbf
rm /home/oracle/oradata/APPLE/datafile/example05.dbf
rm /home/oracle/oradata/APPLE/datafile/system03.dbf
rm /home/oracle/oradata/APPLE/datafile/sysaux03.dbf
oracle@fly007 :~> ./fly_datafile.sh
oracle@fly007 :~>

4、fly用户创建表报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
oracle@fly007 :~> sqlplus /nolog
SQL*Plus: Release11.1.0.7.0- Production on Mon Dec921:11:522013
Copyright (c)1982,2008, Oracle.  All rights reserved.
SQL> conn sys/oracleassysdba
Connected.
SQL> conn fly/fly
Connected.
SQL> create table fly008asselect * from dba_objects;
create table fly008asselect * from dba_objects
*
ERROR at line1:
ORA-01116: errorinopening database file7
ORA-01110: data file7:'/home/oracle/oradata/fly/datafiles/fly01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error:2: No such file or directory
Additional information:3

5、停止监听,kill通过监听连接过来的进程

1
2
3
4
5
6
7
oracle@fly007 :~> lsnrctl stop
LSNRCTLforLinux: Version11.1.0.7.0- Production on09-DEC-201321:29:29
Copyright (c)1991,2008, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.46.200.5)(PORT=1521)))
The command completed successfully
oracle@fly007 :~> ps aux | grep LOCAL=NO | grep -v grep | awk'{print $2}'| xargs kill -9
oracle@fly007 :~

6、查看dbw0进程pid,查看哪些数据文件被删除了,拷贝被删除的数据文件到原来的位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
oracle@fly007 :~> ps aux | grep dbw0 | grep -v grep
oracle   1257 0.0 4.53431904366532?      Ss  15:36  0:01ora_dbw0_apple
oracle@fly007 :~> cd /proc/1257/fd
oracle@fly007 :/proc/1257/fd> ls -l | grepdelete
lrwx------1oracle oinstall642013-12-0915:5510-> /home/oracle/product/11g/db/dbs/lkinstapple (deleted)
lrwx------1oracle oinstall642013-12-0915:5522-> /home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5523-> /home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5524-> /home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5525-> /home/oracle/oradata/APPLE/datafile/o1_mf_users_8mfvsbdd_.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5526-> /home/oracle/oradata/APPLE/datafile/o1_mf_example_8mfvwlmk_.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5528-> /home/oracle/oradata/APPLE/datafile/example02.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5529-> /home/oracle/oradata/APPLE/datafile/example03.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5530-> /home/oracle/oradata/APPLE/datafile/example04.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5531-> /home/oracle/oradata/APPLE/datafile/example05.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5532-> /home/oracle/oradata/APPLE/datafile/users02.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5533-> /home/oracle/oradata/APPLE/datafile/system03.dbf (deleted)
lrwx------1oracle oinstall642013-12-0915:5534-> /home/oracle/oradata/APPLE/datafile/sysaux03.dbf (deleted)
lrwx------1oracle oinstall642013-12-0921:1537-> /home/oracle/oradata/fly/datafiles/fly01.dbf (deleted)
oracle@fly007 :/proc/1257/fd> ls -l | grepdelete | grep dbf | awk'{print $8,$10}'> /tmp/copy_datafile.sh
oracle@fly007 :/proc/1257/fd> cat /tmp/copy_datafile.sh
22/home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf
23/home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf
24/home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf
25/home/oracle/oradata/APPLE/datafile/o1_mf_users_8mfvsbdd_.dbf
26/home/oracle/oradata/APPLE/datafile/o1_mf_example_8mfvwlmk_.dbf
28/home/oracle/oradata/APPLE/datafile/example02.dbf
29/home/oracle/oradata/APPLE/datafile/example03.dbf
30/home/oracle/oradata/APPLE/datafile/example04.dbf
31/home/oracle/oradata/APPLE/datafile/example05.dbf
32/home/oracle/oradata/APPLE/datafile/users02.dbf
33/home/oracle/oradata/APPLE/datafile/system03.dbf
34/home/oracle/oradata/APPLE/datafile/sysaux03.dbf
37/home/oracle/oradata/fly/datafiles/fly01.dbf
oracle@fly007 :/proc/1257/fd> sed -i -e"s/^/cp /g"-e"s/$/\ \&/g"/tmp/copy_datafile.sh
oracle@fly007 :/proc/1257/fd> cat /tmp/copy_datafile.sh
cp22/home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf &
cp23/home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf &
cp24/home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf &
cp25/home/oracle/oradata/APPLE/datafile/o1_mf_users_8mfvsbdd_.dbf &
cp26/home/oracle/oradata/APPLE/datafile/o1_mf_example_8mfvwlmk_.dbf &
cp28/home/oracle/oradata/APPLE/datafile/example02.dbf &
cp29/home/oracle/oradata/APPLE/datafile/example03.dbf &
cp30/home/oracle/oradata/APPLE/datafile/example04.dbf &
cp31/home/oracle/oradata/APPLE/datafile/example05.dbf &
cp32/home/oracle/oradata/APPLE/datafile/users02.dbf &
cp33/home/oracle/oradata/APPLE/datafile/system03.dbf &
cp34/home/oracle/oradata/APPLE/datafile/sysaux03.dbf &
cp37/home/oracle/oradata/fly/datafiles/fly01.dbf &
oracle@fly007 :/proc/1257/fd> chmod u+x /tmp/copy_datafile.sh
oracle@fly007 :/proc/1257/fd> /tmp/copy_datafile.sh
oracle@fly007 :/proc/1257/fd> watch -n1"ps aux | grep cp"
Every1.0s: ps aux | grep cp                                                                                                         Mon Dec 921:18:302013
root       45 0.0 0.0     0    0?        S<   Jul24  0:00[kacpid]
root       46 0.0 0.0     0    0?        S<   Jul24  0:00[kacpi_notify]
root     2858 0.0 0.0  2684  520?        Ss   Jul24  0:00/sbin/acpid
root     3052 0.0 0.0  6080  700?        S    Jul24  0:00hald-addon-acpi
root     7444 0.0 0.0 20356 2088?        S    Jul24  0:01/usr/sbin/powersaved -d -f /var/run/acpid.socket -v3
oracle  10123 2.3 0.0  5948  712pts/0   D   21:16  0:02cp23/home/oracle/oradata/APPLE/datafile/o1_mf_sysaux_8mfvsb9t_.dbf
oracle  10124 2.5 0.0  5948  712pts/0   D   21:16  0:02cp24/home/oracle/oradata/APPLE/datafile/o1_mf_undotbs1_8mfvsbbx_.dbf
oracle  10202 0.0 0.0  6400 1356pts/0   S+  21:18  0:00watch -n1ps aux | grep cp
oracle  10206 0.0 0.0  9168 1532pts/0   S+  21:18  0:00sh -c ps aux | grep cp
oracle  10208 0.0 0.0  3976  804pts/0   S+  21:18  0:00grep cp

7、确认在线日志和控制文件没有丢失后,关闭数据库,进行recover database的操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
SQL> conn sys/oracleassysdba
Connected.
SQL> shutdown immediate
ORA-01122: database file1failed verification check
ORA-01110: data file1:'/home/oracle/oradata/APPLE/datafile/o1_mf_system_8mfvsb5r_.dbf'
ORA-01208: data fileisan old version - not accessing current version
SQL> startup mount
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area3240239104bytes
Fixed Size                 2164048bytes
Variable Size           2499807920bytes
Database Buffers         721420288bytes
Redo Buffers              16846848bytes
Database mounted.
SQL> recover database;
Media recovery complete.
SQL> alter database open;
Database altered.
SQL

8、查看表的数据,完全恢复

1
2
3
4
5
6
SQL> conn fly/fly
Connected.
SQL> select count(*) from fly;
COUNT(*)
----------
2256800

转载于:https://my.oschina.net/u/1412027/blog/183314

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值