Team Foundation Server only performs soft deletes and the files are very easy to recover just by performing an undelete. After a while the deleted files may use a lot of unneccesary space. From TFS 2008 it is possible to erase the data from the database. On option would be to use tf.exe and the destroy command. That however will be pretty tedious when there is more than one file that should be destroyed. I have created a small application to help with this task.
The TFS communication is handled in a separate class which i very simple without any error handling.
Usage of this class is very simple and this is just sample.
This class only handles already deleted files. It is possible to destroy non-deleted files as well, but I do not really see the point in that. Keep in mind that the data will be permanently removed and cannot be restored, so be careful! Always back up the TfsVersionControl database before using the destroy methods.
The TFS communication is handled in a separate class which i very simple without any error handling.
using System; using System.Net; using System.Windows.Forms; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.VersionControl.Client; using Microsoft.TeamFoundation.VersionControl.Common; namespace TFSCleanupTool { internal class TFS { private string ServerName = null; private VersionControlServer VersionControl = null; internal TFS(string servername) { ServerName = servername; } internal void Connect(string domain, string username, string password) { TeamFoundationServer server = new TeamFoundationServer(ServerName, new NetworkCredential(username, password, domain)); server.Authenticate(); VersionControl = (VersionControlServer)server.GetService(typeof(VersionControlServer)); } internal Item[] GetDeletedItems(string path) { ItemSet itemSet = VersionControl.GetItems(path, VersionSpec.Latest, RecursionType.Full, DeletedState.Deleted, ItemType.Any); return itemSet.Items; } internal void DestroyDeletedItem(Item item) { ItemSpec itemSpec = new ItemSpec(item.ServerItem, RecursionType.Full, item.DeletionId); VersionControl.Destroy(itemSpec, VersionSpec.Latest, null, DestroyFlags.None); } } }
Usage of this class is very simple and this is just sample.
TFS tfs = new TFS("server"); tfs.Connect("domain", "username", "password"); Item[] items = tfs.GetDeletedItems("$/"); foreach(Item item in items) { tfs.DestroyDeletedItem(item); }
This class only handles already deleted files. It is possible to destroy non-deleted files as well, but I do not really see the point in that. Keep in mind that the data will be permanently removed and cannot be restored, so be careful! Always back up the TfsVersionControl database before using the destroy methods.
Comments
Post a Comment