Delete backup issue
pcorujo
Posts: 14
Hi,
I am trying to take backups locally as well as copy them to another box and then delete backups older than 2 days on both servers. My current code pasted below does take and copy the backups but never deletes. Is there a problem with my code?
DECLARE @exitcode int
DECLARE @sqlerrorcode int
exec master..sqlbackup N'-SQL "BACKUP DATABASES [*]
TO DISK = ''H:\FullBackups\<AUTO>''
WITH NAME = ''<AUTO>'',
DESCRIPTION = ''<AUTO>'',
VERIFY,
COMPRESSION = 3, COPYTO = ''\\TMPDB103\e$\FullBackupsFromSeoSiteDB'',
ERASEFILES = 2, FILEOPTIONS = 3, THREADCOUNT = 6"',
@exitcode OUTPUT, @sqlerrorcode OUTPUT
IF (@exitcode <>0) OR (@sqlerrorcode <> 0)
BEGIN
RAISERROR ('SQL Backup job failed with exitcode: %d SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode)
END
Thank you all in advance.
I am trying to take backups locally as well as copy them to another box and then delete backups older than 2 days on both servers. My current code pasted below does take and copy the backups but never deletes. Is there a problem with my code?
DECLARE @exitcode int
DECLARE @sqlerrorcode int
exec master..sqlbackup N'-SQL "BACKUP DATABASES [*]
TO DISK = ''H:\FullBackups\<AUTO>''
WITH NAME = ''<AUTO>'',
DESCRIPTION = ''<AUTO>'',
VERIFY,
COMPRESSION = 3, COPYTO = ''\\TMPDB103\e$\FullBackupsFromSeoSiteDB'',
ERASEFILES = 2, FILEOPTIONS = 3, THREADCOUNT = 6"',
@exitcode OUTPUT, @sqlerrorcode OUTPUT
IF (@exitcode <>0) OR (@sqlerrorcode <> 0)
BEGIN
RAISERROR ('SQL Backup job failed with exitcode: %d SQL error code: %d', 16, 1, @exitcode, @sqlerrorcode)
END
Thank you all in advance.
Comments
The archive flag is used by Windows to indicate that the file has not been archived. Usually, users would back up the files to tape, which then unsets the archive flag. Thus, you would use this option (FILEOPTIONS value 2) only when you have an application that archives your backup files, which then clears the archive flag, allowing SQL Backup to delete the file if it's older than the specified interval.
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8
In your case, since you do not archive your files, you can leave out FILEOPTIONS value 2, and just use FILEOPTIONS value 1 i.e.
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8