Chinaunix首页 | 论坛 | 博客
  • 博客访问: 103582589
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类:

2008-04-02 19:50:16

作者:太阳花  出处:

# 中创对公(BANKACC)数据库数据备份程序

# FLWSUN  测试专用

getdev() {
      softdev=/dev/null
      while true
      do
            clear
            echo "               <1> 软  盘                 "
            echo "               <2> U  盘                 "
            echo "               <3> 硬  盘                "
            echo "               <4> 退  出                 "
            echo "                                        "
            echo "请选择备份介质: \c"
            read sel rest
            [ "$sel" ] || continue
            sel_long=`expr length $sel`
            [ $sel_long -eq 1 ] || continue
            [ $sel -ge 1  -a $sel -le 3 ] && break
            [ $sel -eq 4 ] && { 
                  rm /tmp/bankdata.Z >/dev/null  2>/dev/null
                  exit 4
            }
      done

      case $sel in
            1) 
                  softdev=/dev/fd0135ds18
                  fdbak
                  hhdbak
                     ;
            2) 
                  softdev=/dev/dsk/1s0
                  echo "\n\033[2;14;1m请插入U盘,按任意键继续....\033[2;7;0m\c"
                  read wait rest
                  su usb -c "mount $softdev /mnt"  >/dev/null 2>/dev/null
                  if [ $? -eq 0 ]
                  then
                        udbak
                        hhdbak
                  else
                  echo "\n\033[2;14;4mU盘安装失败!!\007\007\033[2;7;0m\c"
                        exit 1
                  fi
                  su usb -c "umount /mnt"
                  [ $? -ne 0 ] && echo "\nU盘卸载失败!!!"
                     ;
            3) 
                  softdev=/usr/tmp/backup
                  [ -d "$softdev" ] || { 
                        mkdir $softdev
                        [ $? -eq 0 ] || exit 1
                    }            
                  hdbak
                     ;
      esac

#      [ -w $softdev ] || {
#            echo "$softdev 不可写,按任意键返回!\n"
#            read wait
#            return 1
#      }
return 0
}

hdbak()
{
      cd $softdev
      find $softdev/bankdata* -atime +7 -print -exec rm {} \;  >/dev/null 2>/dev/null     
      echo "\n正在将备份数据写入硬盘,请稍候...\c"
      cp /tmp/bankdata.Z $softdev/bankdata.Z.$year$month$day >/dev/null 2>/dev/null
      if [ $? -eq 0 ]
      then
            echo "完成!"
      else
            echo "硬盘备份失败!!"
            exit 1
      fi
      cd $HOME
      rm -r /tmp/bankdata.Z
      exit 0
}

udbak()
{
      echo "\n正在将备份数据写入U盘,请稍候...\c"
      cp /tmp/bankdata.Z /mnt/bankdata.Z.$year$month$day >/dev/null 2>/dev/null
      if [ $? -eq 0 ]
      then
            echo "完成!"
      else
            echo "失败!!"
            exit 1
      fi
}
            
            
fdbak()
{
      cd /tmp
      echo "\n\033[2;14;1m请插入软盘,按任意键继续....\033[2;7;0m\c"
      read wait rest
      tar cv6 bankdata.Z
      aa=$?
      #rm -f bankdata.Z
      if [ $aa -ne 0 ]
      then
            exit $aa
      #else
      #      exit 0
      fi
}
      
hhdbak()
{
      echo "\n\033[2;14;1m硬盘备份(/usr/tmp/backup 目录下)...\c"
      softdev="/usr/tmp/backup"
      cd $softdev
      find $softdev/bankdata* -atime +7 -print -exec rm {} \;  >/dev/null 2>/dev/null     
      cp /tmp/bankdata.Z $softdev/bankdata.Z.$year$month$day
      [ $? -eq 0 ] || { 
            echo "文件(bankdata.Z)拷贝失败!!!"
            rm -f /tmp/bankdata.Z
            exit 1
      }
      cd $HOME
      rm -f /tmp/bankdata.Z
      echo "OK\033[2;7;0m\n"
}




cd $HOME


kjrq_data=`head -1 $HOME/etc/cs | awk -F \| '{print $1}'`
echo $kjrq_data >kjrq_file
kjrq=`cat kjrq_file | grep / |awk '{ printf ("%10s",$1) }'`
year=`cat kjrq_file | grep / |awk 'BEGIN { FS="\/" } { printf $1 }'`
month=`cat kjrq_file | grep / |awk 'BEGIN { FS="\/" } { printf $2 }'`
day=`echo $kjrq | grep / |awk 'BEGIN { FS="\/" } { printf ("%2s", $3) }'`

rm -r  single.exp >/dev/null 2>/dev/null
rm -r -f /tmp/bankdata    >/dev/null 2>/dev/null
rm -r -f /tmp/bankdata.Z  >/dev/null 2>/dev/null

[ -f "/tmp/bankdata" -o -f "/tmp/bankdata.Z" ] && {
      echo "请先清理 /tmp 目录然后再开始备份!\n"
      exit 1
}

cd $HOME
tput cup 5 0 
echo "正在卸载数据库,请稍候...\c"
      dbexport single -o  . >/dev/null 2>/dev/null
      if [ $? -eq 0 ]
      then
            echo "完成!"
      else
            echo "失败!!\007\007"
            exit 1
      fi

#tar cvf  /tmp/bankdata com data etc frm  single.exp

tput cup 5 15
echo "正在打包备份数据,请稍候...\c"
tar cvf  /tmp/bankdata single.exp >/dev/null 2>/dev/null
      if [ $? -eq 0 ]
      then
            echo "完成!"
      else
            echo "失败!!\007\007"
            exit 1
      fi

tput cup 5 32
chmod 777 /tmp/bankdata
echo "正在压缩备份数据,请稍候...\c"
compress -H /tmp/bankdata
      if [ $? -eq 0 ]
      then
            echo "完成!\c"
            sleep 2
      else
            echo "失败!!\007\007"
            exit 1
      fi
chmod 777 /tmp/bankdata.Z

getdev
[ $? -eq 0 ] || exit 1
阅读(650) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~