I put a sysadmin hat on this morning (makes a change!) as I spotted that one of our TFS servers was running out of disk space on drive C: - yet this was quite a beefy box, multiple spindles and all sorts.
On closer inspection, all the TFS and WSS and Reporting Services databases had been installed on the C: drive. So it was time to move them. I thought I'd jot down the basic approach here.
1. Logon to your Team Foundation Server as the "TFSSetup" user.
2. Stop all TFS, WSS and Reporting Services activities.
The quick way to do this for me was:
iisreset /stop
net stop "TFSServerScheduler"
net stop "SQL Server Reporting Services (MSSQLSERVER)"
3. Detach the relevant databases.
I scripted this out fairly quickly in SQL as follows:
USE [master]
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsActivityLogging', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsBuild', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsIntegration', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsVersionControl', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsWorkItemTracking', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsWorkItemTrackingAttachments', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'TfsWarehouse', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'ReportServer', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'ReportServerTempDB', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'STS_Config_TFS', @keepfulltextindexfile=N'true'
GO
EXEC master.dbo.sp_detach_db @dbname = N'STS_Content_TFS', @keepfulltextindexfile=N'true'
GO
3. Move the .ldf and .mdf files to their correct locations (e.g. in my installation I have logfiles on D: and Data on E:)
4. Re-attach the databases.
You can use the following SQL as a template:
USE [master]
GO
CREATE DATABASE [STS_Content_TFS] ON
( FILENAME = N'E:\MSSQL\data\STS_Content_TFS.mdf' ),
( FILENAME = N'D:\MSSQL\logs\STS_Content_TFS_log.LDF' )
FOR ATTACH
GO
if not exists (select name from master.sys.databases sd where name = N'STS_Content_TFS' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [STS_Content_TFS].dbo.sp_changedbowner @loginame=N'YOURDOMAIN\tfssetup', @map=false
GO
5. Restart the relevant services.
net start "SQL Server Reporting Services (MSSQLSERVER)"
net start "TFSServerScheduler"
iisreset /start