Set up a Test TFS environment with production databases

I get this question quite a lot. We have a production environment and we want a Test environment for TFS. A Test TFS is quite useful for testing upgrades, setting up builds or testing out some build tasks or just as a sandbox for users who you do not trust with production data 🙂

Although it is not really hard to do and I have done it a few times, I always tend to forget some steps in this process so Iit is time to create a blog post. Is it not useful for you (dear readers) then it is at least useful for myself.

The post is not really exhaustive. Details on the various steps can be found easily with google or with the links I provide.

There are 2 ways of getting this done.

  • By attaching “detached” Team Project Collection Databases to your running TFS
  • By using the “operational” backups of Team Foundation Server

This post describes the second scenari, and I left SharePoint out of scope.

The steps

Installing a clean Team Foundation Server

Assuming you do not have a Test environment yet, it is wise to just set up a new, fresh and crispy installation of Team Foundation Server. Running the same version as your production TFS. If possible try to choose the same infrastructure. So a dual server if you have a dual server installation on Production. That is preferred but not required.

Follow these links to install a clean TFS

When you have set

Backup the databases

Of course you need to backup the data from production in order to restore it on Test. TFS has quite some databases you need to backup. Besides that you need to backup your reporting encrytion key and “if needed” your analysis cube.

Shut down all TFS activity on Test

To make sure you are not changing anything during migration it is wise to shut down all TFS Services so that nothing can be reached,

You can use the TfsServiceControl quiesce|unquiesce for that

Restore the Databases

After you have backupped your databases, you can restore them on the Test environment. Make sure that you restore all the databases of ALL collection that are attached in the Tfs_Configuration database. Just overwrite the existing databases. You can either restore the database by hand, or use the scheduled backups in the TFS Admin Console. Make sure you have the backupsettings.xml

Also restore the Reporting Encryption key to decrypt the connection information in the TFS Report database

Fix mapping and start services

Then you need to update some things in order to get everything to work. You need to remap the databases to get the connectionstring right.You can do this by executing the command

TfsConfig.exe RemapDB

TfsConfig can be found in the C:\Program Files\Team Foundation Server\Tools folder

Another important  thing you need to do is to give the collection a new GUID. Why? Visual Studio caches information from TFS and uses the ID of the Configuration database. When you do not change this, it mixes the production cache with the test cache and you might get unexpected behavior.For this you can execute

TfsConfig.exe changeserverid

Now the serverID has changed you have a problem. The application tier is still looking at the “old” id. You need to update the web.config in c:\Program Files\Microsoft Team Foundation Server 11.0\Application Tier\Web Services\web.config to point to the new ID. This can be found in the configuration database in the tbl_servicehost table

After this you can run the

TfsServiceControl unquiesce

command to start the TFS Service

Fix URL and Service Accounts

When you start the services, you need to fix some accounts and rights. Also the URL under which the services are available should change.

You can use the TFS Admin Console to update the URL, service account and admin console users. I would also recommend to clear the SMTP settings so that users don’t get alerts from the Test Server


You should also do this on the report Tab and fill ion the right accounts for reporting services.

(Optionally) Rebuild Process Warehouse

If you don’t want to wait for the schedule to kick off you can kick of the rebuild of the data warehouse manually. to do this you can use the WarehouseControlService which can be accessed on http://[tfs]:8080/tfs/Teamfoundation/Administartion/v3.0/WarehouseControlService



You can also choose to completely rebuild the schema as well. Beware that if you do that you lose some of the historical information. For example build and work items that were permanently destroyed

Invalidate cache

Then, to make sure everything is cool an fresh, invalidate the cache of the clients so that they really are forced to get the uncached information.

Invalidate cache

Test and enjoy

If everything went well, the server is now up and running on your Test environment!

5 Responses to “Set up a Test TFS environment with production databases”

  1. It’s possible to restore the backups taken with TFS Admin console (Scheduled Backups option) on another server?

    • Yes it is. Just make sure you have the xml files with the settings

      • Indeed it worked but with couple of modifications:
        1. you need to change the database name from BackupSettings.xml to point to the second server
        2. you need to change the ApplicationId from the web.config to match the hostId value from [Tfs_Configuration].[dbo].[tbl_ServiceHost]


  1. Visual Studio – Developer Top Ten for Feb 4th, 2016 - Dmitry Lyalin - February 4, 2016

    […] Set up a Test TFS environment with Production Databases by Rene van Osnabrugge […]

  2. Visual Studio – Developer Top Ten for Feb 5th, 2016 - Dmitry Lyalin - February 5, 2016

    […] Set up a Test TFS environment with production databases by Rene van Osnabrugge […]

%d bloggers like this: