http://fly1116.blog.51cto.com/8301004/1338316 sql
在數據庫非歸檔狀態,沒有任何的備份狀況下,經過操做系統命令rm,誤刪除了全部數據文件,要如何恢復呢
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>
|
二、在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
|
三、查看全部數據文件,以及刪除全部數據文件 bash
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 :~>
|
四、fly用戶建立表報錯 oracle
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
|
五、中止監聽,kill經過監聽鏈接過來的進程 app
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 :~
|
六、查看dbw0進程pid,查看哪些數據文件被刪除了,拷貝被刪除的數據文件到原來的位置 socket
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
|
七、確認在線日誌和控制文件沒有丟失後,關閉數據庫,進行recover database的操做 ui
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
|
八、查看錶的數據,徹底恢復 spa
1
2
3
4
5
6
|
SQL> conn fly/fly
Connected.
SQL> select count(*) from fly;
COUNT(*)
----------
2256800
|