Thursday 7 May 2009

Moving Team Foundation Server from Physical to a virtual machine

We have been using a single-machine installation of TFS for quite a few years now. The single-machine installation with Application & Data tiers on a single server serves us well. We recently moved from TFS 2005 to TFS 2008 but remained on SQL Server 2005. A recent review of the project identified potential benefits of moving TFS to a virtual machine. Microsoft’s stance on this is that the application tier of TFS is supported in Hyper V but SQL Server 2005 is not. However, browsing through various posts and example scenarios we decided to go for it.


Microsoft has provided a complete guide of moving from one hardware configuration to another, which is fairly comprehensive. Here I will write only from the perspective of moving a single server.


Note that in our scenario, we are also moving the domain of our TFS server. Some of these steps are not needed if your new TFS server uses the same server. Also, I assume that you have already had TFS installed in your new server. To install the TFS server you can download TFS installation guide from here If you have MSDN subscription, you can avoid the pain of installing everything by simply downloading TFS VM

Existing TFS Machine:

  1. Take a backup of Encryption key from your Reporting Server.
    a. For this, open Start menu >> Microsoft SQL Server 2005 >> Configuration Tools >> Reporting Service Configuration.
    b. Ensure that the Machine & Instance Names are correct and click Connect.
    c. Click Encryption Keys from left menu and click on the Backup button.
    d. Save the key file to a location from where you can read it in the new server.

  2. Take a backup of existing TFS databases and copy them out. I use LiteSpeed from Quest Software to take backups but simple SQL scripts or a manual backup of all databases would do the same. The databases that you need to take backup of are


  • ReportServer

  • ReportServerTempDB

  • TfsBuild

  • TfsIntegration

  • TfsVersionControl

  • TfsWarehouse

  • TfsWorkItemTracking

  • TfsWorkItemTrackingAttachments

Make sure that you copy the backup files & encryption keys to a place from where they can be read by the new server.


New TFS Machine:


Preparation:


1. Copy the backed up databases to local drive.


2. From a Command Prompt window, run



  • net stop TFSServerScheduler

  • net stop SPTimer

3. In Internet Information Services (IIS) Manager, stop the following app pools



  • ReportServer

  • TFS AppPool

4. Stop the Reporting Service instance. To do this



  • For this, open Start menu >> Microsoft SQL Server 2005 >> Configuration Tools >> Reporting Service Configuration.

  • Ensure that the Machine & Instance Names are correct and click Connect.

  • Click Server Status from left menu and click on the stop button.

Database Restoration:
Connect to SQL server using SQL Server Management Studio and restore the following database in the same order:


• ReportServer
• ReportServerTempDB
• TfsBuild
• TfsIntegration
• TfsVersionControl
• TfsWarehouse
• TfsWorkItemTracking
• TfsWorkItemTrackingAttachments



Setting Database users:
Since the database restored are from a different machine, with a different domain, the database users need to be set up again.

1. Click Start, click All Programs, Microsoft SQL Server 2005, and then click SQL Server Management Studio.

2. In the Connect to server dialog, click OK.

3. Expand Databases.

4. Expand the database “TfsActivityLogging”. Expand Security and then expand Schema. Name the new Schema as \. Expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select role “TFSExecRole”. In the Owned Schema section, select schema “Domain \”. Delete the user and schema \.

5. Expand the TfsBuild database. Expand Security and then expand Schema. Name the new Schema as \. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select role “TFSExecRole”. In the Owned Schema section, select schema “\”. Delete the user and schema \.

6. Expand the TfsIntegration database. Expand Security and then expand Schema. Name the new Schema as \. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select role “TFSExecRole”. In the Owned Schema section, select schema “\”. Delete the user and schema \.

7. Expand the TfsVersionControl database. Expand Security and then expand Schema. Name the new Schema as \. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select role “TFSExecRole”. In the Owned Schema section. Select schema “\”. Delete the user and schema \.

8. Expand the TfsWarehouse database. Expand Security and then expand Schema. Name the new Schema as \. Create another schema called \TFSReports. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select role “TFSExecRole”. In the Owned Schema section. Select schema “\”. Click New User. Then in the login name browse to the user \TFSReports. Set the user name as \TFSReports. In the Roles section, select role “TFSWarehouseDataReader”. In the Owned Schema section. Select schema “\TFSReports”. Delete users and Schemas \ and \.

