批处理应用
REM 取系统日期前8位(用于短日期格式),如果是长日期格式(如2004-12-12)
REM 则取前10位(将8改为10)
set day=%DATE:~-8%
REM 取当前完整时间,将:号改为_
set currenttime=%time::=_%
set currenttime=%currenttime: =0%
REM 设置备份路径
set backupdir=c:/dbbackup
REM 设置备份文件名,格式:数据库名.日期.时间.dmp
set filename=%backupdir%/%2.%day%.%currenttime%.dmp
REM @ECHO OFF
REM 检查参数
IF "%1" == "" GOTO displayUsage
IF "%2" == "" GOTO displayUsage
IF "%3" == "" GOTO displayUsage
IF "%4" == "" GOTO displayUsage
REM 取系统日期前10位
SET day=%DATE:~-10%
REM 取当前完整时间,将:号改为_
SET currentTime=%TIME::=_%
SET currentTime=%currentTime: =0%
REM 设置备份路径
REM 此备份目录必须手工设定,并且事先创建好。
SET localBackupDir=C:/dbbackup
SET remoteBackupDir=D:/RemoteBackup
REM 设置备份服务器
REM 设置本地日志路径,日志只能存放于本地!
SET defaultBackupServer=SYB_BACKUP
IF "%5" == "" (
SET backupServer=
SET logDir=%defaultBackupServer%
SET backupDir=%localBackupDir%
) ELSE (
SET backupServer=at %5
SET logDir=%5
SET backupDir=%remoteBackupDir%
)
IF NOT EXIST %logDir% mkdir %logDir%
REM 设置备份文件名,格式:数据库服务名.数据库名.日期.时间.dmp
SET filenamePrefix=%1.%4.%day%.%currenttime%
SET dmpFile=%backupDir%/%filenamePrefix%.dmp
REM 临时SQL文件名
SET sqlFile=%1.%4.dump.sql
REM 日志文件
SET logFile=%logDir%/%filenamePrefix%.log
REM 产生临时SQL文件
echo dump database %4 to 'compress::9::%dmpFile%' %backupserver% >%sqlfile%
echo go >>%sqlfile%
REM 备份
isql -S%1 -U%2 -P%3 -i%sqlfile% -o%logfile%
ECHO 备份完成,请检查日志文件%logFile%。
GOTO finished
:displayUsage
ECHO 用法:
ECHO %0 service user password databasename [backupserver]
ECHO service : Sybase 服务名
ECHO user : 用户名
ECHO password : 用户密码
ECHO databasename : 数据库名
ECHO backupserver : 备份服务器名,可选
ECHO
ECHO 必须手工设置备份目录,并事先创建好!
ECHO 日志目录将建在当前运行目录下
ECHO 备份文件名格式:
ECHO <服务名>.<数据库>.<日期>.<时间>.dmp
:finished