SEARCH

How-To Geek

Backup/Copy Files that are "In Use" or "Locked" in Windows (Command Line)

If you’ve ever tried to copy a file that is locked by another application, you’ve probably seen an error message similar to “The process cannot access the file because another process has locked a portion of the file”. So how do you copy it anyway?

image

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 you’ll 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 don’t 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 it’s 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. Here’s the syntax that I’d use:

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

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, we’ll want to add a couple of command-line arguments.

/full Copy all files
/skipdenied Ignore any access denied messages because of permission errors.
/r Copy recursively
/y Don’t prompt, just copy everything

Syntax:

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

Let’s go with the same example, I want to backup my entire user directory to d:\backups\, so I’d 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 errors you’ll be alerted to files that didn’t copy. Realistically any files in your user directory shouldn’t have this problem.

Using HoboCopy to Incrementally Backup a Drive

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 This flag specifies the file that contains the last backup information.
/incremental Only copy files that have 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 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 hasn’t 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

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 03/9/08

Comments (48)

  1. Benman

    Wow. I’ve always wondered how to do that… nice find, great article!

  2. timothy

    This is pretty cool… I guess hobocopy is a play on the name of robocopy.

    Has anybody tried sending the backups to a network share on a samba box?

  3. jim

    You say it works like rsync, but a timestamp to compare if a file has been changed is way different from rsync. rsync only copies the part of a file that has changed since the last time it was copied, not the entire thing if its timestamp is different.

  4. Ross Presser

    Indeed. This sells rsync way short. If you have a 15 gb PST (Outlook Personal Folder file) and you want to back it up every day to a network share, hobocopy is going to copy the whole thing over the wire, possibly taking hours. rsync might get away with a few megabytes.

  5. The Geek

    You guys are absolutely correct… I was just meaning that generally it keeps the directories in sync… I probably could have been more clear.

    And I definitely would not recommend using HoboCopy across a network share… as jim and Ross mention, it’s going to copy the entire file every time, which would take forever.

    I’m putting together an article on using rsync along with shadow copies, to give you the best of both worlds.

  6. jim

    nice, that sounds cool

  7. RonCam

    I just downloaded the file “HoboCopy-1.0.0.0-W2K3-Vista-32bit-Release.zip” and I am confused. The Geek says — and the HoboCopy READ.ME verifies — that this utility needs the MS Volume Shadow Service (VSS), included with Windows XP and above.

    But if I look at the filename I see an abbreviation that must mean “Windows 2000 Professional, SP3.” Presumable the author of the utility knows its requirements, and I hope he’s right since I do run Windows 2000. But, how could it run, if it requires the VSS service?

    Or, was there an earlier version that ran on Windows 2000, and the filename has been left unchanged?

  8. The Geek

    @RonCam

    “w2k3″ or “Win2k3″ are commonly used abbreviations for “Windows Server 2003″, not for Windows 2000. Sorry for the confusion!

  9. your_mum

    The Geek, I am very interested in your forthcoming article in using Rsync with M$ Shadow Copy, if possible please keep me posted, thanks in advance.

    Kind regards, Jim.

    p.s. For what it’s worth, I use SyncToy for general sync and backup but this is not 100% accurate or reliable nor is M$ NTBackup!

  10. Pirateworks

    gone through a bunch of readings then finally i came across this article… Small file but powerful…

    you guys are really “The Geek”

    thanks a lot.

  11. Amit

    try this…

    CopySharp is a GUI tool for copying open/inprocess/lock files. It is inspired by robocopy and vshadow.

    CopySharp V1.0 requires .Net Framework 3.5 and VC++ 2005 Runtime. CopySharp V1.0 requires Microsoft® Windows® Server 2003, Microsoft® Windows® XP.

    For Example:
    1. Try to backup/copy your .pst file(s), while your outlook is open.
    2. Try to backup/copy your .mdf/.ldf (SQL Server) files, while your SQL Server is running.

    Locate it at: http://www.amitchaudhary.com/

  12. SR

    The Hobocopy link doesn’t work. Also, the app doesn’t run on two xp machines despite using the 32-bit program plus the c++ library helper.

  13. The Geek

    The link should be fixed now.

  14. Amit

    then try CopySharp.

  15. Mithil

    This is really nice tool. i like it.
    however after creating full backup using statefile syntax,
    if we add new file anywhere after full backup [in same location of which we have taken full backup]
    and next time if we run /incremental switch along with statefile of last full backup, it skips this newly added file as their is no information of this newly added file in statefile.

    how to overcome this.

  16. MM

    I agree with Mithil. /incremental mode seems to be buggy. I does not copy any newly added files in the folder

  17. Louis

    I haven’t downloaded the program yet, but form what I have read on the original description and on this page it sounds great. But I just wanted to be sure I didn’t make a mistake. This program is supposed to be able to copy streaming video of flash?.

  18. jd2066

    @Louis: This article is about backing up files on your computer not flash streaming. For saving streaming flash videos you can use something like Orbit downloader at http://www.orbitdownloader.com/

  19. Peter

    Can’t get this to work om my machine. Trying to copy my Windows.edb file and it just says that the file is being used by another process.

    Starting a full copy from C:\Users\All Users\Application Data\Microsoft\Search\Data\Applications\Windows to c:\hej
    Copy of file failed with error Det går inte att komma åt filen eftersom den används av en annan process.
    (Error number 32) on file \\?GLOBALROOT\Device\HarddiskVolumeShadowCopy33\Users\All Users\Application Data\Microsoft\Search\Data\Applications\Windows\Windows.edb

  20. Preston

    Nice, this is a real time saver. Appreciate the write up, thanks,

  21. Chris Roller

    I’m trying to backup my windows, Program Files, Doc/Setting/Users directory on another harddrive in prep for a backup state that is setup.

    I was thinking hobocopy can do this. What tool makes this possible, so instead of reinstalled OS, and reinstalling all my programs, I can just take the state of my system files, and copy from BUdrive to c:\ when c:\ and it’s OS gets plugged up and needs reinstall.

    Any ideas on this?

  22. b1gjohn

    hobocopy has a problem when your source path has a space in the address under Vista – make sure you change your temp file location!!!

  23. Ahmed

    hobocopy has also problem copying from windows temporary folder. Here is the output of my cmd prompt;

    C:\>HoboCopy.exe c:\Work\temp\delme\ C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp fla60.tmp
    HoboCopy (c) 2006 Wangdera Corporation. hobocopy@wangdera.com

    Starting a full copy from c:\Work\temp\delme\ to C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp
    Copied directory
    Backup successfully completed.
    Backup started at 2009-10-20 20:41:27, completed at 2009-10-20 20:41:30.
    0 files (0.00 bytes, 1 directories) copied, 0 files skipped

  24. Ozgur H.

    @Ahmed,

    You’ve reversed the order of directories. If you look at the article again, you’ll notice it says:

    hobocopy c:\directoryname\ d:\backupdirectory\

    Where “c:\directoryname\” stands for source directory, and “d:\backupdirectory\” is the target. Assuming the file you’re referring to (“fla60.tmp”) is in %temp%, you need to switch the order.

    @Louis,

    Yes, you can use hobocopy to get to the underlying file of a flash video if it’s a fixed-size/length clip. If you’re after recording a live stream, hobocopy can’t help you there as, I don’t think flash players cache anything locally then. However, when you visit sites like youtube, dailymotion, etc, you usually have a “fla*.tmp” stored in your %TEMP% directory for the video you’re watching. You can use hobocopy to get yourself a copy of the video (as the regular copy won’t work). After the video is fully loaded in your browser, run the following command in command prompt:

    dir /o:-d %temp%\fla*.tmp /p

    learn the file name, and use the corrected syntax of Ahmed’s post to get yourself a copy. The file will be a FLV (“Flash Video”) file. Regular WMP would not play it, and you may need a player like VLC to play it offline locally.

  25. mona

    hi,

    i just tried it and typed like this:

    C:\ hobocopy c:\Users\admin\AppData\Local\Temp\ e:\pics\ fla781.tmp
    it just opened the c drive only.

    nothing happened afterward !!!

  26. Dan

    Hi, it seems to choke on spaces in file names ie program files

    workaround?

  27. Martin

    HoboCopy could not copy locked flash video files. They were locked while I was watching video, and disappeared when I closed the player – so I could not copy them normally.
    HoboCopy just kept saying that it did copying but no results. But Unlocker did the trick without any problems. The only thing about unlocker – it has a terrible UI, I have to start it over every time I need to unlock another file. It really misses refresh button so I can monitor a folder for locks.

  28. Roman

    @Martin: I’ve just successfully copied the locked flash video file.
    If you watch something on Youtube with Internet Explorer, then it saves the locked “fla***.tmp” file in “Low” folder and the unlocked “videoplayback[n]” file in “Low\Content.IE5\***\”. One can easily find the unlocked file by size. However, sometimes the unlocked file isn’t saved in that directory (does anyone know the reason?)
    The syntax to copy *.tmp file is then (as one line), which simultaneously solved Dan’s problem:

    HoboCopy.exe “C:\Users\roman\AppData\Local\Microsoft\Windows\Temporary Internet Files\Low” D:\temp fla769.tmp

    Of course, all copying should be done, while the video is still open in IE.

  29. vaselcub

    “However, sometimes the unlocked file isn’t saved in that directory (does anyone know the reason?)”

    Enlarge your max cache setting. Dont know how in IE

  30. Justin

    I cannot get Hobocopy to work from Windows 7 64 bit (compiled with Visual Studio 2010). I used to have a Win 7 32 bit machine and Hobocopy (compiled with Visual Studio 2008) worked great on it. But now that I am on 64 bit I cannot get it to work. I tried compiling all the configurations… the win 2k3 versions (both debug and release) give me the error “There was a COM failure 0x80042302 – HoboCopy.cpp (172)”… the xp versions (both debug and release) give me a “HoboCopy.exe stopped working” general Windows error with the options to debug, close or check online for a solution. I see that they all start the Volume Shadow Copy service but not the Microsoft Software Shadow Copy Provider service, I tried manually starting that service as well then running again but same error.

    I searched online and that COM failure seems to be an access denied error. But I am running the CMD as administrator so don’t know what else I could do to make it work.

  31. Gino

    This is a great tool. I hope it would work as well in copying the .edb files of exchange. I’ll try it today.

  32. Rockie

    Winows 2008 Server R2 x64 Web Server Edition gives me this error too(on busy file):

    There was a COM failure 0x8004230c – .\HoboCopy.cpp (351)

  33. vpprof

    I think the syntax for copying just one file is somewhat incorrect, at least it doesn’t work on my machine. When the paths for source and destination folder end with a backslash, HoboCopy just creates a folder with the name of the file you are about to copy, in the folder where HoboCopy.exe is. If you delete the backslashes, everything works just fine.

    For example, if I wanted to copy the file ‘fla8D1.tmp’ from “C:\Documents and Settings\vpprof” to “V:\vpprof” and typed the following:

    hobocopy “C:\Documents and Settings\vpprof\” “V:\vpprof\” fla8D1.tmp

    then I would have a folder called ‘fla8D1.tmp’ in the directory “V:\HoboCopy”, where the program is. The correct syntax would be without the backslashes, namely:

    hobocopy “C:\Documents and Settings\vpprof” “V:\vpprof” fla8D1.tmp

    Anyway, it’s a great tool – thanks a lot, mate!

  34. Rey Campos

    Great tool! how incredible it is everytime an “oldie but goodie” comes along. I am glad to know I still remember how to command line instead of GUI… After two+ years it still works!

  35. Samir

    HoboCopy is indeed a great tool. I have used it in the XP environment for a couple of years now to copy tmp (read FLV) files. However, I just recently upgraded my OS to Win 7. And I do not use IE. I use Firefox instead.

    So, would someone please tell me where Mozilla Firefox keeps its Internet Temp Files (Videos from You Tube etc.) in Windows 7 environment, so that I may modify my script and continue to use HoboCopy?

    Thanks in advance, and have a great day!!!

  36. vijer

    UNDER WINDOWS 7

    Hobocopy does a great job of making a directory but that is it. No matter what syntax I use.

  37. vijer

    Persistence is the key in life. Found this on another site.

    Put hobocopy files in C:\windows

    then run an elevated command prompt

    then run hobocopy like this

    hobocopy %LocalAppData%\Temp destinationDir fileName

    Worked perfectly.

  38. someguy

    Hobocopy is a little selective in syntax. You need to use ” before and after directory if your path has spaces in it. “C:\Documents and Settings\user\Temp” instead of C:\Documents and Settings\user\Temp
    And you shouldn’t have final backslash after the filepath. Leave it like “C:\Documents and Settings\user\Temp” instead “C:\Documents and Settings\user\Temp\”
    But I couldn’t use the wildcard option. It says you can use *.txt or something like that in its’ site but it gave error when I tried *.mdf
    Did you find a solution to that?

  39. Craig Andera

    Hi! I’m the author of hobocopy. In addition to this post, I’d encourage anyone with questions to email the (newly created) hobocopy mailing list at hobocopy@googlegroups.com.

  40. Moe Badderman

    First I had to install “ShadowCopy” and “vcredist”, and ran “net start vss”, then “cmd” to get the command-line editor.

    There I entered the directory containing Hobocopy:

    C:> cd C:\Program Files\hobocopy

    … then entered “hobocopy” with the source directory and the target directory in quotes:

    C:\Program Files\hobocopy> hobocopy “C:\Documents and Settings\User\Local Settings\Temp” “C:\Documents and Settings\User\My Documents\duplicate”

    … then enter, and wait for confirmation. It copied everything in “Temp” to “duplicate”.

  41. GEOSoft

    I may have simply missed it but I don’t see any mention that the download file has moved to
    https://github.com/candera/hobocopy/downloads

    The link in this page should be changed to reflect that.

  42. Mohammed Shehata

    Works great here, downloaded the 64bit for my Win7 copy and it works pretty well, but as GEOSoft said the download link moved from their website and also from sourceforg to github.com the link on the previous post.
    Thanks for sharing.

  43. Dempsey

    At first I was pretty excited by this, tool until I found it doesn’t copy attributes and ACL at all. Shame.

  44. Kobena

    Is it possible for the target directory to be on a different computer on the network?

  45. Forest

    Downloaded the files and installed – a command prompt flashed and I do not see an icon anywhere. I open command as admin and I get “hobocopy is not recognized as an internal or external command operable program or batch file”

  46. Forest

    wait – read some more and found Mos’ post – everything good

  47. bhupendra

    I have windows 7 os and i dont have document setting folder in my c: drive so where i have to copy hobocopy

  48. loser

    Shitty app doesn’t work with paths that have spaces in them.

Enter Your Email Here to Get Access for Free:

Go check your email!