9. Expand the TfsWorkItemTracking database. Expand Security and then expand Schema. Name the new Schema as \. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select roles “db_datareader”, “db_datawriter” and “TFSExecRole”. In the Owned Schema section. Select schema “\”. Delete the user and schema \.

10. Expand the TfsWorkItemTrackingAttachments database, Expand Security and then expand Schema. Name the new Schema as \. Now expand Users. Click New User. Then in the login name browse to the user \. Set the user name as \. In the Roles section, select roles “db_owner” and “TFSExecRole”. In the Owned Schema section. Select schema “\”. Delete the user and schema \.


Change Server Name in Tables
Now, since the databases we have restored contains details of the old database. We need to change the name of servers from within the database. I did it by manually changing the serverName in database tables
1. Open table tbl_database in database “TfsIntegration”. Replace the value of column “servername” with the name of new TFS server.


Reconfigure Application Tier
1. From a Command Prompt window, run


C:\Program Files\Microsoft Visual Studio 2008 Team Foundation
Server\Tools\TfsAdminUtil ActivateAT


Reconfigure Report Server
To restore and verify Report Server on the new Team Foundation Server

1. Click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.

2. In the Explorer pane, under the Application Pools node, right-click Report Server, and then click Start.

3. Click Start, click Programs, click Microsoft SQL Server 2005, click Configuration Tools, and then click Reporting Services Configuration.

4. In Report Server Installation Instance Selection, make sure that the computer name is the name of the new Team Foundation application-tier server and that the instance name is MSSQLSERVER, and then click Connect.


5. In the Explorer pane, click Server Status.

6. In the Report Server Status pane, in Instance Properties, click Start.

7. In the Explorer pane, click Database Setup.

8. In the Database Connection pane, make sure that the name of the Team Foundation data-tier server is correct in Server Name, and then click Connect.

9. On the SQL Server Connection Dialog dialog box, click OK.

10. In the Database Connection pane, click Apply.

11. On the SQL Server Connection Dialog dialog box, click OK.

12. Restore the encryption key and remove previous instances of Report Server by doing one of the following:

If you are running SQL Report Server Enterprise Edition


1. In the Explorer pane of Reporting Services Configuration, click Encryption Keys.


2. In the Explorer pane, click Encryptions Keys.


3. On the Encryption Key page, click Restore.


4. On the Encryption Key Information page, type the password for the encryption key file in Password, type or select the backup encryption key .snk file location in Key File, and then
click OK.


5. In the Explorer pane of Reporting Services Configuration, click Initialization.


6. On the Initialization page, select the instance ID that corresponds with the name of the old Team Foundation data-tier server, click Remove, and then click OK.



Note: Do not remove the installation ID that you recorded in the "To save Reporting Service installation IDs and stop services" section of this document.

13. Open Internet Explorer and connect to http://localhost/reports [ http://localhost/reports ] . In Contents, click TfsReportDS.

14. In Connection string, type “Data source=TFSMachineName;initial catalog=TfsWarehouse”. Select option Credentials stored securely in the report. Update the user name and password to reflect the new reporting services service account. Check the checkbox “Use as Windows credentials when connecting to the data source” and then click Apply.

15. Under SQL Server Reporting Services, click Home.

16. In Contents, click TfsOlapReportsDS.


17. In Connection string, type “Data source=TFSMachineName;initial catalog=TfsWarehouse”. Select option Credentials stored securely in the report. Update the user name and password to reflect the new reporting services service account. Check the checkbox “Use as Windows credentials when connecting to the data source” and then click Apply.

18. Click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.

19. In the Explorer pane, under the Application Pools node, right-click Team Foundation Server, and then click Start.

20. Open a Command Prompt window and change directories to drive:\%ProgramFiles%\ Microsoft Visual Studio 2008 Team Foundation Server\Tools. Type the following command, where newDataTierServerName is the name of your new Team Foundation data-tier server, TFSReportServiceAccount is the name of the reporting services service account, and TFSServiceAccount is the name of the Team Foundation Server service account:
SetupWarehouse.exe -o -s newDataTierServerName -d Tfswarehouse -c warehouseschema.xml -ra TFSReportServiceAccount -a TFSServiceAccount –mturl http://TFSServerName:8080

