欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

RMAN进行表空间的备份和恢复

程序员文章站 2022-06-13 23:19:17
...

1、创建表空eygle 2、创建用户eygle,隶属于eygle表空间;赋予用户DBA权限 3、egyle用户登录DB,创建表test_egyle 4、rman备份eg

1、创建表空eygle

2、创建用户eygle,隶属于eygle表空间;赋予用户DBA权限

3、egyle用户登录DB,创建表test_egyle

4、rman备份egyle表空间

RMAN> backup tablespace eygle tag="ey_first";

Starting backup at 15-FEB-14
using target database control file instead of recovery catalog ----使用目标库控制文件替代恢复目录
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=317 device type=DISK
channel ORA_DISK_1: starting full datafile backup set ----启动full数据文件备份集
channel ORA_DISK_1: specifying datafile(s) in backup set ----指定备份集中的数据文件
input datafile file number=00029 name=/home/Oracle/oradata/temp/eygle.f ----输入数据文件
channel ORA_DISK_1: starting piece 1 at 15-FEB-14
channel ORA_DISK_1: finished piece 1 at 15-FEB-14
piece handle=/home/oracle/app/flash_recovery_area/ORA11G/backupset/2014_02_15/o1_mf_nnndf_EY_FIRST_9hxyglp2_.bkp tag=EY_FIRST comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 15-FEB-14

Starting Control File and SPFILE Autobackup at 15-FEB-14 ----库结构发生变化时,,controlfile和spfile将自动备份
piece handle=/home/oracle/app/flash_recovery_area/ORA11G/autobackup/2014_02_15/o1_mf_s_839597011_9hxygn23_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 15-FEB-14

6、sys用户登录DB,修改表空间egyle状态offline

SQL> alter tablespace eygle offline;

7、破坏表空间egyle对应数据文件,如删除或改名

oracle@linux:~/oradata/temp> mv eygle.f eygle_bak.f

8、修改表空间egyle状态online,报错

SQL> alter tablespace eygle online;
alter tablespace eygle online
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 29 - see DBWR trace file
ORA-01110: data file 29: '/home/oracle/oradata/temp/eygle.f'

9、rman恢复

RMAN> restore tablespace eygle; 将备份文件恢复到原先位置

Starting restore at 15-FEB-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=261 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 00029 to /home/oracle/oradata/temp/eygle.f
channel ORA_DISK_1: reading from backup piece /home/oracle/app/flash_recovery_area/ORA11G/backupset/2014_02_15/o1_mf_nnndf_EY_FIRST_9hxyglp2_.bkp
channel ORA_DISK_1: piece handle=/home/oracle/app/flash_recovery_area/ORA11G/backupset/2014_02_15/o1_mf_nnndf_EY_FIRST_9hxyglp2_.bkp tag=EY_FIRST
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 15-FEB-14

RMAN> recover tablespace eygle; 执行恢复操作

Starting recover at 15-FEB-14
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 15-FEB-14

10、检验恢复结果

SQL> alter tablespace eygle online;

Tablespace altered.

推荐阅读:

RMAN 配置归档日志删除策略

Oracle基础教程之通过RMAN复制数据库

RMAN备份策略制定参考内容

RMAN备份学习笔记

Oracle数据库备份加密 RMAN加密