Applies To:
  • Windows XP SP1
  • Vista
  • 2003 Server
  • 2008 Server

Summary:

How can I copy or back up files that are always being written by Citect or other applications? The Windows Explorer and utilities like XCopy, and RoboCopy fail to copy these files. 


Solution:

Professional backup software should be able to do this. However, if you just want to copy some files to another location (e.g. mirroring your Citect installation and projects or data files), this can be done with some command-line utilities. The above versions of Windows have a Volume Shadow service which makes a snapshot of a drive (takes under 10 seconds) and allows the backup program to see the state of all files when the snapshot was taken. Other applications can continue to read and write the files, but any file modifications are written to unused space on the disk so the backup program can still read the original snapshot version.

The following example shows how to use the Microsoft RoboCopy command-line utility to back up a drive. RoboCopy is useful because it retries if there is an error and can be terminated and restarted later to continue the same backup. The Microsoft VShadow utility is used to create a temporary snapshot of the drive, and the DOSDev utility makes that snapshot accessible through a drive letter. Batch files are used to link everything together. All files are included in the attachment below (just unzip to a folder) and the latest builds of the utilities can be downloaded from the following locations:

RoboCopy - http://microsoft.com/download Search for 'Windows Resource Kit Tools'

  • RoboCopy is also installed with the Easy RoboCopy utility from the Citect Toolbox

VShadow - http://microsoft.com/download Search for 'Volume Shadow Copy Service SDK'

DOSDev - http://ltr-data.se

Note: The attached copy of VShadow is only for Windows XP. Other builds can be downloaded from Microsoft.

Running 'Shadow RoboCopy.cmd' starts the backup process. It sets the command window's title, then runs VShadow to create a temporary snapshot. The command-line arguments tell VShadow to create a batch file (vss-setvar.cmd) to define environment variables containing information about the snapshot, and to run another batch file (vss-exec.cmd) to do the backup. As soon as vss-exec.cmd finishes, VShadow terminates and destroys the snapshot. Edit 'Shadow RoboCopy.cmd' and change 'C:' to the source drive. Check VShadow.doc for additional options.

The vss-exec.cmd batch file runs vss-setvar.cmd to get the snapshot information as environment variables. Then, it runs DOSDev to mount that snapshot to an unused drive letter (B:). It runs RoboCopy to back up the B: drive to a network path (X:\Backups\<ComputerName>\). The command-line arguments tell it to back up all subdirectories, create a log file, and exclude files like the Windows swapfile, temporary internet files, the recycle bin, etc. RoboCopy's mirror mode is used to check existing files in the destination path. If their size and time/datestamp match the source files, they're skipped to save time. Otherwise they're deleted or replaced with the newer source files. Edit vss-exec.cmd to back up the desired files or folders. See RoboCopy.doc for additional options.

The 'Shadow RoboCopy.cmd' batch file can be run from the Windows Explorer. To run it from CitectSCADA, see Q4572.

Reference: "Workstation Open File Backup Using Robocopy And Vshadow", Robert Jeffery.

 

Keywords: