Search code examples
source-control-explorer

My Main branch in TFS just disappeared - why?


Our Main branch was apparently just deleted and there's no record of why. (The branch still appears in Source Control Explorer - When I view the history of the branch it's empty). When I get latest on the branch it deletes everything locally. We have numerous children branches that all appear to be fine, but Main is now empty with no record of how/why. Anybody have any idea how we can figure out what happened and recover it? We have a child branch that should be a duplicate so we should be OK, but we'd really like to figure out what happened!


Solution

  • What may have happened

    There are a few things I can think of, the most logical in this case is that someone issued a tf destroy $/project/Branch/* /recursive, that would have the observed effect.

    It could also be that someone has renamed the branch, that would not be visible in the history per se, unless you turn on the "Show Deleted Items" option in the options of the Team Foundation Source control options.

    Your Application Tier's version control cache may have become corrupted, the chance of this happening is very slim, but it may have caused this. Ensure you have a good backup of your databases even if this may seem the case, if it isn't you're going to need the database backup and the older it is, the more unlikely it is data marked for deletion will still be there.

    How can you find out what happened?

    Check the tbl_command in the Project Collection Database or access the hidden _oi activity log page on the web access server. You may be able to find the command that caused the deletion.

    If that doesn't tell you, analyze the transaction logs of the SQL Server (if your server is configured to keep these).

    What to do now?!

    Make a backup of your TFS server or secure the ones you have if you haven't done so

    If the version control cache is the culprit clearing it (on Application Tier machines) may solve your problem, the cache location shows on the TFS Admin Control panel:

    enter image description here

    Best way to go about this, is to stop the TFS server temporarily and then delete the contents of this folder.

    There seem to be a few ways out:

    • Forget about it, take the contents of the most up-to-date branch and use that to repopulate the missing data. Just add them to the empty folder, check them in and then re-merge all other branches and resolve all conflicts.

      • Pro: Fast
      • Con: you loose history, resolving conflicts will be a horrible task.
    • Restore the project collection database to a previous point in time (warning! may require restore of all project collections to a previous point in time)

      • Pro: You get all your history back
      • Con: You loose changes made since the last known good backup, takes alot of work, will impact all projects in the same collection, possibly all projects on the same server.
    • Restore the whole server to temporary server and restore the collection with the missing data to the last known good configuration. Use a tool like OpsHub or Team Foundation Migration Toolkit to replay the changes since the disaster.

      • Pro: You get back to the most up to date point in time
      • Con: Takes a lot of time and expertise in TFS Migration
    • Restore the collection database and use the transaction logs to replay as much of the changes to the collection , then skip the transactions that perform the destroy. Be careful though, usually the destroy action marks files as deleted, but a job does the actual deletion in the background.

      • Pro: You get back to the most up to date point in time
      • Con: Takes a lot of time and expertise in SQL
    • Contact Microsoft Support and get a Field expert in the house. They may be able to restore the deletion if it was done without immediately triggering the cleanup job.

      • Pro: You will get back into the best state possible
      • Con: it will be costly

    Whatever you do, make sure you have a backup of your current situation, that allows you to try different tactics, should your first attempts fail.

    Consider splitting the project collection to allow other projects to continue working. You will end up in a situation were this one project ends up in an isolated Project Collection on its own, but it will allow you to move forward quickly.