Copy Locked Files With Robocopy Using /b Parameter

Posted on admin

We are using Robocopy to redistribute files which arrive via FTP in a drop folder. Ideally we want Robocopy to leave files alone if they are still being FTPd. Having tried various switches, Robocopy still copies the open files. It doesn't delete them, so the FTP continues unaffected.

  1. Robocopy Skip Locked Files
Copy Locked Files With Robocopy Using /b Parameter

RoboCopy (Robust File Copy) is a command-line file copying tool in Windows. It is designed for reliable copying or mirroring of directories anywhere the computer has access, including local drives, removable drives, Local Area Network, remote servers, and in the process ensures that all file properties and permissions stays intact.RoboCopy also supports resume copying feature to pick up where it left off on network disconnect, which means when a copy fails at 99% you can just finish the last bits that were not copied. It has a handy command line progress indicator too which comes useful while copying large files.Robocopy was available for free download with the Windows Resource Kit since Windows NT 4.0, however it has never been an official feature of the operating system until the arrival of Vista. As of now, it works on the following Operating Systems: Windows 8, Windows 7, Windows Vista, Windows Server 2008, Windows Server 2003, Windows XP, and Windows 2000 or Microsoft Windows NT version 4.0. Robocopy Syntax and ExamplesRoboCopy Syntax: robocopy source destination file file. parameters.

source: specifies source folder. You can use drive:path or serversharepath here. destination: specifies destination folder. You can use drive:path or serversharepath here.

file: Files to process. Wildcard characters are supported (. match any sequence of characters,?: match a single character).

parameters: Command-line switches you wish to use. You can find the entire list at the end of this post.Examples:Example 1: A simple Robocopy command looks like this: robocopy C:Folder1 C:Backuporrobocopy sourceserverpath destinationserverpathThis command will copy all files in C:Folder1 to C:Backup. Sub-folders are excluded. To recursively copy all files and sub-folders, use this command: robocopy C:Folder1 C:Backup /EExample 2: Copy a single file: robocopy C:Folder1 C:Backup myfile.xlsxExample 3: Copy only a specific file type from source to destination: robocopy C:Folder1 C:Backup.docx /EExample 4: Mirror source folder to destination folder: robocopy C:Folder1 C:Backup /MIRThis command will mirror C:Folder1 to C:Backup. While doing so, it will delete any file(s)/folder(s) in the destination folder that’s not present in source.Example 5: Mirror folders, while preserving all pre-existing files and folders in destination. Robocopy C:Folder1 C:Backup /MIR /XXFor preserving specific file or folder use /XF (file) or /XD (folder) parameter. Robocopy C:Folder1 C:Backup /MIR /XD 'C:BackupOld'Example 6: Copy only those files and folders that exists in destination, ignore others: robocopy C:Folder1 C:Backup /S /XLExample 7: Copy files from source to destination, skipping files already existing in the destination.

Robocopy C:Folder1 C:Backup /SThis can be useful to save time as well as to prevent loss of existing file data/properties.Example 8: List files of specific size: robocopy C:Folder1 C:Backup /MAX:33554432 /LThis will list files larger than 32MB. Use /MIN for smaller than 32MB files.Example 9: Copy only those files that are older/newer than specified days: robocopy C:Folder1 C:Backup /E /MINAGE:7This command copies only those files that are older than 7 days. To select only newer files use /MAXAGE.Example 10: Mirror folders by enabling resume function, ignore hidden files, and reduce wait time between failures: robocopy robocopy C:Folder1 DestinationServerFolder1 /MIR /Z /XA:H /W:5/Z: Enables resume of while from without starting from beginning./XA:H: Ignore Hidden files./W:5: Reduces wait time between failures to 5 seconds instead of the 30 second default.Example 11: Monitor and automatically synchronize on change in source: robocopy C:Folder1 C:Backup /MON:1 /R:10This command re-saves every time a change is made.

Robocopy

Increase value of /MON to change number of changes before sync is performed. /R is used to specify retries.Example 12: Enable multi-threaded support: robocopy sourceserversharepath C:Backup /MIR /MT:nIn this command, n instructs Robocopy to do multi-threaded copies with n threads.Robocopy copies files and folders in multi-threaded operation by default, with 8 threads in one go.

Something you may have found while performing maintenance in Windows is that some files or folders simply cannot be opened or copied. One example is the folder found in the root of your hard drives which cannot be opened. Another is the found in the System32Config folder. Try to open or copy the SOFTWARE or SAM hive files for example and Windows will not allow you to do it popping up an error message.The error “The action can’t be completed because the file is open in System. Close the file and try again.” will show and even if you retry, the action cannot be completed.

A similar error is “Location not available, access denied” trying to open or read a file or folder. The reason these items cannot be accessed is because they are either intentionally locked to prevent access or are open and in use by the operating system meaning nothing else can can touch them.Various methods to unlock these files so you can gain access and manually copy them would include trying an. However, trying to unlock important system files often doesn’t work. Other ways to accomplish the task of removing their in use status are the Volume Shadow Service (VSS) which of the required files, or using low level disk access to gain access which can help bypass certain windows restrictions.Here we show you 7 different tools that can get access to those locked or in use files allowing you to copy or back them up manually. Shadow CopyShadow Copy uses the Volume Shadow Service allowing you to copy locked and in use files from one location to another with the aid of a simple user interface.

