rman使用文档(备份脚本和恢复)

rman备份恢复模拟
全备脚本如下:
#!/bin/bash
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
begin=`date +'%Y-%m-%d %H:%M:%S'`
echo '------backup begin------ ' $begin
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/11g
export ORACLE_SID=pu


/u01/11g/bin/rman target / <<EOF
run {
configure retention policy to recovery window of 8 days;
configure controlfile autobackup on;
configure controlfile autobackup format for device type disk to '/u01/rmanbackup/controlfile_%F';
allocate channel c1 type disk;
allocate channel c2 type disk;
backup   format '/u01/rmanbackup/all_db_%d_%T_t%t_s%s_p%p' database;
sql 'alter system archive log current';
backup archivelog all delete input format '/u01/rmanbackup/all_log_%d_%T_t%t_s%s_p%p';
release channel c1;
release channel c2;
crosscheck backup;
delete noprompt obsolete;
}
exit;
EOF


end=`date +'%Y-%m-%d %H:%M:%S'`
echo '-----backup over-----'  $end



运行脚本生成以下文件


[oracle@oracle ~]$ ls /u01/rmanbackup/
all_db_PU_20160505_t911035475_s211_p1   all_log_PU_20160505_t911035552_s215_p1
all_db_PU_20160505_t911035475_s212_p1   controlfile_c-2741963487-20160505-00
all_log_PU_20160505_t911035552_s214_p1  controlfile_c-2741963487-20160505-01


第一步:模拟控制文件丢失
找出控制文件并删除select name from v$controlfile;


SQL> shutdown immediate
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/oracle/oradata/pu/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> select open_mode from v$database;
select open_mode from v$database
                      *
ERROR at line 1:
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/oracle/oradata/pu/control01.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
上面是我在开启的时候删除了控制文件,这个是很危险的,立即拷贝复原
SQL> startup
ORACLE instance started.


Total System Global Area  413372416 bytes
Fixed Size                  2228904 bytes
Variable Size             348130648 bytes
Database Buffers           54525952 bytes
Redo Buffers                8486912 bytes
ORA-00205: error in identifying control file, check alert log for more info
这个时候可以看到数据库无法打开,提示检查控制文件和告警日志,日常控制文件至少有两个以上,这里我们全部删除掉
开始恢复


RMAN> restore controlfile from '/u01/rmanbackup/controlfile_c-2741963487-20160505-01';   指定任何一个备份的控制文件都可以


Starting restore at 05-MAY-16
using channel ORA_DISK_1


channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/oracle/oradata/pu/control01.ctl
output file name=/u01/oracle/fast_recovery_area/pu/control02.ctl
Finished restore at 05-MAY-16
查看控制文件:


[oracle@oracle ~]$ ls /u01/oracle/oradata/pu/
control01.ctl  redo02.log  sysaux01.dbf  temp01.dbf     users01.dbf
redo01.log     redo03.log  system01.dbf  undotbs01.dbf
[oracle@oracle ~]$ ls /u01/oracle/fast_recovery_area/
pu  PU
[oracle@oracle ~]$ ls /u01/oracle/fast_recovery_area/pu/
control02.ctl
已经全部恢复


SQL> alter database mount;


Database altered.


RMAN> recover database;


Starting recover at 05-MAY-16
released channel: ORA_DISK_1
Starting implicit crosscheck backup at 05-MAY-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=133 device type=DISK
Crosschecked 5 objects
Finished implicit crosscheck backup at 05-MAY-16


Starting implicit crosscheck copy at 05-MAY-16
using channel ORA_DISK_1
Finished implicit crosscheck copy at 05-MAY-16


searching for all files in the recovery area
cataloging files...
no files cataloged


using channel ORA_DISK_1
RMAN-06900: WARNING: unable to generate V$RMAN_STATUS or V$RMAN_OUTPUT row
RMAN-06901: WARNING: disabling update of the V$RMAN_STATUS and V$RMAN_OUTPUT rows
ORACLE error from target database:
ORA-19922: there is no parent row with id 0 and level 1




starting media recovery


archived log for thread 1 with sequence 42 is already on disk as file /u01/oracle/oradata/pu/redo03.log
archived log file name=/u01/oracle/oradata/pu/redo03.log thread=1 sequence=42
media recovery complete, elapsed time: 00:00:00
Finished recover at 05-MAY-16


RMAN> alter database open;


RMAN-00571: ========
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值