Windows SBS 2008 server out of disk space
I’ve been seeing a lot of Windows 2008 SBS servers running out of disk space lately on the C drive.
This causes Exchange to stop working due to the “back pressure” feature, which has been the first clue to the problem. After a bit of searching I found several area’s where log files can grow.
The 4 main area’s I found are :
- Active Directory Certificate Services
- IIS Log Files
- SBS Data Collector log (DataserviceComponents.log)
- Sharepoint SQL logs
I found a great script at SBSfaqs (http://www.sbsfaq.com/?p=1598) and updated the script to include all 4 points above and be able to select which options to run.
You will need to save the 2 SQL files and the batch file to a folder called “SBS Cleaner” on the root of the E drive. Run the batch file as administrator.
Please find the code for each file below.
Other Sources:
http://support.microsoft.com/kb/2000544
http://blogs.technet.com/b/sbs/archive/2010/03/02/recovering-disk-space-on-the-c-drive-in-small-business-server-2008.aspx
http://oxfordsbsguy.com/2012/10/31/sbs-2008-disk-space-and-the-dataservicecomponents-log-file/
Copy the following code and save it as logshrink.sql
declare @ConfigDB varchar(255); declare @ConfigDBLog varchar(255); declare @ConfigDBCmd varchar(255); select @ConfigDB = name from sys.databases where name like 'SharePoint_Config_%'; set @ConfigDBCmd = 'BACKUP database [' + RTRIM(@ConfigDB) + '] to disk=''before.bkf'''; execute(@ConfigDBCmd); set @ConfigDBCmd = 'use [' + RTRIM(@COnfigDB) + ']'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'BACKUP LOG [' + RTRIM(@ConfigDB) + '] WITH TRUNCATE_ONLY'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'use [' + RTRIM(@COnfigDB) + ']'; execute(@ConfigDBCmd); select @ConfigDBLog = name from sys.database_files where name like 'SharePoint_Config%_log'; set @ConfigDBCmd = 'use [' + RTRIM(@ConfigDB) + '] DBCC SHRINKFILE([' + RTRIM(@ConfigDB) + '_log],1)'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'BACKUP database [' + RTRIM(@ConfigDB) + '] to disk=''after.bkf'''; execute(@ConfigDBCmd); go
Copy the following code and save it as logshrinkshareweb.sql
declare @ConfigDB varchar(255); declare @ConfigDBLog varchar(255); declare @ConfigDBCmd varchar(255); select @ConfigDB = name from sys.databases where name like 'ShareWebDb%'; set @ConfigDBCmd = 'BACKUP database [' + RTRIM(@ConfigDB) + '] to disk=''beforeWeb.bkf'''; execute(@ConfigDBCmd); set @ConfigDBCmd = 'use [' + RTRIM(@COnfigDB) + ']'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'BACKUP LOG [' + RTRIM(@ConfigDB) + '] WITH TRUNCATE_ONLY'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'use [' + RTRIM(@COnfigDB) + ']'; execute(@ConfigDBCmd); select @ConfigDBLog = name from sys.database_files where name like 'ShareWebDb%_log'; set @ConfigDBCmd = 'use [' + RTRIM(@ConfigDB) + '] DBCC SHRINKFILE([' + RTRIM(@ConfigDB) + '_log],1)'; execute(@ConfigDBCmd); set @ConfigDBCmd = 'BACKUP database [' + RTRIM(@ConfigDB) + '] to disk=''afterWeb.bkf'''; execute(@ConfigDBCmd); go
Copy the following code into a SBS Cleaner.bat file
@echo off rem Script to clean up disk space on SBS 2008 servers rem Downloaded from SBSfaq.com rem V1.0 - March 28th, 2010 rem v1.1 - Feb 23rd, 2012 - fixed typo in certlog path rem v2.0 updated by Kettlewell.IT 17 Oct 2013 rem add choices and SBS Data Collection Monitoring rem updated IIS files to be over 30 days before deleting (thanks to comment from JVR at SBSfaq.com) rem added logging file. rem PLEASE READ rem It creates a log file SBSCleaner.log in the folder it is run from. rem It must be Run As Administrator rem You need 2 files logshrink.sql and logshrinkshareweb.sql in the same folder for the SQL log shrinking. :START ECHO C Drive cleaner for SBS 2008 ECHO Please Make sure you have a full backup before running this program. No one is responsible for any data loss that may occur. ECHO C Drive cleaner for SBS 2008 was run at : >> "SBSCleaner.log" ECHO %date% %time% >> "SBSCleaner.log" ECHO DISK SPACE BEFORE: >> "SBSCleaner.log" wmic logicaldisk where "deviceid='C:'" get freespace >> "SBSCleaner.log" ECHO . >> "SBSCleaner.log" CHOICE /M "Do you want to clean up the Active Directory Certificate Services ?" IF ERRORLEVEL 2 GOTO IIS IF ERRORLEVEL 1 GOTO CERT rem Certificate Services Logs :CERT net stop "Active Directory Certificate Services" >> "SBSCleaner.log"forfiles /d -30 /p "%windir%\system32\certlog" /m *.log /c "cmd /c del @file" >> "SBSCleaner.log" forfiles /d -30 /p "%windir%\system32\certlog" /m *.chk /c "cmd /c del @file" >> "SBSCleaner.log" forfiles /d -30 /p "%windir%\system32\certlog" /m *.jrs /c "cmd /c del @file" >> "SBSCleaner.log" net start "Active Directory Certificate Services" >> "SBSCleaner.log" ECHO Active Directory Certificate Services Cleaned ! ECHO Active Directory Certificate Services Cleaned ! >> "SBSCleaner.log" rem IIS Log Files :IIS CHOICE /M "Do you want to clean up the IIS logs ?" IF ERRORLEVEL 2 GOTO SBS IF ERRORLEVEL 1 GOTO IIS2 :IIS2 forfiles /d -30 /p "C:\inetpub\logs\LogFiles" /m *.log /s /c "cmd /c del @file" >> "SBSCleaner.log" ECHO IIS Logs Cleaned ! ECHO IIS Logs Cleaned ! >> "SBSCleaner.log" REM SBS Monitoring Logs :SBS CHOICE /M "Do you want to clean up the SBS Data Collector log ?" IF ERRORLEVEL 2 GOTO :SQL IF ERRORLEVEL 1 GOTO :SBS2 :SBS2 Net stop "DataCollectorSvc" >> "SBSCleaner.log" del "C:\program files\Windows Small business Server\logs\monitoringServiceLogs\DataserviceComponents.log" Net start "DataCollectorSvc" >> "SBSCleaner.log" ECHO SBS Data Collector Log Cleaned! ECHO SBS Data Collector Log Cleaned! >> "SBSCleaner.log" :SQL CHOICE /M "Do you want to clean up the Sharepoint SQL logs ?" IF ERRORLEVEL 2 GOTO :END IF ERRORLEVEL 1 GOTO :SQL1 :SQL1 sqlcmd -S \\.\pipe\mssql$microsoft##ssee\sql\query -E -i "E:\SBS cleaner\logshrink.sql" sqlcmd -S \\.\pipe\mssql$microsoft##ssee\sql\query -E -i "E:\SBS cleaner\logshrinkshareweb.sql" ECHO SQL Log files Cleaned! ECHO SQL Log files Cleaned! >> "SBSCleaner.log" :END ECHO DISK SPACE AFTER: >> "SBSCleaner.log" wmic logicaldisk where "deviceid='C:'" get freespace /format:value >> "SBSCleaner.log" ECHO . ECHO . ECHO Script Finished PAUSE
3 Comments
Omega_Masha!
I still have something else that s slowly consuming many GBs of SBS disk space. Have had IIS logs under control for years, but didn t know about CertLog, from which I recovered 2GB. Every little bit helps! Thanks, and will continue my search for the other culprit(s).
Ian
Hi Omega_Masha
Glad you found this helpful.
Ian
Jay Holt
This is a fine set of scripts but they are nearly useless in this format. Whatever blog software you use tried to be helpful and has made all of the double and single quotes pretty for you. The only way these scripts can be used now is to try and strip all that out and put the proper quote marks back in.