8.RMAN备份EXAMPLE表空间
RMAN> backup tablespace EXAMPLE;
Starting backup at 21-DEC-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD1/example01.dbf
channel ORA_DISK_1: starting piece 1 at 21-DEC-16
channel ORA_DISK_1: finished piece 1 at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T102837_d5mt6oxv_.bkp tag=TAG20161221T102837 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 21-DEC-16
Starting Control File and SPFILE Autobackup at 21-DEC-16
piece handle=/u01/app/oracle/fast_recovery_area/PROD1/autobackup/2016_12_21/o1_mf_s_931170520_d5mt6s1z_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 21-DEC-16
9.再次向测试表t插入10记录,然后将EXAMPLE的数据文件删除
SYS@PROD1>create table scott.t(x int) tablespace EXAMPLE;
Table created.
SYS@PROD1>insert into scott.t select rownum from dual connect by rownum<=10;
10 rows created.
SYS@PROD1>commit;
Commit complete.
SYS@PROD1>select count(*) from scott.t;
COUNT(*)
----------
10
SYS@PROD1>select file_name from dba_data_files where tablespace_name='EXAMPLE';
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/PROD1/example01.dbf
SYS@PROD1>! rm /u01/app/oracle/oradata/PROD1/example01.dbf
SYS@PROD1>! ls /u01/app/oracle/oradata/PROD1/example01.dbf
ls: /u01/app/oracle/oradata/PROD1/example01.dbf: No such file or directory
10.再次向测试表t插入10记录
此时,有些朋友可能觉得奇怪,表t所使用的表空间的数据文件已经丢失了,怎么数据写入成功了呢?
虽然我们的commit成功了,但dbwr进程实际上还没有工作(可以肯定的是,redo中一定记录了本次操作),
不过已经纳入到写入队列中,dbwr并不着急,在慢慢的处理已经提交且还没有写入磁盘的数据。
SYS@PROD1>insert into scott.t select rownum from dual connect by rownum<=10;
10 rows created.
SYS@PROD1>commit;
Commit complete.
11.手工触发一次检查点事件
SYS@PROD1>alter system checkpoint;
System altered.
12.因为之前利用RMAN备份过EXAMPLE表空间,我们可以使用RMAN进行恢复,将数据库启动到mount模式下
SYS@PROD1>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@PROD1>startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 520096848 bytes
Database Buffers 310378496 bytes
Redo Buffers 2371584 bytes
Database mounted.
RMAN> restore tablespace example;
Starting restore at 21-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 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 00005 to /u01/app/oracle/oradata/PROD1/example01.dbf
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T102837_d5mt6oxv_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/PROD1/backupset/2016_12_21/o1_mf_nnndf_TAG20161221T102837_d5mt6oxv_.bkp tag=TAG20161221T102837
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
Finished restore at 21-DEC-16
RMAN> recover tablespace example;
Starting recover at 21-DEC-16
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 21-DEC-16
SYS@PROD1>alter database open;
Database altered.
验证
SYS@PROD1>select count(*) from scott.t;
COUNT(*)
----------
20
SYS@PROD1>! ls /u01/app/oracle/oradata/PROD1/example01.dbf
/u01/app/oracle/oradata/PROD1/example01.dbf
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31400681/viewspace-2131101/
,如需转载,请注明出处,否则将追究法律责任。