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