【oracle】rman 简单的数据文件恢复

Posted on 2012-12-19 16:01  雅飞士  阅读(341)  评论(0编辑  收藏  举报

本实验简单介绍数据文件损坏后的恢复。

1.创建测试环境:建测试表空间和测试用户。

SQL> create tablespace tbs_rman datafile '/oradata/orcl/tbs_rman.dbf' size 5M autoextend off;
Tablespace created.
SQL> create user testrman identified by a1234 default tablespace tbs_rman;
User created.
SQL> grant dba to testrman;
Grant succeeded.
SQL> conn testrman/a1234;
Connected.
SQL> create table test1 (id number);
Table created.
SQL> insert into test1 values(1);
1 row created.
SQL> insert into test1 values(2);
1 row created.
SQL> commitl
SP2-0042: unknown command "commitl" - rest of line ignored.
SQL> commit;
Commit complete.
SQL> select * from test1;
        ID
----------
         1
         2
SQL>

2.由于我的库没开归档,重启到mount做个全库备份:

空间不足,先删除之前的备份:

RMAN> delete backup;

备份全库:

RMAN> backup database  format '/backup/fulldb/%U';

查看备份:

RMAN> list backup;

3.删除数据文件:

[oracle@yfs orcl]$ ls | grep rman
tbs_rman.dbf
[oracle@yfs orcl]$ rm tbs_rman.dbf
[oracle@yfs orcl]$ ls | grep rman 
[oracle@yfs orcl]$

4.查看数据状态,并open之:

SQL> select instance_name,status from v$instance;
INSTANCE_NAME    STATUS
---------------- ------------
orcl             MOUNTED
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 241 - see DBWR trace file

ORA-01110: data file 241: '/oradata/orcl/tbs_rman.dbf'

出错喽。

下面该rman出场了。

5. rman先修复,再恢复:

RMAN> restore datafile '/oradata/orcl/tbs_rman.dbf';
Starting restore at 20121217152919
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=18 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=17 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 00241 to /oradata/orcl/tbs_rman.dbf
channel ORA_DISK_1: reading from backup piece /backup/fulldb/2dnt3jv6_1_1
channel ORA_DISK_1: piece handle=/backup/fulldb/2dnt3jv6_1_1 tag=TAG20121217T152315
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 20121217152922
RMAN> recover datafile '/oradata/orcl/tbs_rman.dbf';
Starting recover at 20121217152935
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 20121217152936

6.打开数据库:

SQL> alter database open;

Database altered.

7 查看数据:

SQL> conn testrman/a1234
Connected.
SQL> select * from test1;
        ID
----------
         1

         2

OK,恢复的不错哦。

8.清理测试环境:

SQL> drop tablespace tbs_rman including contents and datafiles;
Tablespace dropped.
SQL> drop user testrman cascade;

User dropped

--EOF

Copyright © 2024 雅飞士
Powered by .NET 9.0 on Kubernetes