I'm backing into the DBA position from being an app / web designer. Using SQL 2005 and hating wizards, I'm trying to code a BACKUP LOG query to run every 15 minutes and create a separate date-time-stamped TRN. I have several questions starting with - should I be doing this Is it better to create separate LOGs or append to one Isn't it true that the only time I'll need the LOGs is when I have a crash and that then I'll need to RESTORE in date-time-order
I'm doing a FULL backup every 6 hours and intend on automating deleting the TRNs on a successful completion of the BAK.
The following code runs fine and creates a date-time-stamped TRN but doesn't do what I want, as it overwrites the first TRN, so how do I create, say, four JOBSTEPs and get a JOBSTEP @COMMAND to run the SETs
USE
msdbIF
EXISTS (SELECT Name FROM sysjobs WHERE Name = 'jobDBBackupWedb_1Log') EXEC sp_delete_job @job_name = 'jobDBBackupWedb_1Log'GO
DECLARE
@now char(14) -- current date in the form of yyyymmddhhmmssDECLARE
@dbName sysname -- database name to include date-time-stampDECLARE
@Cmd nvarchar(260) -- variable used to build JobStep commandSET
@now = REPLACE(REPLACE(REPLACE(CONVERT(VARCHAR(50), GETDATE(), 120), '-', ''), ' ', ''), ':', '')SET
@dbName = 'Wedb_1_' + @now + '_.trn'SET
@Cmd = 'BACKUP LOG Wedb_1 TO DISK = ' + CHAR(39) + '\\SERVER1\D$\SQLDatabases\Backup\WebEoc\' + @dbName + CHAR(39)
EXEC
sp_add_job@Job_Name
= 'jobDBBackupWedb_1Log',@Description
= 'Run Wedb_1 DB Backup Transaction Log Every 15 Minutes',@Category_Name
= 'Database Maintenance'EXEC
sp_add_jobstep@Job_Name
= 'jobDBBackupWedb_1Log',@step_name
= 'DB_Backup_Log',@step_id
= 1,@Database_Name
= 'Master',@subsystem
= 'TSQL',@command
= @Cmd/*
Start time for the Transaction Log backups is seven and one half minutes after midnight
to not conflict with the Full database backups run every 6 hours starting at midnight.
The Transaction Log backups are to be run every fifteen minutes.
*/
EXEC
sp_Add_JobSchedule@Job_Name
= 'jobDBBackupWedb_1Log',@Name
= 'schedDB_BackupLog',@Freq_Type
= 4, -- Daily@Freq_Interval
= 1, -- Each day@Freq_Subday_Type
= 0x4, -- Interval in minutes@Freq_Subday_Interval
= 15, -- Every fifteen minutes@Active_Start_Time
= 000730 -- Start Time is seven and one half minutes after midnight --@Active_End_Time = 235959 -- End Time is next midnightEXEC
sp_Add_JobServer@Job_Name
= 'jobDBBackupWedb_1Log'GO