Shell脚本实现sybase数据备份

可在 sybase 用户下创建,将其命名为 bcpoutdata 。
然后 chmod a+x bcpoutdata
在 sybase 用户下运行 bcpoutdata 即可。
注:
1)将 database_name 改为你的数据库名。

2)将 pas 改为你的 sa 口令。
3)将 server 改为你的 SQL server 名。
4)要导入,将 out 改为 in 即可。
最后提醒你,别忘了要在 sybase 用户下创建一个目录,
把 bcpoutdata 置入其中,再运行。
什麽?你要打包、压缩。
哈,在后面加几条:
tar cvf data.tar *.bcp
compress data.tar
rm *.bcp
愿各位好运

isql -Usa -Ppas -Sserver -otables.tmp <<-EOF
USE database_name
GO
SELECT name FROM sysobjects WHERE type='U' ORDER BY name
GO
exit
EOF
vi tables.tmp < /dev/null
:1,2 d
:$ d
:1,$ <<<
: x
EOF
total=`cat tables.tmp|wc -l`
current=0
for table in `cat tables.tmp`
do
current=$current+1
echo "*** $current/$total bcpout $table ***"
bcp database_name..$table out $table.bcp -Usa -Ppas -Sserver -Jiso_1 -c
echo "*** $table done ***n"
done
rm tables.tmp

首先感谢诸位对此文的兴趣,现解释如下:
一、导出用户数据库中的表,将其置入文件 tables.tmp 中。

isql -Usa -Ppas -Sserver -otables.tmp <<-EOF 
USE database_name 
GO 
SELECT name FROM sysobjects WHERE type='U' ORDER BY name 
GO 
exit 
EOF

二、编辑 tables.tmp ,因 tables.tmp 中首两行和末三行,
是我们不要的东西。前次的有小小错,现更正如下:

vi tables.tmp < /dev/null 
:1,2 d      (删首两行)
:$          (到末行)
:-2,. d     (删末三行)
:1,$ <<<    (清各行左侧空格,即各行顶左。当然一个 < 也够用,1,$ 也可换成 % )
: x 
EOF

至如 < 使它们不在屏上显示,哈哈、、、就用它了。
找本书看看,再在 SHELL 下,带 < 键入上述脚本,你就会有收获的。EOF 可用其他字母,但前后必须一致。

三、导出用户数据库各表中的数据

total=`cat tables.tmp|wc -l`    (总表数) 
current=0                       (当前的第 n 张表)
for table in `cat tables.tmp`   (将文件 tables.tmp 中的表名依次赋给 table)
do 
current=$current+1 
echo "*** $current/$total bcpout $table ***" 
bcp database_name..$table out $table.bcp -Usa -Ppas -Sserver -Jiso_1 -c 
echo "*** $table done ***n" 
done 
rm tables.tmp

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值