SQL Server 2014 – Clean Up Log Files

loggingsql server 2014

We had a disk alert pop up today on a SQL 2014 Enterprise Server telling us a drive was getting full on one of our servers. On investigation we found that the majority of the space was being used by the MSSQL Logs folder (G:\MSSQL12.MSSQLSERVER\MSSQL\Log).

We have log files going back over 2 years on this drive. Most of the files are created by Ola Hallengren's backup stored procs running transaction log backups every 5 minutes (DR requirements).

We'd like to keep the last 1-2 months worth in case something goes wrong. Is there a way that we can automate clean up of these log files from within SQL, or should we look at creating some sort of powershell/batch file to clean them up?

Best Answer

Ola's script does have a clean up job named 'Output File Cleanup' to clean up log files. Just schedule it with the required retention and you should be good to go.