21. On the Team Foundation data-tier server, click Start, click Programs, click Microsoft SQL Server 2005, and then click SQL Server Management Studio.

22. On the Connect to Server dialog box, in Server type, select Database Engine, verify that the server name and authentication values are correct, and then click Connect.

23. In the Object Explorer pane, expand Databases, expand TFSWarehouse, expand tables, right-click dbo._WarehouseConfig, and then click Properties.

24. In Table Properties - _WarehouseConfig, in Select a page, click Permissions.

25. In Users or Roles, click Add.

26. In Select Users or Roles, add the Reporting Services service account (referred to generically as TFSReports), and then click OK.

27. In Table Properties - _WarehouseConfig, click OK.

28. In the Object Explorer pane, click Connect, and select Analysis Services.

29. On the Connect to Server dialog box, make sure that the server name and authentication values are correct, and then click Connect.

30. In the Object Explorer pane, expand Databases, right-click TFSWarehouse, and then click Process.

31. In Process Database - TFSWarehouse, click OK.


Reset Domain Accounts and SID
Please note that these steps are only needed if the domain of the new server is different to the original server

1. From a Command Prompt window



  • Execute C:\Program Files\Microsoft Visual Studio 2008 Team Foundation Server\Tools\TfsAdminUtil Sid.

  • Create users in the domain for all accounts that are listed as a result of last command.

  • Execute C:\Program Files\Microsoft Visual Studio 2008 Team Foundation Server\Tools\TfsAdminUtil Sid /Change

2. Add user \TFSReports to the “administrators” group of the new TFS server.



Restart Services and verification

1. On the Team Foundation application-tier server, change directories to http://localhost/reports.

2. In Contents, click any project, click any one of the default reports in the project, and then verify that it appears correctly.

3. On the new Team Foundation application-tier server, click Start, click Administrative Tools, and then click Internet Information Services (IIS) Manager.

4. In the Explorer pane, expand the Application Pools node, right-click TFS App Pool, and then click Start.

5. On the new Team Foundation application-tier server, click Start, click Administrative Tools, click Services, select the TFSServerScheduler service, and then click Start, if it is not started already. Select the SharePoint Timer Service, and then click Start.

6. On the Team Foundation data-tier server, connect to http://localhost:8080/WorkItemTracking/v1.0/ClientService.asmx.

7. In ClientService, click StampWorkitemCache.

8. In StampWorkitemCache, click Invoke.

Note: The StampWorkitemCache invocation will not return any data.



I hope this post will help you move single-server TFS installation around quickly and easily. If you find any error in any of these steps, please do leave a comment.

2 comments:

Loomy said...

Hi!
I am trying to find a way to protect our TFS installation in terms of backup-restore or to create a disaster recovery plan.

We also have a single-server installation of TFS2008.
What about Sharepoint sites?
Did you manage to get it work?

Thanks,
Dimitris

Alexander Campos C. said...

Hi! I think I have an issue when I got to:
"13. Open Internet Explorer and connect to http://localhost/reports . In Contents, click TfsReportDS."
First, because that URL showed me "The page cannot be found" error; I tried then http://localhost/reportserver and it showed me a list like the following:
Tuesday, March 17, 2009 2:02 PM AMM_test1
Tuesday, March 17, 2009 3:24 PM AMM-Test2
Friday, March 20, 2009 2:07 PM AMM-Test3
Monday, September 21, 2009 2:41 PM MergeExample
Tuesday, March 17, 2009 2:10 PM PruebaJD
Tuesday, March 23, 2010 3:55 PM Test4
Friday, May 04, 2007 12:11 PM TfsOlapReportDS
Friday, May 04, 2007 12:11 PM TfsReportDS
Wednesday, June 06, 2007 2:40 PM 746588 TfsReportDS Model

And second, because when I click TfsReportsDS, I don´t see a way to modify the parameter you said, as the page that loads seems like an xml file, and I dn´t see how to modify it...

I´m doing something wrong, I know that, but don´t know what.. I followed step by step your guide, until I got there... and hit a concrete wall. Any idea? Thanks!