oracle rman 备份与还原

博客介绍了Oracle中restore(文件级恢复)和recover(数据级恢复)的概念,前者是从备份读出恢复数据,后者是在数据文件还原后用日志恢复。还提及完备脚本、差异备份脚本等操作,以及recover失败的原因和使用scn位置补充还原、开启数据库等内容。

restore: 还原(文件级恢复),与backup相对,从备份读出恢复备份的数据。

recover: 恢复(数据级恢复),指在数据文件成功还原之后,使用归档日志和在线重做日志对数据文件进行恢复,主要前滚与回滚两个动作。最常见的就是实例恢复。

完备脚本

#!/bin/bash

export ORACLE_SID=db3
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/oracle/product/11.2.0/dbhome_1

$ORACLE_HOME/bin/rman target / << EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
crosscheck archivelog all;

backup as compressed backupset database format '/dbbackup/full_dbbackup_%T_%d_%U';

sql 'alter system archive log current';
backup as compressed backupset filesperset 10 format '/dbbackup/Arch_%d_%T_%s.bak' archivelog all;

delete noprompt obsolete;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
EOF

差异备份脚本

#!/bin/bash

export ORACLE_SID=sqmesdb3
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=/u01/oracle/product/11.2.0/dbhome_1

pscnt=`ps -ef | grep rman | grep -v grep | wc -l`
echo "archivebackupprocesscount:$pscnt"
if [ $pscnt -gt 0 ];then
   echo "`date`exitarchivelogbackup!"
   exit 0
else
   $ORACLE_HOME/bin/rman target / << EOF
   run{
#   backup as compressed backupset archivelog all format '/dbbackup/archivelog_backup_%T_%d_%U' not backed up 2 times;
   # backup as compressed backupset archivelog all format '/dbbackup/archivelog_backup_%T_%d_%U';
   delete noprompt archivelog all completed before 'sysdate-7';
   }
EOF
fi

还原control文件
最好还原完备的control file

RMAN> restore controlfile from '/dbbackup/c-1644883930-20220813-01';

异机还原脚本

catalog start with '/dbbackup/';  # 指定日志路径
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
RESTORE DATABASE ;
#recover database using backup controlfile until cancel;
recover database until time "to_date('2022-01-27 20:40:00','yyyy-mm-dd hh24:mi:ss')";
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}

如果recover失败
可能失败, 因为archive log找不到

报错内容:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/23/2022 15:48:19
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 55081 and starting SCN of 89990540475

使用scn位置补充还原

RMAN> recover database until scn 89990540475;

Starting recover at 23-AUG-22
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=129 device type=DISK

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

Finished recover at 23-AUG-22

开启数据库

[oracle@sqmesdbbk ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 23 16:43:44 2022

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> alter database open resetlogs;

Database altered.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值