ITPub博客

首页 > 数据库 > Oracle > Linux下的flashback脚本

Linux下的flashback脚本

Oracle 作者:哇哈哈825 时间:2014-05-21 10:06:47 0 删除 编辑
一个客户比较关心逻辑错误的恢复,我们给他推荐的方案是在容灾库上使用flashback技术,下面是一个简单的Linux的脚本。

#!/bin/bash


export LOGIN_USER=test
export LOGIN_PWD=test


#########################################function###############################################


flashscn()
{
echo -e "enter scn:\c"
read SCNNUM
STR1="flashback table $OWNER.$TABLE_NAME to scn $SCNNUM;"
echo $STR1
T1=`sqlplus -silent $LOGIN_USER/$LOGIN_USER < set pagesize 0 feedback off verify off heading off echo off
alter table $OWNER.$TABLE_NAME enable row movement;
$STR1
alter table $OWNER.$TABLE_NAME disable row movement;
EOF`
if [ -z "$T1" ];then
echo "######"
echo "flashback table $TABLE_NAME OK!"
else 
echo "######"
echo "flashback tabel $TABLE_NAME error:"
echo $T1 |awk -F "ORA-" '{print "ORA-" $NF}' 
fi
}


flashtime()
{
echo -e "enter time (example 2014-05-18 20:34:21):\c"
read STIME
STR2="flashback table $OWNER.$TABLE_NAME to timestamp to_timestamp('$STIME','yyyy-mm-dd hh24:mi:ss');"
echo $STR2
T2=`sqlplus -silent $LOGIN_USER/$LOGIN_USER < set pagesize 0 feedback off verify off heading off echo off
alter table $OWNER.$TABLE_NAME enable row movement;
$STR2
alter table $OWNER.$TABLE_NAME disable row movement;
EOF`
if [ -z "$T2" ];then
echo "######"
echo "flashback table $TABLE_NAME OK!"
else 
echo "######"
echo "flashback tabel $TABLE_NAME error:"
echo $T2 |awk -F "ORA-" '{print "ORA-" $NF}' 
fi


}


############################################main start##############################################


echo -e "enter flashback table owner:\c"
read OWNER
echo -e "enter flashbackup table name:\c"
read TABLE_NAME
echo -e "chose flashback type 1)time 2)scn  1\2 :\c"
read STYPE
case $STYPE in
    1)
flashtime
;;
    2)
flashscn
;;
    *)
echo "your enter is error,please enter 1 or 2 !!!"
exit
;;
esac

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29635878/viewspace-1165811/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-04-30

  • 博文量
    43
  • 访问量
    46137