I had a few TFS 2017 build definitions created at one point, and through some messing around with the install and databases, I have lost access to those definitions. They don't show up anywhere in the web portal. I also can't restore and attach the project collection that was associated with them, though I do have an actual SQL backup of the project collection database.
So, is there a way to query either the Tfs_Configuration, Tfs_Warehouse, or the Tfs_projectcollection databases to retrieve build definition information?
If not, I will end up recreating them, but just curious if there was some other way.
Recommend you to recreate them if the definitions are simple ones, that will not spend much time.
But if they are complicated ones, you can restore the backup database in another sql instance, query out the missing build definitions, then insert the definitions to current table [Tfs_DefaultCollection].[Build].[tbl_Definition]. (Make sure backup the databases before doing this in case meet any problems.)
Just select a row and copy (right click > copy in sql server) from the queried definitions, you need to do additional actions to add the ' ', for each value.
Then insert into the values something like this:
insert into [Tfs_DefaultCollection].[Build].[tbl_Definition]
values
('1', '85', '17', '1', 'D4', '1', '7', '0', '5', '8', '1', '', '$(date:yyyyMMdd)$(rev:.r)', '1', '60', '', '1F739003-44A9-4AB6-B1A2-D3CD2A291588', '2017-04-21 19:53:49.733', '', '[{"enabled":false,"definition":{"id":"7c555368-ca64-4199-add6-9ebaf0b0137d"},"inputs":{"multipliers":"[]","parallel":"false","continueOnError":"true","additionalFields":"{}"}},{"enabled":false,"definition":{"id":"a9db38f9-9fdc-478c-b0f9-464221e58316"},"inputs":{"workItemType":"106","assignToRequestor":"true","additionalFields":"{}"}},{"enabled":false,"definition":{"id":"57578776-4c22-4526-aeb0-86b6da17ee9c"},"inputs":{"additionalFields":"{}"}}]', '{"properties":{"labelSources":"0","tfvcMapping":"{\"mappings\":[{\"serverPath\":\"$/6553c041-5e50-4ace-bec2-c1dba2b812ca\",\"mappingType\":\"map\",\"localPath\":\"\\\\\"},{\"serverPath\":\"$/6553c041-5e50-4ace-bec2-c1dba2b812ca/Drops\",\"mappingType\":\"cloak\",\"localPath\":\"\\\\\"}]}","cleanOptions":"0"},"id":"$/","type":"TfsVersionControl","name":"6553c041-5e50-4ace-bec2-c1dba2b812ca","url":"http://win-kev0061habi:8080/tfs/DefaultCollection/","defaultBranch":"$/6553c041-5e50-4ace-bec2-c1dba2b812ca","rootFolder":"$/6553c041-5e50-4ace-bec2-c1dba2b812ca","clean":"false","checkoutSubmodules":false}', '', '[{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"NuGet restore **\\*.sln","timeoutInMinutes":0,"task":{"id":"333b11bd-d341-40d9-afcf-b32d5ce6f23b","versionSpec":"0.*","definitionType":"task"},"inputs":{"solution":"**\\*.sln","nugetConfigPath":"","restoreMode":"restore","noCache":"false","nuGetRestoreArgs":"","verbosity":"-","nuGetVersion":"3.3.0","nuGetPath":""}},{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Build solution **\\*.sln","timeoutInMinutes":0,"task":{"id":"71a9a2d3-a98a-4caa-96ab-affca411ecda","versionSpec":"1.*","definitionType":"task"},"inputs":{"solution":"**\\*.sln","msbuildArgs":"","platform":"$(BuildPlatform)","configuration":"$(BuildConfiguration)","clean":"false","vsVersion":"15.0","maximumCpuCount":"false","restoreNugetPackages":"false","msbuildArchitecture":"x86","logProjectEvents":"true","createLogFile":"false"}},{"enabled":true,"continueOnError":false,"alwaysRun":false,"displayName":"Test Assemblies **\\$(BuildConfiguration)\\*test*.dll;-:**\\obj\\**","timeoutInMinutes":0,"task":{"id":"ef087383-ee5e-42c7-9a53-ab56c98420f9","versionSpec":"1.*","definitionType":"task"},"inputs":{"testAssembly":"**\\$(BuildConfiguration)\\*test*.dll;-:**\\obj\\**","testFiltercriteria":"","runSettingsFile":"","overrideTestrunParameters":"","codeCoverageEnabled":"false","runInParallel":"false","vstestLocationMethod":"version","vsTestVersion":"14.0","vstestLocation":"","pathtoCustomTestAdapters":"","otherConsoleOptions":"","testRunTitle":"","platform":"$(BuildPlatform)","configuration":"$(BuildConfiguration)","publishRunAttachments":"true"}},{"enabled":true,"continueOnError":true,"alwaysRun":false,"displayName":"Publish symbols path: ","timeoutInMinutes":0,"task":{"id":"0675668a-7bba-4ccb-901d-5ad6554ca653","versionSpec":"1.*","definitionType":"task"},"inputs":{"SymbolsPath":"","SearchPattern":"**\\bin\\**\\*.pdb","SymbolsFolder":"","SkipIndexing":"false","TreatNotIndexedAsWarning":"false","SymbolsMaximumWaitTime":"","SymbolsProduct":"","SymbolsVersion":"","SymbolsArtifactName":"Symbols_$(BuildConfiguration)"}},{"enabled":true,"continueOnError":false,"alwaysRun":true,"displayName":"Copy Files to: $(build.artifactstagingdirectory)","timeoutInMinutes":0,"task":{"id":"5bfb729a-a7c8-4a78-a7c3-8d717bb7c13c","versionSpec":"2.*","definitionType":"task"},"inputs":{"SourceFolder":"$(build.sourcesdirectory)","Contents":"**\\bin\\$(BuildConfiguration)\\**","TargetFolder":"$(build.artifactstagingdirectory)","CleanTargetFolder":"false","OverWrite":"false","flattenFolders":"false"}},{"enabled":true,"continueOnError":false,"alwaysRun":true,"displayName":"Publish Artifact: drop","timeoutInMinutes":0,"task":{"id":"2ff763a7-ce83-4e1f-bc89-0ae63477cebe","versionSpec":"1.*","definitionType":"task"},"inputs":{"PathtoPublish":"$(build.artifactstagingdirectory)","ArtifactName":"drop","ArtifactType":"Container","TargetPath":"\\\\my\\share\\$(Build.DefinitionName)\\$(Build.BuildNumber)"}}]', '{"system.debug":{"value":"false","allowOverride":true},"BuildConfiguration":{"value":"release","allowOverride":true},"BuildPlatform":{"value":"any cpu","allowOverride":true}}', '', '[{"branches":["+refs/heads/*"],"artifacts":[],"artifactTypesToDelete":["FilePath","SymbolStore"],"daysToKeep":10,"minimumToKeep":1,"deleteBuildRecord":true,"deleteTestResults":true}]', '0', '0', '1', '')
If you have lots of definitions need to be done, you can also try to merge database, please refer to below link for details: http://byalexblog.net/merge-sql-databases