Code Focused

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.

About the Author

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].

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube