DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),120)
set @strPath = REPLACE(@strPath, ':' , '.')
set @strPath = 'E:/bak/' + @strPath + '.bak' --备份目录
BACKUP DATABASE pws TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT
declare @dt datetime
select @dt=getdate()-3 --只保留3天备份文件
EXECUTE master.dbo.xp_delete_file 0,N'E:/bak/',N'BAK',@Dt