Shell脚本实现sybase数据备份
2007-03-02 15:33
736 查看
可在 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
然后 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
相关文章推荐
- shell实现自动备份mysql、整站数据的两个脚本分享
- shell脚本实现系统监视统计与数据备份
- 利用Shell脚本实现自动备份VPS数据到Dropbox
- shell实现自动备份mysql、整站数据的两个脚本分享
- shell脚本实现系统监视统计与数据备份
- linux下实现VPS web和mysql数据的备份脚本
- CentOS中使用Shell脚本实现每天自动备份网站文件和数据库并上传到FTP中(转)
- shell脚本实现删除过期数据库中的数据
- 程序员(媛)Shell脚本必备技能之中的一个: 在Linux下怎样自己主动备份mysql数据
- 在Shell脚本中编写AWK脚本实现数据提取—注意格式、awk中使用shell变量、awk中数字字符串转换成数字、awk中字符串相等比较
- 程序猿(媛)Shell脚本必备技能之一: 在Linux下如何自动备份mysql数据
- shell脚本实现ftp自动备份
- shell脚本实现mysql纯文本格式备份
- Shell脚本实现数据父子关系定义——目标:将目标数据批量导入MySQL数据库
- 完全备份数据和差异备份数据的shell脚本
- expdp/impdp数据泵和RMAN全库备份shell脚本各一则
- Shell脚本_备份/etc数据
- Vbs脚本实现数据CUT备份及自动轮询删除备份数据
- linux服务器实现每天定时备份mysql数据库的shell脚本
- Linux 平台下 Oracle 数据泵备份(expdp) SHELL 脚本