1. 程式人生 > >數據庫備份恢復--恢復普通表空間上的數據文件

數據庫備份恢復--恢復普通表空間上的數據文件

enter cif chan sequence ror tin dir cto family

恢復前提

1.數據庫存在完整可用的備份

2.手動刪除user表空間的數據文件(非system和undo表空間)

影響範圍:

1.數據庫正常讀寫

2.數據文件對象無法訪問

3.需要將表空間脫機,一段時間內對象無法訪問

1.查看數據庫數據文件

SYS@ocp> select name from v$datafile;

NAME
------------------------------------------------------------------------------------------------------------------------
/u01/app/oracle/oradata/OCP/datafile/o1_mf_system_fb8w44fm_.dbf


/u01/app/oracle/oradata/OCP/datafile/o1_mf_sysaux_fb8w44g7_.dbf
/u01/app/oracle/oradata/OCP/datafile/o1_mf_undotbs1_fb8w44gd_.dbf
/u01/app/oracle/oradata/OCP/datafile/o1_mf_users_fb8w44gz_.dbf
/u01/app/oracle/oradata/OCP/datafile/o1_mf_example_fb8w6fnx_.dbf

2.刪除數據文件

[oracle@bonda1 ~]$ rm -rf /u01/app/oracle/oradata/OCP/datafile/o1_mf_users_fb8w44gz_.dbf
[oracle@bonda1 ~]$

3.訪問數據文件上的對象

[oracle@bonda1 ~]$ sqlplus abc/cba

SQL*Plus: Release 11.2.0.4.0 Production on Sat Sep 8 21:29:50 2018

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

WSL@ocp> select * from t1;
select * from t1
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: ‘/u01/app/oracle/oradata/OCP/datafile/o1_mf_users_fb8w44gz_.dbf‘
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

3.查看數據庫的狀態
WSL@ocp> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

4.整個表空間置於offline狀態

RMAN> sql "alter tablespace users offline immediate";

using target database control file instead of recovery catalog
sql statement: alter tablespace users offline immediate

5.還原users表空間

RMAN> restore tablespace users;

Starting restore at 08-SEP-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=929 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/OCP/datafile/o1_mf_users_fb8w44gz_.dbf
channel ORA_DISK_1: reading from backup piece /u01/FRA/OCP/backupset/2018_09_07/o1_mf_nnndf_TAG20180907T082038_fs4v8q06_.bkp
channel ORA_DISK_1: piece handle=/u01/FRA/OCP/backupset/2018_09_07/o1_mf_nnndf_TAG20180907T082038_fs4v8q06_.bkp tag=TAG20180907T082038
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 08-SEP-18

6.恢復users表空間,應用歸檔和聯機重做日誌

RMAN> recover tablespace users;

Starting recover at 08-SEP-18
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 125 is already on disk as file /u01/FRA/OCP/archivelog/2018_09_07/o1_mf_1_125_fs6cvq5f_.arc
archived log for thread 1 with sequence 126 is already on disk as file /u01/FRA/OCP/archivelog/2018_09_08/o1_mf_1_126_fs8v96b3_.arc
channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=124
channel ORA_DISK_1: reading from backup piece /u01/FRA/OCP/backupset/2018_09_07/o1_mf_annnn_TAG20180907T082317_fs4vfogg_.bkp
channel ORA_DISK_1: piece handle=/u01/FRA/OCP/backupset/2018_09_07/o1_mf_annnn_TAG20180907T082317_fs4vfogg_.bkp tag=TAG20180907T082317
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
archived log file name=/u01/FRA/OCP/archivelog/2018_09_08/o1_mf_1_124_fs91q1b8_.arc thread=1 sequence=124
channel default: deleting archived log(s)
archived log file name=/u01/FRA/OCP/archivelog/2018_09_08/o1_mf_1_124_fs91q1b8_.arc RECID=121 STAMP=986337313
media recovery complete, elapsed time: 00:00:03
Finished recover at 08-SEP-18

7.將users表空間online

RMAN> sql "alter tablespace users online";

sql statement: alter tablespace users online

8.驗證表空間對象是否可以訪問

SYS@ocp> connect wsl/wsl
Connected.
WSL@ocp> select * from t1;

no rows selected

數據庫備份恢復--恢復普通表空間上的數據文件