当前位置导航:炫浪网>>网络学院>>编程开发>>MsSQL教程

根据日期手工备份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
相关内容
赞助商链接