数据库备份恢复--恢复普通表空间上的数据文件
Posted bondait
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据库备份恢复--恢复普通表空间上的数据文件相关的知识,希望对你有一定的参考价值。
恢复前提:
1.数据库存在完整可用的备份
2.手动删除user表空间的数据文件(非system和undo表空间)
影响范围:
1.数据库正常读写
2.数据文件对象无法访问
3.需要将表空间脱机,一段时间内对象无法访问
1.查看数据库数据文件
[email protected]> 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.删除数据文件
[[email protected] ~]$ rm -rf /u01/app/oracle/oradata/OCP/datafile/o1_mf_users_fb8w44gz_.dbf
[[email protected] ~]$
3.访问数据文件上的对象
[[email protected] ~]$ 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
[email protected]> 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.查看数据库的状态
[email protected]> 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.验证表空间对象是否可以访问
[email protected]> connect wsl/wsl
Connected.
[email protected]> select * from t1;
no rows selected
以上是关于数据库备份恢复--恢复普通表空间上的数据文件的主要内容,如果未能解决你的问题,请参考以下文章