Prevent Exchange Log volume from running out of space

  • Section(s): Exchange
  • Published on Apr 28, 2005.
  • Last Modified on Apr 28, 2005.
  • Last Modified by Leon Funnell.
  • Rated 5 out of 5 based on 1 votes.
Have you ever arrived at work to find the backup hasnt run over the weekend, the logs volume is out of space, and the Storage Group is off line? This little batch file will prevent this from happening by NTFS compressing the oldest logs until the free space is at an acceptable limit to run a backup.

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.

MAKESPACE.CMD:

-------------------------------------------------------------------------------------------------------

@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

 

setlocal

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

 

:done

call :freespace %DriveToMonitor%

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

endlocal

 

goto :eof

 

rem --------------------------------------------------------------------------------------

:testCompressed

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 --------------------------------------------------------------------------------------

:CompressFiles

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 --------------------------------------------------------------------------------------

:freespace

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 Leon Funnell

Systems Engineer/Architect for 350+ user base for a Global Insurance Underwriter

Share this article


Article not looking right or info is missing? Let us know so that we can fix it: .


Receive all the latest articles by email!

Receive Real-Time & Monthly WindowsNetworking.com article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become a WindowsNetworking.com member!

Discuss your network issues with thousands of other network administrators. Click here to join!

Community Area

Log in | Register

Limited time offer!

SolarWinds screenshot

Subscribe to WindowsNetworking.com Newsletters today and get a free copy of the new SolarWinds Exchange Monitor!

Readers' Choice

Which is your preferred software-based Backup solution?