SqlAgent备份脚本

declare @dbname varchar(255)
declare @back_path varchar(255)
set @dbname='emcp'
set @back_path= 'e:\'+@dbname+'\'+@dbname
    +convert(varchar(9),getdate(),112)
    +CAST(datepart(hour,getdate()) as char(2))
    +CAST(datepart(minute,getdate()) as char(2))
    +CAST(datepart(second,getdate()) as CHAR(2))
    +'.bak'

exec('use ['+@dbname+']')
exec('backup database ['+@dbname+'] to disk='''+@back_path+'''')

 

posted @ 2014-09-15 17:23  refuly  阅读(225)  评论(0编辑  收藏  举报