Erase Files not working
spider
Posts: 3
Hi Guys
I have the following script to backup all user databases, I can not get it to erase the old backup files, they are now 2 days old, the user has permission to delete the files, I'm sure its something silly, can someone point me in the right direction please. It just keeps reporting backup file exists.
SET NOCOUNT ON
DECLARE @dbname sysname
DECLARE @backupstring varchar(1000)
DECLARE backup_cursor CURSOR FOR
SELECT name
FROM sysdatabases
WHERE dbid > 4
OPEN backup_cursor
FETCH NEXT FROM backup_cursor
INTO @dbname
@FETCH_STATUS = 0
BEGIN
set @backupstring = '-SQL "BACKUP DATABASE TO DISK = ''d:\backuprg\'+ @dbname +'.sqb '' " ERASEFILES_ATSTART = 1'
exec master..sqlbackup @backupstring
FETCH NEXT FROM backup_cursor
INTO @dbname
END
CLOSE backup_cursor
DEALLOCATE backup_cursor
I have the following script to backup all user databases, I can not get it to erase the old backup files, they are now 2 days old, the user has permission to delete the files, I'm sure its something silly, can someone point me in the right direction please. It just keeps reporting backup file exists.
SET NOCOUNT ON
DECLARE @dbname sysname
DECLARE @backupstring varchar(1000)
DECLARE backup_cursor CURSOR FOR
SELECT name
FROM sysdatabases
WHERE dbid > 4
OPEN backup_cursor
FETCH NEXT FROM backup_cursor
INTO @dbname
@FETCH_STATUS = 0
BEGIN
set @backupstring = '-SQL "BACKUP DATABASE TO DISK = ''d:\backuprg\'+ @dbname +'.sqb '' " ERASEFILES_ATSTART = 1'
exec master..sqlbackup @backupstring
FETCH NEXT FROM backup_cursor
INTO @dbname
END
CLOSE backup_cursor
DEALLOCATE backup_cursor
Comments
Contact support for the patched version.
SQL Backup Consultant Developer
Associate, Yohz Software
Beyond compression - SQL Backup goodies under the hood, updated for version 8
SET NOCOUNT ON
DECLARE @dbname sysname
DECLARE @backupstring varchar(1000)
DECLARE backup_cursor CURSOR FOR
SELECT name
FROM sysdatabases
WHERE dbid > 4
OPEN backup_cursor
FETCH NEXT FROM backup_cursor
INTO @dbname
@FETCH_STATUS = 0
BEGIN
set @backupstring = '-SQL "BACKUP DATABASE TO DISK = ''e:\backup\'+ @dbname +'.sqb'' WITH NAME = '''+ @dbname +''', INIT, COMPRESSION = 1" -E'
exec master..sqlbackup @backupstring
FETCH NEXT FROM backup_cursor
INTO @dbname
END
CLOSE backup_cursor
DEALLOCATE backup_cursor