LOGO

Shadow Copies: Copying Locked Files - A Comprehensive Guide

September 26, 2016
Shadow Copies: Copying Locked Files - A Comprehensive Guide

Addressing Locked Files During Windows Backups

A frequent challenge encountered when attempting to create basic file copy backups in Windows involves encountering files that are locked. This can disrupt the backup process.

Files may be locked either because they are actively in use by a user or due to system-level restrictions imposed by the operating system itself.

Complete inactivity of a file is often a prerequisite for successful copying.

Leveraging Shadow Copies for Backup Solutions

Fortunately, a straightforward solution exists to overcome this obstacle: utilizing Shadow Copies.

Our tool provides convenient access to these shadow copies, enabling retrieval of earlier versions of files that are currently inaccessible due to being locked.

These point-in-time copies are automatically generated by the Windows Restore feature.

Accessing shadow copies allows backups to proceed even when files are in use.

Source Attribution

Image credit: Best Backup Services

Understanding Shadow Copies

Introduced initially with Windows Server 2003, the concept of shadow copies provides a method for tracking file revisions. The operating system regularly scans the system, identifying alterations made to files since the previous scan.

These detected changes are then recorded and layered, effectively building a historical record of each file or folder. This functionality was subsequently integrated into Windows Vista as part of the System Restore feature, where it continues to operate today. It serves as the core technology behind Windows’ “Previous Versions” capability.

How Shadow Copies Function

The creation of shadow copies occurs as a background system-level process, specifically during Restore Point creation. This process circumvents the restrictions typically associated with user-initiated file operations.

Consequently, the system can capture modifications to files that are currently locked by a user or application. This is a key benefit of the technology.

Accessing a locked file becomes straightforward; simply retrieving the most recent shadow copy provides access to its previous state.

Applications Beyond System Restore

The underlying principle is also utilized by Windows Backup and numerous commercial backup solutions. These products can access files, such as Outlook PST files, even while the associated application—Outlook—remains active.

Important Considerations

It’s crucial to understand that the content of a shadow copy may differ from the live file, as copies are generated during system restore point creation.

Windows typically creates a restore point on a daily basis, which generally provides an acceptable level of data preservation for most backup scenarios.

Retrieving Files from Shadow Copies

The following instructions presume the utilization of the tool linked at the article’s conclusion. Ensure the provided batch script resides within a directory included in your system’s Windows PATH environment variable. If you are uncertain, placing it directly into the C:\Windows folder will generally suffice.

Accessing the data preserved in shadow copies necessitates the VSSAdmin command-line utility, a component already integrated with Windows. Proper functionality requires running this tool with administrator privileges; therefore, initiate the command prompt with a right-click and selection of the 'Run as Administrator' option.

htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files-1.jpg

Our tool streamlines the process. To display the tool’s syntax and header details, simply input the following command:

MountLatestShadowCopy /?

htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files-2.jpg

For instance, the command:

MountLatestShadowCopy C:\LatestShadow\ C:

will execute these steps:

  1. The most recent shadow copy for the C: drive will be identified.
  2. A symbolic link, or pseudo-directory, named "C:\LatestShadow" will be created.
  3. The complete contents of the shadow copy will become accessible through this directory.

Upon completion, you can navigate the files either via the command line:

htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files-3.jpg

or through the familiar interface of Windows Explorer, functioning identically to any other folder.

htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files-4.jpg

When finished, the pseudo-directory can be removed using the command prompt:

RMDIR C:\LatestShadow

Alternatively, deletion can be performed directly within Windows Explorer. This action merely unmounts the folder and does not affect the underlying shadow copy itself.

htg-explains-what-are-shadow-copies-and-how-can-i-use-them-to-copy-or-backup-locked-files-5.jpg

Leveraging Shadow Copies in Scripts and Automation

While manual access to shadow copies is readily available through Windows' earlier iterations, their true power is unlocked when integrated into automated tasks and scripting environments.

Consider the following example script. It mounts the most recent shadow copy to the "C:\MyShadow" directory. Subsequently, it copies the "outlook.pst" file, found within user JDoe’s Documents folder, to a designated backup server.

CALL MountLatestShadowCopy C:\MyShadow\

XCOPY "C:\MyShadow\Users\JDoe\Documents\Outlook\outlook.pst" "\\BackupServer\MyFiles\"

RMDIR C:\MyShadow

Attempting to copy the live file while it’s actively in use by a user would typically result in a failure. However, accessing the file through a shadow copy bypasses these locks, ensuring a virtually guaranteed successful copy operation. This methodology mirrors the functionality employed by many commercial backup solutions.

A crucial detail to remember is that executing the script, or any script utilizing the MountLatestShadowCopy.bat tool (which relies on the VSSAdmin tool), requires administrative privileges.

To facilitate this within a scheduled task, the task settings must be configured to 'Run with highest privileges'. This ensures the automated process possesses the necessary permissions to mount shadow copies using VSSAdmin.

In essence, initiating file copy backups from shadow copies is generally the most reliable approach. Although it may not always yield the absolute latest file version, the assurance of an unlocked file and a successful copy process offers significant benefits in numerous scenarios.

The MountLatestShadowCopy tool can be downloaded from HowToGeek.com.

Benefits of using Shadow Copies for Backups:

  • Reliable Copies: Avoids file locking issues during backups.
  • Automated Processes: Integrates seamlessly into scripts and scheduled tasks.
  • Mimics Backup Software: Employs the same techniques as professional backup products.
  • Administrative Privileges: Requires elevated permissions for execution.

Key Tools:

  • MountLatestShadowCopy.bat: A tool for mounting the latest shadow copy.
  • VSSAdmin: The underlying command-line tool used by MountLatestShadowCopy.bat.

Important Note: Always ensure scheduled tasks are configured to run with the highest privileges to enable shadow copy mounting.

#shadow copies#locked files#file copying#Windows#VSS#Volume Shadow Copy Service