Prevent Exchange Log volume from running out of space

Have you ever arrived at work to find the Exchange backup hasn’t run over the weekend, the logs volume is out of space, and the Storage Group is off line?  This little utility will prevent this from happening by NTFS compressing the oldest logs until the free space is at an acceptable limit to run a backup and clear down the logs.

Note that to restore an exchange full backup you dont need the logs.  If you do an incremental/differential backup however, you may need to compress some or all of them to make the logs fit during a restore.

Schedule this to run every 30 minutes, and it will check the space threshold and if necessary, compress enough files to keep the free space above the threshold.



@echo off

rem this will determine the free space of the Log volume and compress the oldest logs until

rem the free space is above the set threshold.

rem Written by Leon Funnell 04/04/2005



rem change the values below to suit your configuration:

rem the threshold is in bytes – example below is 4GB

set threshold=4000000000

set DriveToMonitor=L:

set FolderToCompress=L:\exchsrvr\mdbdata

set FilesToCompress=*.log


echo Monitoring %DriveToMonitor% for threshold %threshold% bytes


rem Sets the variable freespace to the space available on DriveToMonitor

call :freespace q:


if /i “%freespace”% geq “%threshold%” goto :done


echo Free Space is %freespace% bytes – We need to compress some files!

echo Compressing %FolderToCompress%\%FilesToCompress%


for /f “delims=\” %%i in (‘dir %FolderToCompress%\%FilesToCompress% /b /od’) do call :testCompressed “%FolderToCompress%\%%i” %threshold% %DriveToMonitor%

goto :done



call :freespace %DriveToMonitor%

echo Free Space on %DriveToMonitor% is OK –    %freespace% bytes



goto :eof


rem ————————————————————————————–


rem Tests if the file passed is compressed


call :freespace %3

if /i “%freespace%” geq “%2” goto :eof


compact /a %1 | find “=” | find “1   ” > nul

if ERRORLEVEL 1 goto :eof

if ERRORLEVEL 0 call :CompressFiles %1 %2 %3


goto :eof


rem ————————————————————————————–


Rem Compresses files until threshold is reached then exits


call :freespace %3

if /i “%freespace%” geq “%2” goto :eof

echo Compacting %1

compact /c %1 >nul

goto :eof


rem ————————————————————————————–


Rem finds free space of given drive

for /f “tokens=3,4,5” %%a in (‘dir %1 /-c’) do if “%%b %%c”==”bytes free” set freespace=%%a

goto :eof

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top