Sql-server – Solution for the deletion of old Database Backups for Linux SQL Server 2017 after Backups created with Ola Hallengren scripts

linuxsql-server-2017

I have a problem when I want to delete older backups, I've created with Ola Halengreen scripts.

USE Maintenance
EXECUTE dbo.DatabaseBackup
 @Databases = 'USER_DATABASES',
 @Directory ='/mssql/backup/',
 @DirectoryStructure ='${InstanceName}{DirectorySeparator}{DatabaseName}',
 @Filename='{DatabaseName}_{BackupType}_{Year}{Month}{Day}_{Hour}{Minute}{Second}_{FileNumber}.{FileExtension}',
 @BackupType = 'FULL',
 @Compress = 'Y',
 @CleanupTime = 3

I got the following error message:

The value for the parameter @CleanupTime is not supported. Cleanup is not >supported on Linux.

So far so good, but whats the best way now to delete old Backups without to destroy the Backup chain?

My frist thought was to have a script to delete

#!/bin/sh
find /mssql/backup -name "*.bak" -type f -mtime +3 -exec rm -f {} \;
find /mssql/backup -name "*.trn" -type f -mtime +4 -exec rm -f {} \;

The internal system of the SQL Server Instance will not recognize the clean up after the script was executed. The Backup History in the internal Backup Management will not updated and in the case of a recovery the system wants to have backups which are not existing anymore.

So does anyone have a solution to the problem?

Best Answer

I don't know if you already found a solution to your problem, but as of this moment, the extended system stored procedure xp_delete_files is supported on SQL Server 2017 when hosted on a Linux machine.

You can edit Ola's script for database backup and remove the check when the cleanup parameter is being verified, to allow usage on a Linux machine.

I've tried that and the removal of old backups functions just ok, as when run on Windows.