标题: 根据日期手工备份SQL Server数据库 [打印本页] 作者: eddy 时间: 2009-1-22 16:54 标题: 根据日期手工备份SQL Server数据库 IF EXISTS (SELECT name FROM master.dbo.sysdevices WHERE name = N'mx_hr_backup')
EXEC sp_dropdevice 'mx_hr_backup' // 删除原备份设备
GO
DECLARE @filename VARCHAR(255)
DECLARE @now AS DATETIME
SELECT @now = GETDATE()
SELECT @filename = 'C:\Program Files\Wizit Software\Wiz_HR\mx_hr_' //备份文件主文件名
CAST(DATEPART(yyyy, @now) AS VARCHAR)
CAST(DATEPART(mm, @now) AS VARCHAR)
CAST(DATEPART(dd, @now) AS VARCHAR)
CAST(DATEPART(hh, @now) AS VARCHAR)
CAST(DATEPART(mi, @now) AS VARCHAR)
CAST(DATEPART(ss, @now) AS VARCHAR)
CAST(DATEPART(ms, @now) AS VARCHAR)
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'xm_hr')
BEGIN
EXEC sp_addumpdevice 'disk', 'mx_hr_backup', @filename // 添加备份设备
BACKUP DATABASE xm_hr TO mx_hr_backup WITH INIT // 备份数据库
END
GO <