Backup on Build: Source Code Assurance
On VB author Joe Kunk looks into how an automated source code backup utility can provide a vital, extra level of protection in team-based projects.
Living on a lake in Michigan, I saw that most parents consistently required their children to take life jackets with them whenever they went out any kind of boat or watercraft. Many of those children were excellent swimmers; I knew that because I often swam with them. The parents required the life jackets because they wanted that extra assurance that if the unexpected happened, their children would be protected. Some recent events at my workplace made me feel that we really needed source code "life jackets", that is, extra protection for our source code in the event of unexpected mishaps.
Like most software development teams, we actively use source code management (SCM) software in order to share source code and provide a unified repository with regular backups. Our particular SCM software allows multiple developers to concurrently modify a source file, and the changes are merged when committing to or updating from the repository.
As the size of the developer team grew on a significant project, I starting receiving sporadic reports from developers that changes they were certain they had completed were no longer present in the current or prior versions within the source code repository. For a large development project on a tight timeline, this was a major problem. It didn't really matter if there was a problem with the SCM software or if it was just not being used properly, or even if the problem was imagined, we needed to be sure that none of our completed source code would be lost.
The project manager's solution was to instruct the developers to fully backup their entire source code folder before using the repository. I mean no disrespect to project managers or to developers, but honestly my thought on that recommendation was something akin to "Right, they will manually backup the entire application source code folder every time before they access the repository, sure they will...."
It was obvious that to truly ensure that no source code would be lost, we needed a custom utility that would meet the following requirements:
- Source code should be backed up frequently without any developer interaction.
- Source code backup of the most critical source files should be fast enough to be transparent.
- Source code backup of the entire source folder should occur on a regular but less frequent basis.
- Source code backup should optionally be compressed to minimize disk space usage.
- Source code backup behavior should vary by project to accommodate the criticality of the particular project.
- It should be easy to verify that all critical files are included in the most frequent backups.
- A log of each step of the backup should optionally be available to validate proper operation of the utility.
- There should be an automated unit test project to validate the backup utility's functionality.
The best way to provide a frequent and transparent backup is to add a post-build command for each project that runs the new backup utility only on a successful build. The backup becomes a "set it and forget it" feature of the project that ensures the source code backup is available when and if you need to recover any possible lost source code. This utility does not replace the need for source code management software; it simply provides an extra layer of protection, i.e., Source Code Assurance.
Tomorrow in Part 2 of this article, I will present the source code that implements all of the above requirements using Visual Basic 2010 and the .NET 4.0 framework. Note that although it is written in Visual Basic 2010, the backup utility can be used to back up any .NET project written in any language in any version of Visual Studio that supports custom post-build commands.
You can download the source code from the CodePlex site.
Joe Kunk is a Microsoft MVP in Visual Basic, three-time president of the Greater Lansing User Group for .NET, and developer for Dart Container Corporation of Mason, Michigan. He's been developing software for over 30 years and has worked in the education, government, financial and manufacturing industries. Kunk's co-authored the book "Professional DevExpress ASP.NET Controls" (Wrox Programmer to Programmer, 2009). He can be reached via email at [email protected].