备份:
备注:
rman恢复需要同版本数据库软件,同环境变量,同SID,尽可能路径一致,可以跨操作系统平台 。
1、脚本
##用于每个星期的全量日志备份
#!/bin/bash
. /home/oracle/.bash_profile
dt=`date +%Y%m%d`
logdir=/u11g/backup/log
if [ -d ${logdir} ]
then
sleep 1
else
mkdir -p ${logdir}
fi
logfile=${logdir}/backup_${dt}.trc
echo "------------`date '+%Y-%m-%d %H:%M'`---Start Backup----------------">>$logfile
rman target / log=$logfile <<EOF
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired backup;
delete noprompt obsolete; ---删除历史的备份
run
{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as compressed backupset Database
Format '/u11g/backup/bak_db_%s_%p_%T' filesperset=1
plus Archivelog filesperset=20 Format '/u11g/backup/bak_archivelog_%s_%p_%T';
Backup current controlfile format '/u11g/backup/bak_ctl_%s_%p_%T';
}
exit;
EOF
echo "------------`date '+%Y-%m-%d %H:%M'`---End Backup----------------">>$logfile
find ${logdir}/*.trc -ctime +20|xargs rm -r
2、上传备份文件到测试服务器:
scp /u11g/backup/* oracle@192.168.1.201:/u01/backup
恢复:
shell:
rman target /
rman:
startup nomount;
restore controlfile from "/u01/backup/bak_ctl_XXX";
sql 'alter database mount';
catalog start with '/u01/backup';
run{
set newname for datafile 1 to '/home/oracle/db/SYSTEM01.DBF';
set newname for datafile 2 to '/home/oracle/db/SYSAUX01.DBF';
set newname for datafile 3 to '/home/oracle/db/UNDOTBS01.DBF';
set newname for datafile 4 to '/home/oracle/db/USERS01.DBF';
set newname for datafile 5 to '/home/oracle/db/YEWU.DBF';
set newname for datafile 6 to '/home/oracle/db/AFD.DBF';
set newname for datafile 7 to '/home/oracle/db/example01.DBF';
restore database;
switch datafile all;
}
--下面命令应该不会成功,记录报错的scn号
recover database;
--把上面的scn替换到下面
run {
set until scn 7610612;
recover database;
}
sqlplus
--记录redo和temp路径
select * from v$logfile;
select name from v$tempfile;
--修改redo和temp到新路径
alter database rename file '/u01/app/oracle/oradata/redo01.log' to '/home/oracle/db/redo01.log';
alter database rename file '/u01/app/oracle/oradata/redo02.log' to '/home/oracle/db/redo02.log';
alter database rename file '/u01/app/oracle/oradata/redo03.log' to '/home/oracle/db/redo03.log';
alter database rename file '/u01/app/oracle/oradata/temp01.DBF' to '/home/oracle/db/temp01.DBF';
rman执行不完全恢复
alter database open resetlogs;