Subscribe to 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

| More
This article was originally written on 03/9/08 Tagged with: Managing Files and Folders, Windows 7, Windows 7 Tips, Windows Vista

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:

Comments (23)

  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


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Our Friends
Getting Started


About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
mDNSResponder.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
conhost.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.