I'm looking to do something like this:
Daily backups held for 14 days
BiMonthly backups held for 6 months
Yearly backups held for 4 years
DECLARE @exitcode int
DECLARE @sqlerrorcode int
Declare @backupCMD varchar(4000) = ''
,@biMonthly varchar(500) = ''
,@yearly varchar(500) = ''
Select @biMonthly = case when datepart(day, getdate()) in (1,15) then ', COPYTO = ''Link NAS'', ERASEFILES = 190, FILEOPTIONS = 5' else '' end
,@yearly = case when DATEPART(dayofyear, getdate()) = 1 then ', COPYTO = ''LINK NAS'', ERASEFILES = 1825, FILEOPTIONS = 5' else '' end
set @backupCMD = '-SQL "BACKUP DATABASE [MyDB] TO DISK = ''L:\Backup\<AUTO>.sqb'' WITH ERASEFILES_ATSTART = 7' +
', FILEOPTIONS = 4, CHECKSUM, DISKRETRYINTERVAL = 30, DISKRETRYCOUNT = 10, COMPRESSION = 4' +
', COPYTO = ''\\SERVER\SQLBACKUP\'', ERASEFILES = 14, FILEOPTIONS = 5' +
@biMonthly +
@yearly +
', INIT, THREADCOUNT = 23"'
Select @backupCMD
EXECUTE master..sqlbackup @backupCMD, @exitcode OUT, @sqlerrorcode OUT
IF (@exitcode >= 500) OR (@sqlerrorcode <> 0)
BEGIN
RAISERROR ('SQL Backup failed with exit code: %d SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode)
END
Is this supported? Should I approach this by a differnt means?
Daily backups held for 14 days
BiMonthly backups held for 6 months
Yearly backups held for 4 years
DECLARE @exitcode int
DECLARE @sqlerrorcode int
Declare @backupCMD varchar(4000) = ''
,@biMonthly varchar(500) = ''
,@yearly varchar(500) = ''
Select @biMonthly = case when datepart(day, getdate()) in (1,15) then ', COPYTO = ''Link NAS'', ERASEFILES = 190, FILEOPTIONS = 5' else '' end
,@yearly = case when DATEPART(dayofyear, getdate()) = 1 then ', COPYTO = ''LINK NAS'', ERASEFILES = 1825, FILEOPTIONS = 5' else '' end
set @backupCMD = '-SQL "BACKUP DATABASE [MyDB] TO DISK = ''L:\Backup\<AUTO>.sqb'' WITH ERASEFILES_ATSTART = 7' +
', FILEOPTIONS = 4, CHECKSUM, DISKRETRYINTERVAL = 30, DISKRETRYCOUNT = 10, COMPRESSION = 4' +
', COPYTO = ''\\SERVER\SQLBACKUP\'', ERASEFILES = 14, FILEOPTIONS = 5' +
@biMonthly +
@yearly +
', INIT, THREADCOUNT = 23"'
Select @backupCMD
EXECUTE master..sqlbackup @backupCMD, @exitcode OUT, @sqlerrorcode OUT
IF (@exitcode >= 500) OR (@sqlerrorcode <> 0)
BEGIN
RAISERROR ('SQL Backup failed with exit code: %d SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode)
END
Is this supported? Should I approach this by a differnt means?