---
title: "自动备份sybase数据库数据及存储过程"
author: "maoone2003"
date: "2008-07-07T20:57:29Z"
tags: []
slug: "sybase"
draft: false
lastmod: "2008-07-07T20:57:29Z"
id: 212485
url: "https://maoone2003.iteye.com/blog/212485"
---

一：将用户表备份成为文本
（1）先编辑一个名为mkbcpout.sql的文件，内容如下：

select "bcp "+name+" out ./data/" + name+".table -c -t""|"" -Uuser -Ppwd -Sserver -Jcp850" from sysobjects where type='U' order by name
go

（2）将以下语句写入dataBakup_bcp.bat中

isql -Uuser -Ppwd -Sserver -w500 -imkbcpout.sql -obcpout.bat
call bcpout.bat

（3）定义任务计划每天定时启动dataBakup_bcp.bat


二：将用户存储过程备份成文本
在需要对一些存储过程单独进行备份时，往往使用defncopy通过拼串的方式进行。具体步骤如下：

（1）根据需要备份的存储过程，先编写此crtprocout.sql文件，假设导出所有以PR_JF开头的存储过程，内容如下：

select "defncopy -Uuser -Ppwd -Sserver -Jcp850 out ./proc/"+name+".sql abccqpaea "+name from sysobjects where type in('P','V') order by name

（2）将以下语句写入procBakup.bat中

isql -Uuser -Ppwd -Sserver -w500 -icrtprocout.sql -ocrtprocout.bat
call crtprocout.bat

（3）定义任务计划每天定时启动procBakup.bat
<span style="color:red">
注意：-w500指导出的文本每一行最大长度为500个字节，防止由于默认80字节使数据分割，最终bat文件执行时操作系统不能正确识别
</span>