Chinaunix

标题: 在Unix/Linux下用crontab定时备份sybase数据库 [打印本页]

作者: lilian2003    时间: 2004-05-08 16:25
标题: 在Unix/Linux下用crontab定时备份sybase数据库
在Eisen的帮助下,我把我解决的问题分享如下:
一、首先进行一些基础知识的准备
1.        Unix定时执行任务的命令之一Crontab的参数以及用法
crontab 文件的格式是:
minute   hour   day   month   day_ of_ week   command
其中:  minute : 0-59
        hour   : 0-23
        day of the month  :1-31
        month of the year  :1 -12
        day of the week  :0-6 (0=Sunday, 1 =Monday, etc)
这些域可以是“*”号,以“,”做分隔的列表或是一个取值范围。
例如:0 1 15 * * /fullbackup 表示在每个月15号早上1点执行/fullbackup文件(注意该文件必须是可执行文件)。
使用 crontab –l 可以浏览当前crontab文件的内容;使用 crontab –e 则可以对crontab文件进行编辑。
2.        Sybase备份脚本
Dump database 数据库名称 to “物理路径”
二、定时备份sybase数据库的实例应用
1.        用root用户登录小型机RS6000 AIX 4.3 操作系统(其他Unix/Linux系统类似)
2.        使用crontab -e 来编辑定时文件
内容如下:
10 23 * * * * /Sybase/backup.sh
3.        使用Vi编辑backup.sh(保证backup.sh有执行权限)文件,内容如下:
su –sybase –c “ isql -Usa –P密码 -Sserver <bakscript >;bakscript.out “
4.        使用Vi编辑bakscript文件,内容如下:
内容如下:
dump database Mydatabase to “/sybase/mydatabase.dat”
go
作者: Blackrose    时间: 2004-05-08 16:29
标题: 在Unix/Linux下用crontab定时备份sybase数据库

如果使用sybase用户的crontab而不是root的,记住要在shell文件中增加环境变量的设置
作者: lilian2003    时间: 2004-05-08 16:42
标题: 在Unix/Linux下用crontab定时备份sybase数据库
对了,顺便问一下如何在脚本里面加上Shell变量让数据库名按日期生成
比如今天生成mydatabase20040508.dat,明天生成mydatabase20040509.dat??
希望Blackrose或其他大虾帮忙一下!!!
作者: Blackrose    时间: 2004-05-08 17:19
标题: 在Unix/Linux下用crontab定时备份sybase数据库
吐血推荐:
呵呵

--定时备份
-- dump database --
declare @dumpfile varchar(50)

declare @dumpsdate varchar(20)

select @dumpsdate = convert(varchar(20),getdate(),112)

select @dumpfile = 'd:\master.dmp' + convert(varchar(30),@dumpsdate )

dump database master to @dumpfile

select @dumpfile = 'd:\DBNAME.dmp' + convert(varchar(30),@dumpsdate )

dump database DBNAME to @dumpfile

不满意自己改一下
作者: lilian2003    时间: 2004-05-09 08:10
标题: 在Unix/Linux下用crontab定时备份sybase数据库
非常感谢,交个朋友,我的邮箱li_lian@sina.com




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2