免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: hu1234567890
打印 上一主题 下一主题

送个数据导出导入脚本给各位(怎么无人喝彩 ) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-08-20 22:56 |显示全部楼层 |倒序浏览
送个 shell for Sco Unix 5.05 脚本给各位,
可在 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 <<EOF 2>;/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

论坛徽章:
0
2 [报告]
发表于 2003-09-04 21:33 |显示全部楼层

送个数据导出导入脚本给各位(怎么无人喝彩 )

首先感谢诸位对此文的兴趣,现解释如下:
一、导出用户数据库中的表,将其置入文件 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 <<EOF 2>;/dev/null
:1,2 d      (删首两行)
          (到末行)
:-2,. d     (删末三行)
:1,$ <<<    (清各行左侧空格,即各行顶左。当然一个 < 也够用,1,$ 也可换成 % )
: x
EOF

至如 <<EOF ... ... EOF ,批处理执行时,我们要屏蔽一些东西,
使它们不在屏上显示,哈哈、、、就用它了。
找本书看看,再在 SHELL 下,带 <<EOF ... ... EOF 项或不带该项
键入上述脚本,你就会有收获的。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
3 [报告]
发表于 2003-09-05 19:13 |显示全部楼层

送个数据导出导入脚本给各位(怎么无人喝彩 )

这是鄙人工作之谈中的少少部分,放入此意在抛砖引玉。
用此结构可作许多变通,如:

1、
truncate table
update statistics

2、
按条件备份部分数据,这样首先你要对 tables.tmp 编辑,加
入要检索的字段如:

表名1:字段名
表名2:字段名
... ...

其次要用到select into  from
再次修改 for ... ... done 中的脚本,加入一些东西,
如:
echo $table >; tables.tmp
table1=`cut -f1, -d: tables.tmp`
table2=`cut -f2, -d: tables.tmp`

3、还可在脚本前加入键入sa口令等选单。

我做了大量的脚本,给工作带来了很多便利。
什么?..贴出来!当然是不可能的,自己动手那才有乐趣呢。
愿与各位交流。
我只和纯数据打交道,诸位有其它请加入。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP