普通表空间的热备及模拟故障恢复
Posted Tomatoes
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了普通表空间的热备及模拟故障恢复相关的知识,希望对你有一定的参考价值。
创建目录:[[email protected] ~]$ mkdir hot_bk
先查看归档是否打开(热备一定要打开)
SQL> archive log list
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 93
Current log sequence 96
现在开启归档(mount状态下):
SQL> alter database archivelog;
Database altered.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
Oldest online log sequence 93
Next log sequence to archive 96
Current log sequence 96
查看数据库中表空间文件:
SQL> select file_name,tablespace_name from dba_data_files;
FILE_NAME TABLESPACE
-------------------------------------------------- ----------
/u01/app/oracle/oradata/PROD/system01.dbf SYSTEM
/u01/app/oracle/oradata/PROD/sysaux01.dbf SYSAUX
/u01/app/oracle/oradata/PROD/undotbs01.dbf UNDOTBS1
/u01/app/oracle/oradata/PROD/users01.dbf USERS
/u01/app/oracle/oradata/PROD/test101.dbf TEST1
/u01/app/oracle/oradata/PROD/test102.dbf TOOL
/u01/app/oracle/oradata/PROD/user02.dbf USERS
7 rows selected.
开启users表空间热备:
SQL> alter tablespace USERS begin backup;
Tablespace altered.
开始备份:
SQL> !cp /u01/app/oracle/oradata/PROD/user02.dbf /home/oracle/hot_bk
查看备份文件和备份信息:
[[email protected] ~]$ cd /home/oracle/hot_bk/
[[email protected] hot_bk]$ ls
user02.dbf
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 0
2 NOT ACTIVE 0
3 NOT ACTIVE 0
4 ACTIVE 373801 27-SEP-16
6 NOT ACTIVE 0
7 ACTIVE 373801 27-SEP-16
6 rows selected.
关闭备份状态:
SQL> alter tablespace users end backup;
Tablespace altered.
再次查看备份信息:
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 0
2 NOT ACTIVE 0
3 NOT ACTIVE 0
4 NOT ACTIVE 373801 27-SEP-16
6 NOT ACTIVE 0
7 NOT ACTIVE 373801 27-SEP-16
6 rows selected.
模拟故障,删除users表空间:
[[email protected] hot_bk]$ cd /u01/app/oracle/oradata/PROD
[[email protected] PROD]$ ls
initPROD.ora redo03a.log temp_01.dbf test102.dbf
ora_control1.ctl redo04a.log temp01.dbf undotbs01.dbf
redo01a.log sysaux01.dbf temp_02.dbf user02.dbf
redo02a.log system01.dbf test101.dbf users01.dbf
[[email protected] PROD]$ rm user02.dbf
现在开始进行恢复:
首先将要恢复的表空间处于脱机状态:
SQL> alter database datafile ‘/u01/app/oracle/oradata/PROD/user02.dbf‘ offline;
Database altered.
开始恢复数据文件:
[[email protected] PROD]$ cd /home/oracle/hot_bk/
[[email protected] hot_bk]$ ls
user02.dbf
[[email protected] hot_bk]$ cp user02.dbf /u01/app/oracle/oradata/PROD
[[email protected] hot_bk]$ cd /u01/app/oracle/oradata/PROD
[[email protected] PROD]$ ls
initPROD.ora redo03a.log temp_01.dbf test102.dbf
ora_control1.ctl redo04a.log temp01.dbf undotbs01.dbf
redo01a.log sysaux01.dbf temp_02.dbf user02.dbf
redo02a.log system01.dbf test101.dbf users01.dbf
用recover命令进行介质恢复:
SQL> recover datafile 7;
Media recovery complete.
将表空间改成联机状态:
SQL> alter database datafile ‘/u01/app/oracle/oradata/PROD/users01.dbf‘
2 online;
Database altered.
恢复完毕。
以上是关于普通表空间的热备及模拟故障恢复的主要内容,如果未能解决你的问题,请参考以下文章
服务器存储数据恢复华为OceanStor某型号存储raid5硬盘故障离线,热备盘同步数据失败导致raid崩溃的数据恢复案例