我安装了Microsoft Team Foundation Server Express 2012。
表tbl_TestResult正在耗尽7000 MB的数据库空间。
我试图找到有关如何清理此表的信息,但没有办法这样做。
当我想将新文件签入TFS时,我得到错误TF30042:数据库已满...
在Visual Studio上我删除了所有可见的测试,但tbl_TestResult的大小只是减少了很少。
谁能向我解释如何以正确的方式清理所有测试结果?
我正在使用TFS客户端API删除旧的测试运行。这是一些示例代码:
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri("http://tfs2012:8080/tfs/DefaultCollection/"));
TestManagementService testManagementService = tpc.GetService<TestManagementService>();
ITestManagementTeamProject teamProject = testManagementService.GetTeamProject("MyProject");
int totalRuns = teamProject.TestRuns.Count("SELECT * FROM TestRun");
// Limit by date, so the query doesn't take too long.
string query = "SELECT * FROM TestRun WHERE CreationDate < '2013/07/01'";
int numTotalToDelete = teamProject.TestRuns.Count(query);
if (numTotalToDelete == 0) { return; }
// Only delete 500 at a time, to give SQL Server time to breathe (don't ask).
var runsToDelete = teamProject.TestRuns.Query(query, false)
.Take(500);
teamProject.TestRuns.Delete(runsToDelete);
查询语法来自:http://blogs.msdn.com/b/duat_le/archive/2010/02/25/wiql-for-test.aspx
对于我们的前期TFS,我们遇到了同样的问题。这就是我们为TFS 2015做到2017年TFS的方式。
c:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools
<INSTALL_DIR>\TestAttachmentCleaner_samples_settingsfile
的安装文件夹中all-100mb.xml
文件:<DeletionCriteria>
<TestRun>
<Created Before="2016-01-01" />
</TestRun>
<Attachment>
<Extensions>
<Include value="wmv" />
<Include value="xesc" />
<Include value="trmx" />
</Extensions>
<!-- size in MB -->
<SizeInMB GreaterThan="100" />
</Attachment>
<LinkedBugs>
<Exclude state="Active" />
</LinkedBugs>
</DeletionCriteria>
tcmpt.exe AttachmentCleanup /settingsfile:"all-100mb.xml" /mode:preview /collection:"https://tfs.contoso.com/DefaultCollection" /teamproject:"TeamProjectName" /outputfile:all-100mb.log"
------------ Summary ------------
Number of attachments affected: 339
Total size of attachments: 39646,7 MB
Elapsed time was 247,94 seconds
tcmpt.exe
参数的情况下运行/mode:preview
命令以删除测试附件。
EXEC dbo.prc_DeleteUnusedContent 1
EXEC dbo.prc_DeleteUnusedFiles 1, 0, 1000
存储过程从数据库中删除清空的行。
如果存储过程的持续时间不到1秒,请等待一段时间再重新运行它们。祝它好运。
我现在只是通过Visual Studio支持删除所有Builds,然后我关闭TFS创建了TFS数据库的备份并截断整个表tbl_TestResult并再次启动TFS。
TFS没有抱怨,工作仍然很好。这解决了我的问题。 (虽然不推荐这种方法)