简体   繁体   中英

How to backup sybase database with date/time stamp

How to backup sybase database with date/time stamp using command line?

Saw somebody posted this method: declare @pvm varchar(30), @dumptorun varchar(300), @dbname varchar(70) select @pvm=(CONVERT(varchar(30), GETDATE(), 112)) select @dbname='master' select @dumptorun = 'dump database '+@dbname+' to d:\\temp\\'+@dbname+'_'+@pvm+'.dmp' select @dumptorun EXEC ( @dumptorun )

Tried it and removed the go, but still stuck with some errors, it complains some syntax errors with "/"

Anybody can help? Thanks.

declare @pvm varchar(30), @dumptorun varchar(300), @dbname varchar(70)
select @pvm=(CONVERT(varchar(30), GETDATE(), 112))
select @dbname='master'
select @dumptorun = "dump database " + @dbname + " to '/backup/DB/"+ @dbname+"_"+ @pvm + ".dmp'"
select @dumptorun
EXEC ( @dumptorun )

This works on Unix - you would need to adjust for windows as your original question has a windows directory but your answer seems to imply a unix directory type instead so would need the slashes and drive etc to be changed.

The key is that you need quotes around the backup file name so I just changed your concatenated strings to double quotes so that its easier to add the single quote you need.

declare @pvm varchar(30), @dumptorun varchar(300), @dbname varchar(70) select @pvm=(CONVERT(varchar(30), GETDATE(), 112)) select @dbname='TOB' select @dumptorun = 'dump database '+@dbname+' to /backup/DB/'+@dbname+'_'+@pvm+'.dmp' select @dumptorun EXEC ( @dumptorun ) go

Msg 102, Level 15, State 181: Server 'SOL', Line 1: Incorrect syntax near '/'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM