一、 实验环境
db_A:192.168.0.3 db_B:192.168.0.4
db_A为生产数据库,db_B为后备(不运行);两个数据库的环境完全一样。
二、操作
1.db_A的操作
在db_A上进行rman的0级备份
$rman target /
RMAN>backup incremental level=0 database format='/oradata/back/%u';
添加计划任务执行以下脚本:
---------------------------------------------------------------------
db_rsync.sh
#!/bin/sh
#keep tow db Synchronous
ORACLE_HOME=/oracle/app/oracle/product/10.2.0/db_1
bak_dir=/oradata/back
archive_dir=/oradata/arch
dest_db=oracle@192.168.0.4
passwd=ufsoft
ls -l $bak_dir | awk '{print $NF}'|sed '1d'>list1
ls -l $archive_dir | awk '{print $NF}'|sed '1d'>list2
Rsync_exec1(){
expect -c "
set timeout 7200;
spawn rsync -rpogtv --files-from=list1 $bak_dir $dest_db:$bak_dir
expect {
\"*yes/no*\" {send \"yes\r\";exp_continue}
\"*password*\" {send \"$passwd\r\";}
}
expect eof;"
Rsync_exec2(){
expect -c "
set timeout 7200;
spawn rsync -rpogtv --files-from=list2 $archive_dir $dest_db:$archive_dir
expect {
\"*password*\" {send \"$passwd\r\";}
}
expect eof;"
}
Rsync_exec1
Rsync_exec2
rm -f list1 list2
---------------------------------------------------------------------
2.db_B的操作
$ echo "db_name=ora10g">$ORACLE_HOME/dbs/initora10g.ora
$ sqlplus / as sysdba
SQL> startup nomount
$ls /oradata/back #查看从db_A上传过来的备份文件,其中大小比较小的为参数文件和控制文件的备份,最大的为数据文件的备份。可以在db_A上执行“RMAN>list backup;”查看。
0fmhsg4r 0gmhsg5k
$rman target /
RMAN> restore spfile from '/oradata/back/0gmhsg5k';
RMAN> startup nomount force;
RMAN> restore controlfile from '/oradata/back/0gmhsg5k';
RMAN> alter database mount;
RMAN> restore database;
RMAN> recover database;#会报错,但不要紧,我们只需要得到thread和sequence号就行
Starting recover at 20-JUL-11
using channel ORA_DISK_1
starting media recovery
unable to find archive log
archive log thread=1 sequence=1
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 07/20/2011 01:33:58
RMAN-06054: media recovery requesting unknown log: thread 1 seq 1 lowscn 484679
RMAN> run {
2> set until sequence 1 thread 1;
3> recover database;
4> }
RMAN> alter database open resetlogs;
至此数据库已经正常运行。
RMAN> delete noprompt backup;
RMAN> backup incremental level=0 database format='/oradata/back/%u';
此实验就是为了不用dateguard而能够做到灾备的效果。
注意:这样做会产生的问题:用sys从PL/SQL登陆时提示权限不足