It does need installing but you can easily copy the Shadow Copy folder from Program Files and then uninstall again to run the program portably in future.Usage is pretty easy, browse for a copy from folder (note it will copy what’s in the folder and not the folder itself), browse for a copy to folder and click the Copy button. By default all files will be copied with the all files mask (.) which you can change to copy files with a specific extension.There are a few tick box options below to copy subdirectories, overwrite existing files, ignore errors and parse junction points. Running from the command line is supported but all that really does is open the user interface with predefined from and to locations set and automatically starts the copy.2. HoboCopyHoboCopy is a command line file copy and backup tool which uses the Volume Shadow Service and is inspired by Microsoft’s Robocopy. It has a few commands to create a full or incremental backup but these are not required for copying in use or locked files.

Robocopy Skip Locked Files

The command and arguments for that purpose are quite simple:HoboCopy /r C:WindowsSystem32config C:BackupThis will copy the whole contents of Config to the Backup folder, remove the /r to ignore any sub folders. To copy individual files from the Config folder append them to the end of the line:HoboCopy C:WindowsSystem32config C:Backup SOFTWARE SYSTEMThe above will copy only the SOFTWARE and SYSTEM registry hive files to the Backup folder.If you prefer to avoid the command line you can use a front end GUI for HoboCopy called Hobo GUI to simplify the task and copy folders to another location. Click Add to find a source folder, click and browse for a destination folder, press Find Hobo to locate the HoboCopy executable and then press the Backup button.Weirdly Hobo GUI is only 40K in size but requires installation although you can easily bypass this by extracting the installer file with 7-Zip and keeping it as a portable tool.Do note that HoboCopy requires the Visual C runtimes and you will need to use the appropriate 32-bit or 64-bit version. Although it still works fine, HoboCopy itself was discontinued by its author in favor of ShadowSpawn, which is below. 3. ShadowSpawnShadowSpawn’s author says HoboCopy’s copy process was not as good as he wanted so he took the shadowing part and released it as a standalone product so it can be used with third party copy tools.

ShadowSpawn is command line only and relies on the end user having knowledge of other copy tool commands as well as its own.It works by copying the specified folder to a temporary RAM drive using VSS, and in the same command you supply the copy command and arguments from the copy utility using the RAM drive letter as the source. Here’s an example using the FastCopy copying tool:Shadowspawn C:windowssystem32config y: fastcopy /openwindow y: /to=c:backupThat will copy the contents of the Config folder to the temporary RAM drive (y:), then ShadowSpawn invokes FastCopy which copies the contents from y: to the backup folder.

Once copying is complete and the copy tool closed, ShadowSpawn will unmount the RAM drive and exit. You can actually browse and copy most shadowed files from Windows Explorer without a third party copying tool using a command like below:ShadowSpawn C:windowssystem32config y: cmd /k explorer.exe y:This will open shadowed drive y: in Explorer so you can view and copy whatever files you need.

When you’re finished go back to the ShadowSpawn window and press Ctrl+C to release the RAM drive and exit. There are separate 32-bit and 64-bit versions and Visual C runtimes are required.4.

Passmark OSForensicsOSForensics may seem a bit overkill because it’s a 50MB+ installer and a full suite of information gathering tools, but the copying of locked and in use files is completely transparent and done from a Windows Explorer style interface. This makes it very easy to use and allows you to copy whole folders full of locked files with minimal fuss.After install choose to “Continue using the free version”, click the Create Case button and give it a name which places all operations into a profile. Then click File System Browser on the left, choose the drive you want to copy from and click OK.The file browser will be familiar as it’s like Explorer and you simply use it to locate the in use files or folders you want to copy. Right click on the entry, select Save to disk and choose the folder you want to save to.

This makes OSForensics ideal for quickly copying several different folders containing in use files, you can also multi select with Shift+click and Ctrl+click.5. PC HunterIf OSForensics is a bit too much for you, PC Hunter is worth a try because it provides a similar Explorer like file and folder tree view so you can easily copy in use files or a whole folder. PC Hunter is actually an advanced anti rootkit tool that operates at an extremely low level on the system, as a result it may trigger an alert in your antivirus.For such a powerful tool PC Hunter is remarkably simple to use, run the portable 32-bit or 64-bit executable, click on the File tab and use the folder tree to locate the file you want to copy. Right click on the file and choose Copy to. One issue is selecting more than one file will grey out the option although you can still duplicate the whole folder by right clicking on it in the folder tree and using the Copy to option. For advanced users PC Hunter is also very capable at deleting hard to remove files and registry entries although it needs to be used with care.6.

ExtentsExtents is a little bit different because it doesn’t use the Volume Shadow Service but instead reads the actual raw clusters on the disk used by the file and reconstructs them into a new file. This has the side effect of bypassing locking or in use restrictions imposed by the operating system.Only a single file can be handled at a time so it’s best used when you only want to copy one or two files at the most. Run the Extents executable and press Open to look for the in use file. The display will show the disk cluster details of the file. Click the Dump button and choose the save location and filename, make sure to use the same filename and include the extension. Note that Extents doesn’t work perfectly in 64-bit Windows, for instance it will not detect or load open Registry hives like SAM or SOFTWARE.7. RawCopyWhile it’s not exactly the same as Extents in operation, RawCopy is quite similar by using low level disk reading to copy a file from an NTFS formatted disk, whether it’s locked or not.

The biggest obvious difference is the fact RawCopy is used from the command line only and has no user interface.Usage is quite straightforward, simply supply a source path and name of a single file and a destination folder argument to the command, make sure to include quotes if spaces are involved:rawcopy C:WINDOWSsystem32configSYSTEM C:outputfolderBy default the tool will try to copy using the file’s name, if it cannot because for instance the parent folder has locks on it, RawCopy will then try by using the file index number from the Master File Table. There are 32-bit and 64-bit versions available so make sure you use the correct one.