0

I have an environment that we want a full backup once a week (if we fail we can tolerate up to 2 weeks) but the diffs have to be running every day, every day but not the days when the full is scheduled to run.

to achieve this I have create a first step called check day on my diff backup job and I put there something like this:

DECLARE @DateInt INT = CAST(CONVERT(VARCHAR(8),GETDATE(),112) AS INT)

DECLARE @NextFullBU INT = ( SELECT next_run_date
                            FROM sysjobschedules b
                            JOIN sysjobs A
                            ON A.job_id = B.job_id
                            JOIN sysschedules s
                            ON b.schedule_id = s.schedule_id
                            WHERE a.name = 'DatabaseBackup - USER_DATABASES - FULL'
                            AND s.name = 'DatabaseBackup - USER_DATABASES - FULL'
                          )

IF @DateInt = @NextFullBU
BEGIN
  RAISERROR ('This job must not execute today because of the FULL backup.',16,127)
END

However, that marks the job as failed, which is not in reality.

enter image description here

how can I work around that?

0

2 Answers 2

2

You can set up the weekly schedule to run on every day except on the day of the full backup:

Showing the weekly schedule setup in SSMS GUI

1
  • that is a solution too, there are other things that make me tend not to go through this route though. but definitely it is valid. cheers. For instance, if I changed the schedule of the full backup, or add another full backup schedule, then I would have to change it here as well, and take a note or set up another job somewhere to set it back the next day. Commented Jul 31 at 8:00
1

how can I work around that?

Put this condition in 'DatabaseBackup - USER_DATABASES - DIFF' step like

IF @DateInt != @NextFullBU
BEGIN
 EXECUTE [dbo].[DatabaseBackup]
 @Databases = 'USER_DATABASES',
 @Directory = NULL,
 @BackupType = 'DIFF',
 @Verify = 'Y',
 @CleanupTime = 378,
 @CheckSum = 'Y',
 @LogToTable = 'N'
END
1
  • +1, that's a very good idea, I am not sure how it did not come to my mind before. Commented Jul 31 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.