How to copy (or back up) a file if in use or “locked” by Windows

How to copy (or back up) a file if in use or “locked” by Windows

Jay Valente
//

     So you’ve got a file you need to copy (or in my case, back up) but the file is in use all the time, and the backup system you are using is not able to get a clean copy, and throws some sort of error about the file being in use (dang you Backup Exec). What to do, what to do.

     Well, there is a neat utility out there, that is free, and works with the existing windows services (Volume Shadow Copy, and Microsoft Software Shadow Copy Provider), to copy an open file or directory while it is still in use. The utility is HoboCopy, and it’s free (my favorite price). You can download it from Source Forge or by following this link –> http://sourceforge.net/project/showfiles.php?group_id=117783&package_id=204974

     Just extract the file (I dumped it into C:WindowsSystem32 so I wouldn’t have to mess with paths), and use the very simple to follow syntax to copy your “in use” files. The syntax is simply: hobocopy c:directoryname d:backupdirectory

Here’s a few of the switches you can throw in:

/full    – Copy all files
/incremental  – Used after full to only copy changed files
/statefile=filename – Used with the above command to indicate where the state file is used. more later (where filename is the name of the file) 
/skipdenied  – Ignore “access denied” messages
/r    – Copy recursively
/y    – Don’t prompt (and copy everything)

One note, if your running this from Vista, you’ll want to make sure you run it as Administrator, as the program will start the two services listed above, and if you’re not an admin, that part will fail. You’ll also want to ensure those two services (see above) are set to be at least manual start. Don;t worry, Hobocopy will start and stop the services as it needs to, so no worries about extra services killing your machine.

     So let’s say you want to run a “Pre” command in Backup Exec to replicate a “live” directory , and then backup up the replica during the backup so you have a good copy of data (that is consistent). You could run a command like the following:

hobocopy /full /statefile=d:backuplastbackup.dat /y /r d:mainfolder d:backup

      This command would replicate all files in the “D:mainfolder” folder to the “D:backup” folder, and subsequently, create a file called lastbackup.dat, that going forward, will know the dates of all the files last backup, so going forward, an incremental backup could be used using the /incremental switch. The command you’d actually put into Backup Exec, in the “Pre-Command” section would be:

hobocopy /incremental /statefile=d:backuplastbackup.dat /y /r d:mainfolder d:backup

     My test run of a 5 GB directory took less than 10 minutes using the /full switch, and that was copying to and from the same drive, and there were LOTS of folders involved, so your speed may be much better.

     Hobocopy can also be used to copy single files, and would be great for a low cost backup or archive of files (there is a switch that allows removal of the source files, but I’m not even going to list that here, as I don’t want anyone blaming me for schwacking their files. 🙂  )

Good luck

 

Related

Need Expert Help?

See Our Full Menu of Data Services

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!