The official guide to Backing up and Restoring TFS 2010 is wonderfully comprehensive, but will make you very dizzy if just want to throw together a quick clone of a TFS instance from DB backups. Why would you want to clone a TFS instance? Well, it’s very useful for testing out changes in a realistic copy of your production system – you wouldn’t go straight to production with half-baked software changes so you shouldn’t with TFS changes either. Examples include a new branching strategy, significant source control restructuring, or experimentation with the build process.
If you are thinking that the TFS Power Tools Backup and Restore wizard does all this anyway, you would be right – but only if you are restoring back to the same machine that the backups came from. If you are restoring to a fresh TFS installation on a different operating system and AD domain it won’t be so simple.
A few caveats:
- This assumes you are have the source TFS instance database backups (e.g. created using the TFS Power Tools backup and restore wizard).
- I have tried to get the process as quick as possible, but I can’t guarantee that it will produce an absolutely perfect working replica. It should however be good enough to play with source control, work items and build.
- Your source and target machines will probably be configured differently from mine, so you may need to take some additional steps. I have included a few troubleshooting ideas at the end.
- I have assumed you are cloning onto an existing standalone TFS installation – with the database and application tiers together on one machine and pre-existing databases. This process will replace the databases, so make sure you don’t want to keep the existing instance!
- Some of the steps are quite hacky, so don’t be tempted to administer your production TFS instance this way!
Here goes:
- Copy the database backups to local machine
- Open a command prompt and issue:
cd C:\Program Files\Microsoft Team Foundation Server 2010\Tools TFSServiceControl.exe quiesce
- Start SQL Server Management Studio
- Note the physical location of the TFS databases e.g. C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA
- Detach all TFS databases:
- TFS_*
- ReportServer
- ReportServer_TempDB
- SharePoint_Config
- WSS_Content
- Delete, rename or move the physical files for the TFS databases
- Start the TFS Admin Console
- Click Team Foundation Backups on the left
- Click Restore Databases on the right
- Follow the Restore Wizard
- Choose the Network Path to restore from
- Modify the SQL server instance to localhost
- Use SQL Server Management Studio to manually restore any failed databases
- Start SQL Server Management Studio
- Locate the Tfs_Configuration database, right-click on it and select Properties
- Click Extended Properties on the left
- On the right locate the row for TFS_BACKUP_PLAN_CONTROLLER
- Change the value to the new server name e.g. localhost
- Locate the row for TFS_INSTANCE
- Make a note of the GUID value
- Repoint TFS web services to the new instance
- Navigate to folder C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Services
- Open web.config in a plain text editor
- Locate the applicationId key
- Change the value to the TFS_INSTANCE value noted in the step above
- Open a command prompt and issue:
cd C:\Program Files\Microsoft Team Foundation Server 2010\Tools TFSServiceControl.exe unquiesce TFSConfig remapdbs /databaseName:localhost;Tfs_Configuration /sqlInstances:localhost /continue TFSConfig identities /change /fromdomain:{SourceDomain} /todomain:{TargetDomain} /account:{SourceAdminAccount} /toaccount:{TargetAdminAccount}The last command (TFSConfig identities) is intended to repoint an account with TFS administrative privileges on the source instance with an account that is accessible on the target machine (your own account is the obvious choice). Repeat it for any additional accounts which you want to use against the cloned instance. If the target machine is not in a domain, set {TargetDomain} to the machine name.
- Start the TFS Admin Console
- Click Application Tier on the left
- Add a user account accessible on the target machine to Administration Console Users (e.g. your own account)
- Click Change URLs on the right
- Change the notification URL to http://localhost:8080/tfs, test, then click the OK button
- Click Reapply Account on the right, enter the password, then click OK
- Click Build Configuration on the left
- Reconfigure the build service as needed
- Click Application Tier on the left
- Clear the TFS application tier cache by deleting the contents of C:\Program Files\Microsoft Team Foundation Server 2010\Application Tier\Web Services\_tfs_data
- Clear the Visual Studio TFS cache by deleting the contents of C:\Users\Andy\AppData\Local\Microsoft\Team Foundation\3.0\Cache
- Start Visual Studio and connect to the cloned instance
That should do it!
Troubleshooting
- The clone will have the same instance ID as the original instance, and if you are able to connect to both from the same machine you may notice some strange behaviour due to the cache not being able to differentiate between them. If this is a problem look into TFSConfig changeserverid.
- If the restore reports that it failed to restore Reporting Services encryption key it may be because the Reporting Services database is detached at that point. Use rskeymgmt -a -f [KEYFILE] -p [PASSWORD] or Reporting Services Configuration Manager to restore the key instead (if you want to use Reporting Services).
- If you get a message saying that the service account does not have access to SQL Server, start SQL Server Management Studio and issue the SQL grant connect sql to “domain\account”
- If you get a message Failed to add ‘AccountName’ account to the TFSEXECROLE role on the Tfs_Warehouse relational database follow the instructions at http://support.microsoft.com/kb/2025896
- If you get TF30040: The database is not correctly configured when connecting from Visual Studio it may indicate that the service account does not have permission to access the database(s). Give the account permission or change the service account.
- If you get TF14061 Workspace does not exist it might indicate that the user account which owns the workspace has been remapped. Use tf workspace /newowner or the workspaces GUI to remap the workspace.


