Monday, June 20, 2011

SBS 2008 - Cleanup Large Sharepoint Log files

http://smartbserver.net/2011/01/wss-db-large/
http://support.microsoft.com/kb/2000544



1. Connect to windows internal database by using SQL Management Studio Express. Use \\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query as the database name.

2. Right click on sharepoint database > Properties. If you get an error message saying insufficient rights, run the query below to set the owner

Use [SharePoint_Config_*********]
go
exec sp_changedbowner 'domain\administrator'

3. In properties > options, change database recovery model from full to simple.

4. Right click on the database and click on new query. paste the commands below and execute.

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=''C:\windows\temp\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=''C:\windows\temp\after.bkf''';
execute(@ConfigDBCmd);
go

This script will create two backup files (before.bkf and after.bkf) in C:\windows\temp.