Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux系統常見問題解答 >> Linux下的flashback腳本

Linux下的flashback腳本

日期:2017/1/20 17:42:27      編輯:Linux系統常見問題解答

 

 一個客戶比較關心邏輯錯誤的恢復,我們給他推薦的方案是在容災庫上使用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 《EOF

  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 《EOF

  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

Copyright © Windows教程網 All Rights Reserved