自从2004年下半年从陈店调回来后,我参加了几次网点的合并工作,当时均是手工输入,而且网点并帐后,数据量大增加,结果许多网点一张软盘备不了份,只能用两张,而软盘又容易坏,很令人头痛,我后来在网上发现了这个问题的解决办法,现特帖出,与大家共享之。
先把sco openserver 5.0.5升级成5.0.7版,用U盘备份,程序如下:
#USB Storage Utility *** 信用社业务数据U盘备份程序1.0版
#(c) Copyright 2004
#编辑修改: cyberfan alhpd@163.com
# my blog : cyberfan.blogchina.com
#最后修改时间:2004-11-20
#
#=============================
#==========================环境参数设置========================
cx_backup_dir=/usr/tmp/bankstar #储蓄硬盘备份路径
dg_backup_dir=/usr/tmp/single #对公硬盘备份路径
MOUNT_POINT=/mnt #U盘系统装载点
DEV=/dev/dsk/1sC #U盘设备名称
DAYS_U=40 #U盘备份保留天数
DAYS_H=400 #硬盘备份保留天数
#==========================结束========================
MONTH=
DAY=
#
change_time()
{
echo "======================== 系 统 时 间 修 改 ========================="
echo "例如:修改时间为9月1日18点30分,输入内容为:09011830,回车确认。"
echo "退出请输入:q"
echo ""
echo "[2;7;4m 现在系统时间是:`date '+%Y年%m月%d日%H时%M分'` [2;7;0m"
echo "[2;7;1m 请输入新的时间: [2;7;0m\c"
read input_date rest
[ "$input_date" ] || continue
case $input_date in
q]
echo "放弃退出。"
sleep 3
return 1
;;
*]
sel_long=`expr length $input_date`
[ $sel_long -eq 8 ] || {
msg_box "输入错误"
return 1
}
date -t $input_date 1>/dev/null 2>/dev/null
echo "修改完成。"
echo "[2;7;4m 新的系统时间是:`date '+%Y年%m月%d日%H时%M分'` [2;7;0m"
echo "如果不正确,请重新使用本功能更改时间\c"
read any
return 1
esac
]
########
msg_box()
{
#printf "[12;24H"
cat <<MSG
[44m == 提 示 == [40m $@,按任意键继续.
MSG
read any
]
#装载U盘
mount_U()
{
msg_box "请将U盘插入USB接口"
mount -o lower ${DEV} ${MOUNT_POINT}
if [ $? -ne 0 ]
then
msg_box "U盘安装有误 ,请检查"
return 1
else
return 0
fi
}
#
#卸载U盘
unmount_U()
{
cd /usr/usb
umount $DEV
[ $? -ne 0 ] && msg_box "卸载U盘出错"
}
##
################
###############
#自动安装软件
#自动安装软盘制作方法:
#1、在unix下,用tar cv6制作软盘。
#2、软盘必须包括install文件。设为"可执行",内容为自动安装脚本。成功返回exit 0,失败返回exit 1
#3、所有文件应放在/tmp/autoinst目录下面。
autoinst()
{
change_to_dir /tmp/autoinst
rm -r * >/dev/null 2>/dev/null
############################判断安装介质
echo "[1] 从软盘安装"
echo "[2] 从U 盘安装"
echo "[3] 退出"
echo "[2;7;4m请选择安装介质[1-3]:[2;7;0m\c"
read sel rest
[ "$sel" ] || continue
sel_long=`expr length $sel`
[ $sel_long -eq 1 ] || continue
[ $sel -lt 1 -o $sel -gt 4 ]&& break
case $sel in
1]
echo "[2;7;4m请将软盘放入软驱,按任意键继续 [2;7;0m\c"
read any
echo "正在拷贝软盘数据,请稍候......"
tar xv6
;;
2]
#判断是否安装U盘
mount_U || break
[ -d "$MOUNT_POINT/autoinst" ] || {
echo "没有安装程序, 任意键返回"
read any
unmount_U #卸载U盘
return 1
}
cp -r $MOUNT_POINT/autoinst/* ./
;;
3)
echo "放弃安装退出,按任意键继续。\c"
read any
return 1
esac
#判断拷贝结果。
[ $? -eq 0 ] || { echo "文件拷贝失败!!!按任意键继续\c"
read any
[ $sel = 2 ] && unmount_U #卸载U盘
return 1
}
#开始安装
cd /tmp/autoinst
chmod +x ./install
./install
#执行安装程序,获取返回值。成功返回0,失败返回1
[ $? -eq 0 ] && {
echo "[2;7;1m程序安装完成,按任意键继续 [2;7;0m\c"
read any
[ $sel = 2 ] && unmount_U #卸载U盘
[ $sel = 3 ] && umount /dev/cd0
return 1
}
echo "[2;7;4m程序安装失败,按任意键继续 [2;7;0m\c"
read any
[ $sel = 2 ] && unmount_U #卸载U盘
[ $sel = 3 ] && umount /dev/cd0
return 1
}
############33
help_me()#帮助文档
{
[ -f "./vmore" o -f "./help" ] || {
echo "没有帮助文件, 任意键返回"
read any
return 1
}
clear
echo ""
echo ""
echo "帮助文件操作指南:"
echo " ┌────────────────┐"
echo " │ →: 左移一列 ←: 右移一列│"
echo " │L/l: 左移一屏 R/r: 右移一屏│"
echo " │END: 左移一屏 HOME: 右移一屏│"
echo " │ ↑: 上移一行 ↓: 下移一行│"
echo " │TAB: 左移八列 BKS: 右移八列│"
echo " │ PD: 下翻一页 PU: 上翻一页│"
echo " │CTRL_L: 重画屏幕 Q : 退出 │"
echo " └────────────────┘"
echo ""
echo "[2;7;4m按任意键进入即时帮助,请输入"q"退出帮助页面。 [2;7;0m\c"
read any
./vmore help
}
###############3
check_passwd() {
stty -echo
cxsh=`dbaccess bankstar -<<-End 2>/dev/null
select sh from cxs;
END`
# 获得储蓄所号 ,设为密码。
passd=`echo $cxsh | awk '{print substr($0,4,7)}'`
echo "[2;7;4m请输入管理员口令$passd:[2;7;0m\c"
read sel
if [ "$sel" -ne $passd ]
then
echo "\n[2;7;4m口令错误,按任意键继续 [2;7;0m\c"
read any
stty echo
return 1
else
echo "[2;7;1m口令正确![2;7;0m\n\n"
stty echo
return 0
fi
}
#=================================
check_passwd_new() {
stty -echo
pass=`date '+%Y%m%d'` #将当前日期yyyymmdd设为动态的密码。
echo "[2;7;4m请输入管理员口令:[2;7;0m\c"
read sel
if [ "$sel" -ne $pass ]
then
echo "\n[2;7;4m口令错误,按任意键继续 [2;7;0m\c"
read any
stty echo
return 1
else
echo "[2;7;1m口令正确![2;7;0m\n\n"
stty echo
return 0
fi
}
########################
#=============================更改路径
change_to_dir() {
dir=$1
[ -f $dir ] && rm -r $dir
[ ! -d $dir ] && mkdir $dir
cd $dir
}
#==============================end
#==============================删除逾期数据
DeleteYqData()
{
Num=`ls $1/*.dat | wc -l`
GeS=`expr $Num - $DAYS`
[ $GeS -gt 0 ] && {
Num=0
for i in `ls $1/*.dat`
do
Num=`expr $Num + 1`
yes | rm $i >/dev/null 2>/dev/null
[ $? -ne 0 ] && {
echo "\n[2;7;4m$i 删除失败 ![2;7;0m"
}
[ $Num -ge $GeS ] && break
done
}
}
#=================================结束
GetYN()
{
while echo "\n[2;7;4m$* (Y/N): [2;7;0m\07\c"
do
read yn
case $yn in
[yY]) return 0;;
[nN]) return 1;;
*) echo "\07\07"
esac
done
}
#================================================
DateAnalyse()
{
value=`echo $1 | awk 'BEGIN { FS="/" }
{
Year=$1
Mon=$2
Day=$3
if(Year<1899 || Year >9999 || Mon<1 || Mon >12 || \
Day<1 || Day >31 || !IsDigit(Mon) || !IsDigit(Year) ||\
!IsDigit(Day) || !IsYMD(Year,Mon,Day))
printf("1")
else printf("0")
}
function IsDigit(str)
{
for(i=1;i<=length(str);i++)
{
bit=substr(str,i,1)
if(bit<0 || bit>9) return(0)
}
return(1)
}
function IsLeapYear(YearNum)
{
if((int(YearNum%4)==0 && int(YearNum%100)!=0)||int(YearNum%400)==0)
return(1)
else return(0)
}
function IsYMD(YearNum,MonNum,DayNum)
{
DayArr["01"]=31
if(IsLeapYear(YearNum)) DayArr["02"]=29
else DayArr["02"]=28
DayArr["03"]=31
DayArr["04"]=30
DayArr["05"]=31
DayArr["06"]=30
DayArr["07"]=31
DayArr["08"]=31
DayArr["09"]=30
DayArr["10"]=31
DayArr["11"]=30
DayArr["12"]=31
if(DayNum>0 && DayNum<=DayArr[MonNum])
return(1)
else return(0)
}' `
return<$value
}
#========================================
GetDate()
{
while true
do
echo "\n请输入$* (yyyy/mm/dd): \c"
read date
len=`expr length "$date"`
DateAnalyse $date
[ $? -ne 0 -o $len -ne 10 ] && {
echo "\07\07\07"
echo "[2;7;4m日期错误,按回车键重新输入 ...[2;7;0m\c"
read key
continue
]
GetDateYN "输入$*为: [2;1;7m $date [2;7;0m, 是否正确"
[ $? -eq 0 ] && break
done
]
#=============================================
GetDateYN()
{
while echo "\n\07\07$* (Y/N): \c"
do
read yn
len=`expr length "$yn"`
[ $len -ne 1 ] && continue;
case $yn in
[yY]} return 0;;
[nN]] return 1;;
*] echo "\07\c";;
esac
done
}
#=============================================程序主画面
main_menu() {
tput clear
cat <<MYMENU
[44m
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ 安陆市信用合作联社业务数据U盘备份程序 ┃
┃ ┃
┃ ========================================================== ┃
┃ [1] 储蓄业务数据备份 [2] 储蓄业务数据恢复* ┃
┃ [3] 对公业务数据备份 [4] 对公业务数据恢复* ┃
┃ --------------------------------------------------------- ┃
┃ [5] 查看U盘使用情况 [6] 删除U盘全部数据* ┃
┃ [7] 选择删除U盘数据* [8] 列 U 盘 内 容 ┃
┃ [9] 自动程序安装 ┃
┃ --------------------------------------------------------- ┃
┃ [m] 检查密码定期修改情况 [t] 修改系统时间 ┃
┃ [q] 退 出 [h] 帮 助 ┃
┃ =========================================================== ┃
┃Version 1 .0 alhpd@163.com ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛[40m
日常备份数据保留$DAYS_U天,特殊日备份数据保留$DAYS_H天。过期数据,程序将自动删除。
MYMENU
#`date '+%Y年%m月%d日'`
echo "请选择:\c";
}
#=============================================END
check_privilege() {
id_num=`id -u `
if [ id_num -ne 0 ]
then
echo "请用超级用户执行此程序!!!!"
sleep 3
exit
fi
}
#============================================查看U盘使用情况
usd_statistics() {
echo "请稍等......"
total=`df -kv $DEV |grep $DEV| awk '{print $3}'`
used=`df -kv $DEV |grep $DEV| awk '{print $4}'`
free=`df -kv $DEV |grep $DEV| awk '{print $5}'`
percent=`df -kv $DEV |grep $DEV|awk '{print $6}'`
echo " U 盘 当 前 使 用 情 况 "
echo " --------------------------------------------------------------------"
echo " 总容量(K) 已用(K) 剩余(K) 百分比"
echo " ${total} ${used} ${free} ${percent}"
echo " --------------------------------------------------------------------" echo " 按回车键继续......\c"
read any
}
#============================================end
#============================================删除U盘所有数据
delete_all() {
echo "你确定要删除U盘所有数据吗?(y/n)\c"
cd $MOUNT_POINT
read opt
if [ $opt = "y" ]
then
rm -rf *
fi
}
#============================================end
#============================================选择删除U盘数据
delete_single() {
cd $MOUNT_POINT
echo "U盘当前目录:"
lx
echo "请输入要删除的目录或者完整文件路径:\c"
read delete_dir
if [ -d $delete_dir -o -f $delete_dir ]
then
echo "你确定要删除${delete_dir}吗?(y/n)\c"
read opt
if [ $opt = "y" ]
then
rm -rf $delete_dir
fi
else
echo "<$delete_dir>目录或文件不存在"
sleep 2
fi
}
#=========================================================
list_file() {
#####
echo "[1] 储蓄业务"
echo "[2] 对公业务"
echo "[3] 特殊日备份"
echo "[4] 全部内容"
echo "[2;7;4m请选择[1-4]:[2;7;0m\c"
read sel rest
[ "$sel" ] || continue
sel_long=`expr length $sel`
[ $sel_long -eq 1 ] || continue
[ $sel -lt 1 -o $sel -gt 4 ]&& break
#####
case $sel in
1)
[ -d "$MOUNT_POINT/bankstar" ] || {
echo "没有储蓄业务数据, 任意键返回"
read any
return 1
}
echo "U盘当前目录:$MOUNT_POINT/bankstar"
l $MOUNT_POINT/bankstar
echo "任意键返回"
read any
;;
2)
[ -d "$MOUNT_POINT/single" ] || {
echo "没有对公业务数据, 任意键返回"
read any
return 1
}
echo "U盘当前目录:$MOUNT_POINT/single"
l $MOUNT_POINT/single
echo "任意键返回"
read any
;;
3)
[ -d "$MOUNT_POINT/special" ] || {
echo "没有特殊日备份数据, 任意键返回"
read any
return 1
}
echo "U盘当前目录:$MOUNT_POINT/special"
l $MOUNT_POINT/special
echo "任意键返回"
read any
;;
4)
echo "U盘当前目录:"
l $MOUNT_POINT
echo "任意键返回"
read any
esac
}
##############################
new_bankstar()
{
cd $MOUNT_POINT
change_to_dir bankstar
backdate=`head -1 /usr/newbank/etc/cs | awk -F \| '{print $1}'` #获得会计日期 YYYY/MM/DD
date1=`echo $backdate | awk 'BEGIN { FS="/" }{printf("%s.%s.%s",$1,$2,$3)}'` #转换为:YYYY.MM.DD
date2=`echo $backdate | awk 'BEGIN { FS="/" }{printf("%s%s%s",$1,$2,$3)}'` #转换为:YYYYMMDD
###
[ -d $cx_backup_dir ] || {
echo "\n[2;7;1m请先做硬盘备份,按任意键继续...[2;7;0m\c"
read wait rest
return
}
[ -f $cx_backup_dir/cxData:$date1 ] || {
echo "\n[2;7;1m请先做硬盘备份,按任意键继续...[2;7;0m\c"
read wait rest
return
}
cd $cx_backup_dir
echo "正在复制储蓄备份数据:{$backdate}"
cp -f cxData:$date1 $MOUNT_POINT/bankstar/$date2.cx
[ $? -eq 0 ] || { echo "文件拷贝失败!!!"
sleep 3
return
}
###########################删除过期30天数据
echo "\n正在清理过期备份数据。"
find $MOUNT_POINT/bankstar/ -name "????????.cx" -mtime +30 -print -exec rm {} \;
#########################################
echo "[2;7;1m备份成功 ! 按回车键继续...[2;7;0m\c"
read any
}
recover_bankstar()
{
GetDate "所恢复数据的日期"
Date=`echo $date | awk 'BEGIN { FS="/" }{printf("%s%%s",$1,$2,$3)}'`
BkupFile="$Date.cx"
[ ! -f $MOUNT_POINT/bankstar/$BkupFile ] && {
echo "\n\07\07[2;7;4m${date}无备份数据 ! 按回车键返回...[2;7;0m\c"
read key
return 1;
}
cd /tmp
rm bankstar.Z 2>/dev/null
cd $MOUNT_POINT/bankstar
[ -f "$Date.cx" ] || { echo "\n $Date.cx(数据)文件不存在!!!"
read key
return
}
echo "正在拷贝数据"
cp $Date.cx /tmp/bankstar.Z
[ $? -eq 0 ] || { rm -r /tmp/bankstar.Z>dev/null 2>/dev/null
read key
return
}
cd /tmp
rm -r bankstar 1>/dev/null 2>/dev/null
uncompress bankstar.Z
[ $? -eq 0 ] || { rm -r bankstar.Z>/dev/null 2>/dev/null
read key
return
}
tar xvf bankstar
[ $? -eq 0 ] || { rm -r bankstar.Z >/dev/null 2>/dev/null
rm -r bankstar >/dev/null 2>/dev/null
return
}
dbaccess - -<<-End >/dev/null 2>/dev/null
drop database bankstar;
End
dbimport bankstar -l -i ./
flag=$?
while [ $flag -ne 0 ]
do
GetYN "加载数据库失败 ! 是否重新加载数据库" || return
dbaccess - - <<-End
drop database bankstar;
End
dbimport bankstar -l -i ./
flag=$?
done
echo "[2;7;1m恢复成功 ! 按回车键返回...[2;7;0m\c"
rm -r -f /tmp/bankstar.exp 2>/dev/null
read key
return
}
#备份对公业务数据
new_bankacc()
{
cd $MOUNT_POINT
change_to_dir single
cszd=`dbaccess single -<<-End 2>/dev/null
select rq from cszd;
End`
cszd=`echo $cszd | awk '{print substr($0,4,10)}'`
date1=`echo $cszd | awk 'BEGIN { FS="/" }{printf("%s.%s.%s",$1,$2,$3)}'` #转换为:YYYY.MM.DD
date2=`echo $cszd | awk 'BEGIN { FS="/" }{printf("%s%s%s",$1,$2,$3)}'` #转换为:YYYYMMDD
###
[ -d $dg_backup_dir ] || {
echo "\n[2;7;1m请先做硬盘备份,按任意键继续...[2;7;0m\c"
read wait rest
return
}
[ -f $dg_backup_dir/dgData:$date1 ] || {
echo "\n[2;7;1m请先做硬盘备份,按任意键继续...[2;7;0m\c"
read wait rest
return
}
cd $dg_backup_dir
echo "正在复制对公业务备份数据:{$cszd}"
cp -f dgData:$date1 $MOUNT_POINT/single/$date2.dg
[ $? -eq 0 ] || { echo "文件拷贝失败!!!"
sleep 3
return
}
###########################删除过期30天数据
echo "\n正在清理过期备份数据。"
find $MOUNT_POINT/single/ -name "????????.dg" -mtime +30 -print -exec rm {} \;
#########################################
echo "[2;7;1m备份成功 ! 按回车键继续...[2;7;0m\c"
read any
}
#恢复对公业务数据
recover_bankacc()
{
GetDate "所恢复数据的日期"
Date=`echo $date | awk 'BEGIN { FS="/" }{printf("%s%s%s",$1,$2,$3)}'`
BkupFile="$Date.dg"
[ ! -f $MOUNT_POINT/single/$BkupFile ] && {
echo "\n\07\07[2;7;4m${date}无备份数据 ! 按回车键返回...[2;7;0m\c"
read key
return 1;
}
[ -d "/usr/tmp/backup/" ] || mkdir /usr/tmp/backup/
cd /usr/tmp/backup/
tar xvf $MOUNT_POINT/single/$BkupFile
flag=$?
while [ $flag -ne 0 ]
do
GetYN "拷贝失败 ! 是否重新拷贝" || return 1
done
yes | uncompress single.Z
flag=$?
while [ $flag -ne 0 ]
do
GetYN "解压缩失败 ! 是否重新解压缩" || return 1
uncompress single.Z
flag=$?
done
tar xvf single
flag=$?
while [ $flag -ne 0 ]
do
GetYN "解数据包失败 ! 是否重新解数据包" || return 1
tar xvf single
flag=$?
done
dbaccess - - <<-End
drop database single;
End
dbimport single -l -i ./
flag=$?
while [ $flag -ne 0 ]
do
GetYN "加载数据库失败 ! 是否重新加载数据库" || return 1
dbaccess - - <<-End
drop database single;
End
dbimport single -l -i ./
flag=$?
done
echo "[2;7;1m恢复成功 ! 按回车键返回...[2;7;0m\c"
rm -f single
read key
return
]
##主程序
trap '' 2 3
check_privilege #检查权限
while true
do
main_menu
read opt
case $opt in
1]
#储蓄数据备份
mount_U && {
new_bankstar
unmount_U
}
;;
2]#储蓄数据恢复
check_passwd_new && {
mount_U && {
recover_bankstar
unmount_U
}
}
;;
3]
#公存数据备份
mount_U && {
new_bankacc
unmount_U
}
;;
4]#公存数据恢复
check_passwd_new && {
mount_U && {
recover_bankacc
unmount_U
}
}
;;
5]#U盘使用情况
mount_U && {
usd_statistics
unmount_U
}
;;
6]#删除U盘全部内容
check_passwd_new && {
mount_U && {
delete_all
unmount_U
}
}
;;
7]#删除U盘部分内容
check_passwd_new && {
mount_U && {delete_single
unmount_U}
}
;;
8]#列U盘内容
mount_U && {
list_file
unmount_U
}
;;
9]#特殊备份拷贝
mount_U && {
copy_special
unmount_U
}
;;
0]#自动安装
autoinst
;;
h]#帮助文档
help_me
;;
m]#密码检查
./mm
;;
t]
change_time
;;
q]
exit
esac
done