HowTo Copy Files in Use
HowTo Copy Files in Use
Backup/Copy Files that are "In Use" or "Locked" in Windows (Command Line) If youve ever tried to copy a file that is locked by another application, youve probably seen an error message similar to The process cannot access the file because another process has locke d a portion of the file. So how do you copy it anyway?
Since XP, Windows has supported a technology called Volume Shadow Copy, which is used to power the previous versions feature in Vista as well as System Restore and backups. What it does is take a temporary snapshot of the file or drive, and then allow an application to read from the snapshot even while other applications are accessing or modifying the file. What we can do is use a command line utility called HoboCopy that utilizes this service to copy the file. Understanding the Prerequisites HoboCopy and most other backup utilities make use of two services in Windows, and youll need to verify that these services are not disabled: Volume Shadow Copy Microsoft Software Shadow Copy Provider
They can be left as Manual startup, so they dont need to be running all the time. Hobocopy will start the two services automatically when needed, and the Volume Shadow Copy service will be turned back off after its done.
Using HoboCopy to Backup/Copy a Single File The syntax is a little weird, because HoboCopy is really meant to be used for backing up an entire set of folders. We can use it to backup a single file by passing in the filename argument at the end. Note: on Windows Vista you will need to launch an Administrator mode command prompt by right-clicking on the Command prompt in the start menu and choosing Run as Administrator. Syntax: hobocopy c:\directoryname\ d:\backupdirectory\ <filename> For example, I want to backup my c:\users\geek\mail\outlook.pst file to d:\backups\outlook.pst. Heres the syntax that Id use: C:\> hobocopy c:\users\geek\mail\ d:\backups\ Outlook.pst HoboCopy (c) 2006 Wangdera Corporation. [email protected] 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 Using HoboCopy to Backup an Entire Directory A much more useful task would be to backup my entire User folder, probably to an external hard drive for safekeeping. For this, well want to add a couple of command-line arguments. /full /skipdenied /r /y Syntax: hobocopy /full /skipdenied /y /r c:\directoryname\ d:\backupdirectory\ Lets go with the same example, I want to backup my entire user directory to d: \backups\, so Id use this command: hobocopy /full /skipdenied /y /r c:\users\geek\ d:\backups\ This command will likely take a very long time to complete, so you might want to take a nap or something. At the end you should have a nearly perfect copy of the directory if there are any permission err ors youll be alerted to files that didnt copy. Realistically any files in your user directory shouldnt have this problem. Using HoboCopy to Incrementally Backup a Drive Copy all files Ignore any access denied messages because of permission errors. Copy recursively Dont prompt, just copy everything
Hobocopy also supports backing up files incrementally, so it will only copy the files that have changed since the last backup. This works similarly to utilities like rsync, except hobocopy stores the last backup date in a file that you need to specify on the command line. /statefile=filename /incremental 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 first time that you run this command you will need to use /full instead of /incremental, or else you will get an error because the state file hasnt been created yet. After that you can run the incremental backup with the /incremental switch. This would be an excellent way to automatically backup a set of folders as part of a scheduled task. Download HoboCopy from sourceforge.net This article was originally written on 03/9/08 Tagged with: Managing Files and Folders, Vista, Windows 7, Windows 7 Tips This flag specifies the file that contains the last backup information. Only copy files that have changed since the last full copy.
C:\Users\yenc\HoboCopy>hobocopy HoboCopy (c) 2006 Wangdera Corporation. [email protected] Usage: hobocopy [/statefile=FILE] [/verbosity=LEVEL] [ /full | /incremental ] [ /clear ] [ /skipdenied ] [ /y ] [ /simulate ] [/recursive] <src> <dest> [<file> [<file> [ ... ] ] Recursively copies a directory tree from <src> to <dest>. /statefile - Specifies a file where information about the copy will be written. This argument is required when /incremental is specified, as the date and time of the last copy is read from this file to determine which files should be copied. - Specifies how much information HoboCopy will emit during copy. Legal values are: 0 - almost no information will be emitted. 1 - Only error information will be emitted. 2 - Errors and warnings will be emitted. 3 - Errors, warnings, and some status information will be emitted. 4 - Lots of diagnostic information will be emitted. The default level is 2. - Perform a full copy. All files will be copied regardless of modification date.
/verbosity
/full
/incremental - Perform an incremental copy. Only files that have changed since the last full copy will be copied. Specifying this switch requires the /statefile switch to be specified, as that's where the date of the last full copy is read from. /clear - Recursively delete the destination directory before copying. HoboCopy will ask for confirmation before deleting unless the /y switch is also specified. - By default, if HoboCopy does not have sufficient privilege to copy a file, the copy will fail with an error. When the /skipdenied switch is specified, permission errors trying to copy a source file result in the file being skipped and the copy continuing. - Instructs HoboCopy to proceed as if user answered yes to any confirmation prompts. Use with caution - in combination with the /clear switch, this switch will cause the destination directory to be deleted without confirmation. - Simulates copy only - no snapshot is taken and no copy is performed. - Copies subdirectories (including empty ones). Shortcut: /r
/skipdenied
/y
/simulate
/recursive
- The directory to copy (the source directory). - The directory to copy to (the destination directory). - A file (e.g. foo.txt) or filespec (e.g. *.txt) to copy. Defaults to *.*.
C:\Users\yenc\HoboCopy>hobocopy C:\Users\yenc\AppData\Local\Temp\ c:\ fla2AC2.tmp HoboCopy (c) 2006 Wangdera Corporation. [email protected] Starting a full copy from C:\Users\yenc\AppData\Local\Temp\ to c:\ Creation of directory failed with error Access is denied. (Error number 5) on directory \\?\c:\
C:\Users\yenc\HoboCopy\hobocopy C:\Users\yenc\AppData\Local\Temp\ c:\bkup flaB034.tmp HoboCopy (c) 2006 Wangdera Corporation. [email protected] Starting a full copy from C:\Users\yenc\AppData\Local\Temp\ to c:\bkup Copied directory Backup successfully completed. Backup started at 2010-09-09 17:47:26, completed at 2010-09-09 17:47:54. 1 files (30.45 MB, 1 directories) copied, 2235 files skipped C:\Users\yenc\HoboCopy>