Chances are you have run into this problem if you have ever tried copying your files from Windows to another computer, using Windows Explorer, to back them up. You get an error such as “Cannot copy filename: It is being used by another person or program. Close any programs that might be using the file and try again.”
When this happens, your whole copy stops, and you have no idea how far it got before it stopped. It becomes a painful process. Fortunately, there is a program out there called ROBOCOPY, which somehow is supposed to stand for ‘Robust Copy’, it almost works if you ignore the second O. Anyway, this program works great, by continuing in the event of an error. It skips all files in use. ROBOCOPY is a command-line tool, but it has some gui addons to make it easier to use (it’s really not that difficult–how many options can there be to copy files?)
But what if you want to copy in-use files too? Opened files are just as important as closed files, if not moreso. Enter Volume Shadow Services and a little utility called HOBOCOPY (I sense a naming trend here…). HOBOCOPY interacts with Windows by creating a VSS snapshot, which is basically a point-in-time copy of all your files, whether open or closed. HOBOCOPY isn’t as polished as ROBOCOPY, and it wasn’t written by Microsoft, but it is a good utility nonetheless.
Here is a script I wrote to take the work out of using HOBOCOPY remotely.
@echo off :: Backup Script :: usage: backup.bat <computername> <path> :: Stores it in local \\computername\backup path, needs to be shared with full write privileges :: Required files: psexec.exe, hobocopy.exe IF [%2]== goto instr set cmp=%1 set src=%2 set dst=\\%computername%\backup\%cmp% c: cd \backup IF EXIST backup.log del backup.log echo Backup Script > backup.log echo Backup Script echo Backup of %src% to %dst% >> backup.log echo Backup of %src% to %dst% psexec -s -c \\%cmp% c:\backup\hobocopy.exe /full /skipdenied /r /y %src% %dst% echo Backup Complete! >> backup.log goto end :instr echo Backup Script echo usage: backup.bat ^<computername^> ^<path^> echo example: backup NGARA c:\ echo Stores backup in local \\computername\backup path, needs to be shared with full write privileges echo Required files: psexec.exe, hobocopy.exe :end set src= set dst= set cmp=
Since it interacts with the operating system, it needs to have local access to the source drive (in otherwords, if you’re copying from SRC to DST, you can’t run it on DST). The batch file makes it work so that you can run it from DST. Note that I’ve used PSEXEC, another great utility, to remotely execute HOBOCOPY from the destination computer. That way, if I am backing up a remote user’s system, I don’t have to be physically near the computer.
In order to use the script, first you have to set up the destination computer DST:
1. Create a directory called c:\backup on DST
2. Share that directory with All permissions to Everyone
3. Copy PSEXEC.EXE and HOBOCOPY.EXE into c:\backup
4. Create ‘backup.bat’ and copy the above code into it, save in c:\backup
5. Run the script from a command prompt on DST:
C:\> backup.bat SRC C:\
Where SRC is the computername of the source computer and C:\ is the drive you want to back up. Note that only local drives are supported.
Access Denied – Check your shared permissions. Note that the Security permissions AND the Share permissions must both be set to allow write access to a shared directory. Windows treats them separately and requires both to allow you to write to a directory.
COM failure 0x80042301 – There is a blog post about this one, but I haven’t figured it out yet.
HOBOCOPY – Hosted by SourceForge (it’s open source!) Click the Files tab, then browse through Hobocopy – 22.214.171.124 – Hobocopy-126.96.36.199-XP-32bit-Release.zip. Then extract it to c:\backup
PSEXEC – Download and unzip into c:\backup
ROBOCOPY – Part of the Windows 2003 Resource Kit Tools. If you want to try this out, Install the Resource Kit, then go into C:\program files\Windows Resource Kits\Tools and copy robocopy.exe to c:\backup