我的代码,用于 SQL Server 2008 上的代理作业,生成备份文件,但每次触发代理的作业时它都会覆盖第一个 bak 文件!!?
我如何使用不同的名称进行备份与时间相关
例如:testDB201313328.bak 并在 1 分钟后创建名称为:testDB201313329.bak 的文件
而是覆盖第一个
USE msdb ;
GO
DECLARE @fileName VARCHAR(90);
DECLARE @db_name VARCHAR(20);
DECLARE @fileDate VARCHAR(20);
DECLARE @commandtxt VARCHAR(100);
SET @fileName = 'C:\Test_Backups\';
SET @db_name = 'testDB';
SET @fileDate = CONVERT(VARCHAR(8), GETDATE(),112) + convert (varchar(4),DATEPART(HOUR, GETDATE())) + convert ( varchar(4) ,DATEPART(MINUTE, GETDATE())) + convert ( varchar(4) ,DATEPART(SECOND, GETDATE()));
SET @fileName = @fileName + @db_name + RTRIM(@fileDate) + '.bak';
SET @commandtxt = 'BACKUP LOG testDB TO DISK =''' + @fileName + ''' WITH INIT'
-- add a job
EXEC dbo.sp_add_job
@job_name = N'LogBackup',
@description =N'Log Backup on weekdays every 15 minutes from 8am till 6pm' ;
-- add job steps to job
EXEC sp_add_jobstep
@job_name = N'LogBackup',
@step_name = N'Weekdays_Log_Backup',
@subsystem = N'TSQL',
@command = @commandtxt ,
@on_success_action = 1,
@retry_attempts = 5,
@retry_interval = 1 ;
GO
...