LOGO

Copy Locked Files Windows - Command Line

March 9, 2008
Copy Locked Files Windows - Command Line

Overcoming File Lock Errors with HoboCopy

Encountering an error message stating a file is locked by another process during a copy attempt is a common frustration. This typically occurs when an application is actively using the file. Fortunately, Windows provides a solution through a technology known as Volume Shadow Copy, which underpins features like System Restore and the Previous Versions functionality.

Volume Shadow Copy functions by creating a temporary snapshot of the file or drive. This allows applications to access and read from this snapshot, even while other programs continue to access or modify the original file. A command-line utility called HoboCopy leverages this service to facilitate file copying in such scenarios.

Prerequisites for Using HoboCopy

HoboCopy, like many backup utilities, relies on two essential Windows services. It’s crucial to ensure these services are not disabled for HoboCopy to function correctly.

  • These services can be configured to start manually, meaning they don't need to be running continuously.
  • HoboCopy will automatically initiate these services when required.
  • The Volume Shadow Copy service will revert to an off state once the copy operation is complete.

Backing Up or Copying a Single File

While designed for comprehensive folder backups, HoboCopy can also be used to copy individual files. This is achieved by specifying the filename as the final argument in the command.

Note: On Windows Vista, launching the Command Prompt in Administrator mode is necessary. This can be done by right-clicking the Command Prompt icon in the Start Menu and selecting "Run as Administrator."

Syntax:

hobocopy c:\directoryname\ d:\backupdirectory\ <filename>

For instance, to back up the file c:\users\geek\mail\outlook.pst to d:\backups\outlook.pst, the following command would be used:

C:\> hobocopy c:\users\geek\mail\ d:\backups\ Outlook.pst

HoboCopy (c) 2006 Wangdera Corporation. hobocopy@wangdera.com Starting a full copy from c:\users\geek\mail to d:\backups\
Copied directory
Backup successfully completed.
Backup started at 2008-03-09 01:57:28, completed at 2008-03-09 01:58:39.
1 files (606.45 MB, 1 directories) copied, 7 files skipped

Backing Up an Entire Directory

A more practical application of HoboCopy is backing up an entire directory, such as a user folder, to an external storage device. This requires incorporating several command-line arguments.

/full Copy all files.
/skipdenied Ignore access denied errors due to permission issues.
/r Copy recursively.
/y Do not prompt for confirmation; copy all files automatically.

Syntax:

hobocopy /full /skipdenied /y /r c:\directoryname\ d:\backupdirectory\

To back up the entire user directory to d:\backups\, the command would be:

hobocopy /full /skipdenied /y /r c:\users\geek\ d:\backups\

This process can be time-consuming. Upon completion, a near-identical copy of the directory will be created, with any permission-related errors reported.

Incrementally Backing Up a Drive

HoboCopy also supports incremental backups, copying only files that have been modified since the last backup. This functionality is similar to tools like rsync, but HoboCopy stores the last backup date in a state file that must be specified in the command.

/statefile=filename Specifies the file containing the last backup information.
/incremental Only copy files changed since the last full copy.

Syntax:

hobocopy /incremental /statefile=filename /y /r c:\directoryname\ d:\backupdirectory\

Example:

hobocopy /incremental /statefile=d:\lastbackup.dat /y /r c:\users\geek\ d:\backups\

The initial execution of this command requires the use of /full instead of /incremental, as the state file will not yet exist. Subsequent backups can then utilize the /incremental switch. This method is ideal for automating backups as part of a scheduled task.

HoboCopy can be downloaded from sourceforge.net.

#copy locked files#windows command line#backup in use files#file in use#locked file#command prompt