Automating your SQL Server backups (and C# code to calculate your disk space requirements)

Posted: (EET/GMT+2)

 

Any production application using a database for storage and application control should have a database backup strategy. Most often, this strategy includes decisions on how often backups are being taken, and long they are kept.

On a practical level, backing up your SQL Server database(s) should be fully automated, leaving no need for manually-done backups or missing the schedule because of vacations, etc. But, simply automating your backups with for instance SQLCMD isn't enough, if you don't implement an equally-automated process to clean up your backups. That is, if you simply accumulate your (daily) backups on the server's disk, you will soon consume a plenty of disk space. Especially in virtual environments, you usually don't have a lot of disk space, but of course, your mileage may vary.

In any case, since it's actually pretty tough to calculate the amount of disk space you need (or, how long your allotted disk space will last) in your head, I wrote a simple C# console application that you can use to help with your estimates.

screenshot

This application asks a few input parameters, and then shows how many days your disk space will last. The main factor is the daily increase of the database size. If you input zero as the daily rate, the application will simply calculate how much disk space you need.

The application executable can be downloaded here, and here's the source code. To run the application, you will need to have .NET Framework 4.0 or 4.5 installed. When entering input values, use whole numbers (integers) only.