Windows Server 2008 backup with on-board tools and 7z

A server-based data backup stores copies of important data, runs automatically, manages multiple file versions and ensures the integrity of the stored data. Microsoft Windows Server 2008 and Windows Server 2008 R2 already have a large number of these features on board. The missing parts are provided by the open source compression software 7z.

The key to a robust server backup is a copy of files in a consistent state. Since Windows Server 2003 and Windows Vista, Microsoft has built in the Volume Shadow Copy Service (VSS). This service creates a copy of files on a drive in spite of open files in a consistent state. As a result open files can be copied without stopping any service. This is achieved by providers for Microsoft SQL Server and Exchange which make sure that database files in shadow copies are consistent on database, Exchange and Small Business Servers.

Windows Server 2008 backup with on-board tools and 7z

Windows Server 2008 and 2008 R2 deliver a command-line tool called Diskshadow that can be used to manage shadow copies. Thanks to the commitment of Igor Pavlov7z is a free data compression program with a 30-70% better compression rate compared to Zip archives. Using these tools and some batch files you can build an automated backup solution for Windows servers.

The method requires the installation of 7z and Windows Server 2008 or later. In the example presented here, a daily backup is demonstrated. All batch files can be downloaded from the downloads section.

In the following the different parts of the batch scripts are explained in more detail. Essentially the backup consists of a backup batch file, the scripts for then DISKSHADOW command and a 7z batch file:

The backup batch file „Daily.cmd“

The batch file Daily.cmd is the starting point for data backup and can, for example, executed by the task scheduler of windows. At the beginning of the batch all variables for the backup are defined:

::Backup Parameter
set Folder=Daily
set ShadowVolume=D:
set ShadowAlias=Q:
set ShadowCommand=Daily7z.cmd

Variable

Description

%Folder%

Directory where the archives of the backup will be stored. In the example a relative path is used but an absolute path works as well.

%ShadowVolume%

Drive on which the data to be backuped is stored. Currently only one drive is used, since on a server all data resides on a single drive normally.

%ShadowAlias%

Drive letter under which the shadow copy is made available. This has to be an unused drive letter in the server.

%ShadowCommand%

This is the batch file that does the actual compressing of the data with 7z.

In the next step a simple log file is created in which the starting time and ending time of the backup is written:

Here the DISKSHADOW command is executed with two script files using the „/s“ parameter. The script files are simple text files having the extension „.dsh“ for identification. The first script „ShadowRemove.dsh“ removes a potentially remaining shadow copy. This can occur from an aborted backup and should be removed before the next backup. This method is necesary for a more robust and fault tolerant backup.

At this time, the archive and log file have the name „Backup.*“. Thus, it makes sense to make an additional copy of the backup to another medium at this point. This optional copy is used to recover data after a simultaneous total failure of server and backup system (disaster recovery). In any case, this second backup copy should be stored separately from the daily backup at another location. In addition, the most recent backup minimizes the loss of data in the case of a disaster recovery.

In this example, the backup files are copied to a spatially separated NAS System:

Firstly, an existing backup is renamed to „.old.7z.„, then the new backup is copied, and finally the old backup is deleted. This method has the advantage of not losing a backup copy even in the event of an error.

In the next step, the archive files are renamed according to the given name. If the script has been started with no parameters this step is omitted:

The command „begin backup“ starts the backup process, with „add volume“ the volume %ShadowVolume% to shadow is specified and „create“ creates the shadow copy. During this, all providers like SQL Server and Exchange are instructed to write their files in a consistent state to the shadow copy. The ShadowID of the shadow copy is temporarily stored in the variable „DataVolumeShadow“ for later use.

By „expose“ the shadow copy is mounted to the drive letter %ShadowAlias%.

The next step DISKSHADOW script calls another batch file %ShadowCommand% with the „exec“ command. This compresses and copies all files from the shadow copy in a 7z archive.

The remaining commands in the script are for cleaning up by deleting the shadow copy and finishing the backup. A detailed description of the DISKSHADOW tool can be found in Microsoft’s Technet.

Archiving with 7z in „Daily7z.cmd“

In the use command line all directories from the „@Daily.lst“ file are saved in the multi-part archive „Backup.7z“. The size of the archive parts is limited to two gigabyte. Thus, the individual parts of the archive can be easily stored even on FAT drives. The file „Daily.lst“ is a simple text file containing all directories to be saved separated by line breaks:

The batch file can be invoked manually from the command line and takes as a parameter the name of the backup like the weekday at which the backup is executed:

Daily "Monday"

If no parameters are passed, a backup with the file name „Backup.*“ is created.

Automation of the backup with the task scheduler

Windows Server 2008 provides with the task scheduler an efficient mechanism for periodic execution of processes:

Task Scheduler

Action of the Task Scheduler

In this example for each day of the week a task is created with an action that starts the batch file „Daily.cmd“ with the corresponding weekday as parameter at a given time.

You should be aware that depending on the amount of data and processor power, the backup can take a considerable time and utilizes the server cpu strongly. Therefore, the backup should be made during times when the server is not used like during night times.

Discussion

The presented method has been proven for a long time in practice. Nevertheless, there are some points that can be improved: Firstly, incremental backups are difficult to realize with this method. One possibility would be to use Robocopy instead of 7z.

Secondly, the backup method does not check whether the backup files are identical to the original files. This is not a large drawback as the intregrity of the 7z archive ensures a correct backup.