1:创建数据库备份
通过脚本实现
2:构造数据
SQL> create tablespace orcl_data logging datafile '/u01/app/oracle/oradata/orcl/orcl_data.dbf' size 50m autoextend on next 50m maxsize 2048m extent management local;
Tablespace created.
SQL> SQL> create user orcl identified by orcl default tablespace orcl_data;
User created.
SQL> grant connect,resource,dba to orcl;
Grant succeeded.
SQL> conn orcl/orcl
Connected.
SQL> create table t1(id number,name varchar(20));
Table created.
SQL> insert into t1 values(1,'sun');
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> select * from t1;
ID NAME
---------- --------------------
1 sun
1 sun
1 sun
1 sun
SQL> commit;
Commit complete.
Tablespace created.
SQL> SQL> create user orcl identified by orcl default tablespace orcl_data;
User created.
SQL> grant connect,resource,dba to orcl;
Grant succeeded.
SQL> conn orcl/orcl
Connected.
SQL> create table t1(id number,name varchar(20));
Table created.
SQL> insert into t1 values(1,'sun');
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> select * from t1;
ID NAME
---------- --------------------
1 sun
1 sun
1 sun
1 sun
SQL> commit;
Commit complete.
3:模拟文件丢失
以SYSDBA身份连接并关闭数据库
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
手动模拟数据文件丢失,直接删除刚刚创建的orcl_data数据文件。
尝试重启数据库
SQL> startup
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2217952 bytes
Variable Size 520095776 bytes
Database Buffers 310378496 bytes
Redo Buffers 2412544 bytes
Database mounted.
ORA-01157: 无法标识/锁定数据文件 5 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 5: '/u01/app/oracle/oradata/orcl/orcl_data.dbf'
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl MOUNTED
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2217952 bytes
Variable Size 520095776 bytes
Database Buffers 310378496 bytes
Redo Buffers 2412544 bytes
Database mounted.
ORA-01157: 无法标识/锁定数据文件 5 - 请参阅 DBWR 跟踪文件
ORA-01110: 数据文件 5: '/u01/app/oracle/oradata/orcl/orcl_data.dbf'
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl MOUNTED
4:执行恢复
[oracle@oracle ~]$ export ORACLE_SID=orcl
[oracle@oracle ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on чǚ?? 12? 24 19:11:06 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1362763236, not open)
RMAN> restore datafile 5; ----可以指定文件序号,也可以指定文件的详细路径
Starting restore at 2013-12-24 19:11:50
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
creating datafile file number=5 name=/u01/app/oracle/oradata/orcl/orcl_data.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 2013-12-24 19:11:52
RMAN> recover datafile 5;
Starting recover at 2013-12-24 19:12:59
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2013-12-24 19:13:00
RMAN> alter database open;
database opened
[oracle@oracle ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on чǚ?? 12? 24 19:11:06 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1362763236, not open)
RMAN> restore datafile 5; ----可以指定文件序号,也可以指定文件的详细路径
Starting restore at 2013-12-24 19:11:50
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
creating datafile file number=5 name=/u01/app/oracle/oradata/orcl/orcl_data.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 2013-12-24 19:11:52
RMAN> recover datafile 5;
Starting recover at 2013-12-24 19:12:59
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 2013-12-24 19:13:00
RMAN> alter database open;
database opened
切换回SQL*PLUS命令环境下,查看当前数据库状态和数据
[oracle@oracle ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on 星期二 12月 24 19:18:45 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
SQL> conn orcl/orcl
Connected.
SQL> select * from t1;
ID NAME
---------- --------------------
1 sun
1 sun
1 sun
1 sun
SQL>
SQL*Plus: Release 11.2.0.1.0 Production on 星期二 12月 24 19:18:45 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
orcl OPEN
SQL> conn orcl/orcl
Connected.
SQL> select * from t1;
ID NAME
---------- --------------------
1 sun
1 sun
1 sun
1 sun
SQL>
5:关于rman的restore和recover区别
restore 是还原,文件级的恢复。就是物理文件还原。
recover 是恢复,数据级的恢复。逻辑上恢复,比如应用归档日志、重做日志,全部同步,保持一致。
用我自己的土话讲就是,用restore先把备份文件拷贝到数据库目录下进行替换,再用recover经过一些处理,数据库就恢复正常了。
1、restore 命令:用于还原已经备份的数据文件。
(1)、restore database 还原所有的数据文件。
(2)、restore tablespace 还原特定表空间的数据文件。
(3)、restore datafile 还原特定的数据文件。
(4)、restore controlfile 还原控制文件。
(5)、restore archivelog 还原归档日志文件。
2、recover 命令:当数据库需要应用归档日志文件恢复数据文件时,使用recover命令。使用该命令数据库系统会自动应用归档的日志文件。
(1)、recover database 恢复所有的数据文件。
(2)、recover tablespace 恢复特定表空间的数据文件。
(3)、recover datafile 恢复特定的数据文件。
recover 是恢复,数据级的恢复。逻辑上恢复,比如应用归档日志、重做日志,全部同步,保持一致。
用我自己的土话讲就是,用restore先把备份文件拷贝到数据库目录下进行替换,再用recover经过一些处理,数据库就恢复正常了。
1、restore 命令:用于还原已经备份的数据文件。
(1)、restore database 还原所有的数据文件。
(2)、restore tablespace 还原特定表空间的数据文件。
(3)、restore datafile 还原特定的数据文件。
(4)、restore controlfile 还原控制文件。
(5)、restore archivelog 还原归档日志文件。
2、recover 命令:当数据库需要应用归档日志文件恢复数据文件时,使用recover命令。使用该命令数据库系统会自动应用归档的日志文件。
(1)、recover database 恢复所有的数据文件。
(2)、recover tablespace 恢复特定表空间的数据文件。
(3)、recover datafile 恢复特定的数据文件。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28698327/viewspace-1065457/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28698327/viewspace-1065457/