- Oct 04, 2017 You can easily verify that bedata.accdb is the source file. If server1databasebedata.accdb. Does not exist then the robocopy command will fail. Hence bedata.accdb must be the source file. Regardless of the above, robocopy, when used with the /r and /w switches, will move to the next file when dealing with a locked file.
- Aug 31, 2017 Robocopy will skip the open files, so be sure on your final robocopy that all the open files are closed. Also it is a very good idea to use the /log switch so that when you move file servers, people don't say to you 'you didn't copy this file' well you have proof with that file. Also that file will let you know any failed files.
Aug 21, 2013 Hello, Am trying to execute a batch / cmd file with dynamic parameter to the batch file using t-sql / xpcmdshell. Basically am trying to execute a robocopy command from t-sql - read somewhere that this is not possible & i hav to wrap my command in batch file. Nov 08, 2012 The /B tells robocopy to copy the file in 'backup' mode which is a special file access method designed to allow the backup of a file by users who do not have read access to the file. I would not recommend unlocking a file prior to backing it up unless you are 110% sure the file will not be modified whilst it is being copied.
Applies to: Windows Server 2016, Windows Server 2012 R2, Windows Server 2012, Windows Server 2008 R2, Windows Server 2008
This topic explains how to use the command-line tool, Robocopy.exe, to pre-seed files when setting up replication for Distributed File System (DFS) Replication (also known as DFSR or DFS-R) in Windows Server. By pre-seeding files before you set up DFS Replication, add a new replication partner, or replace a server, you can speed up initial synchronization and enable cloning of the DFS Replication database in Windows Server 2012 R2. The Robocopy method is one of several pre-seeding methods; for an overview, see Step 1: pre-seed files for DFS Replication.
The Robocopy (Robust File Copy) command-line utility is included with Windows Server. The utility provides extensive options that include copying security, backup API support, retry capabilities, and logging. Later versions include multi-threading and un-buffered I/O support.
Important
Robocopy does not copy exclusively locked files. If users tend to lock many files for long periods on your file servers, consider using a different pre-seeding method. pre-seeding does not require a perfect match between file lists on the source and destination servers, but the more files that do not exist when initial synchronization is performed for DFS Replication, the less effective pre-seeding is. To minimize lock conflicts, use Robocopy during non-peak hours for your organization. Always examine the Robocopy logs after pre-seeding to ensure that you understand which files were skipped because of exclusive locks.
To use Robocopy to pre-seed files for DFS Replication, follow these steps:
Prerequisites
Because pre-seeding does not directly involve DFS Replication, you only need to meet the requirements for performing a file copy with Robocopy.
How To Copy Locked Files With Robocopy
- You need an account that's a member of the local Administrators group on both the source and destination servers.
- Install the most recent version of Robocopy on the server that you will use to copy the files—either the source server or the destination server; you will need to install the most recent version for the operating system version. For instructions, see Step 2: Stabilize files that will be replicated. Unless you are pre-seeding files from a server running Windows Server 2003 R2, you can run Robocopy on either the source or destination server. The destination server, which typically has the more recent operating system version, gives you access to the most recent version of Robocopy.
- Ensure that sufficient storage space is available on the destination drive. Do not create a folder on the path that you plan to copy to: Robocopy must create the root folder.NoteWhen you decide how much space to allocate for the pre-seeded files, consider expected data growth over time and storage requirements for DFS Replication. For planning help, see Edit the Quota Size of the Staging Folder and Conflict and Deleted Folder in Managing DFS Replication.
- On the source server, optionally install Process Monitor or Process Explorer, which you can use to check for applications that are locking files. For download information, see Process Monitor and Process Explorer.
Step 1: Download and install the latest version of Robocopy
Before you use Robocopy to pre-seed files, you should download and install the latest version of Robocopy.exe. This ensures that DFS Replication doesn't skip files because of issues within Robocopy's shipping versions.
The source for the latest compatible Robocopy version depends on the version of Windows Server that is running on the server. For information about downloading the hotfix with the most recent version of Robocopy for Windows Server 2008 R2 or Windows Server 2008, see List of currently available hotfixes for Distributed File System (DFS) technologies in Windows Server 2008 and in Windows Server 2008 R2.
Alternatively, you can locate and install the latest hotfix for an operating system by taking the following steps.
Locate and install the latest version of Robocopy for a specific version of Windows Server
- In a web browser, open https://support.microsoft.com.
- In Search Support, enter the following string, replacing
<operating system version>
with the appropriate operating system, then press the Enter key:Command keys for mac font color text microsoft word.robocopy.exe kbqfe '<operating system version>'
For example, enter robocopy.exe kbqfe 'Windows Server 2008 R2'. - Locate and download the hotfix with the highest ID number (that is, the latest version).
- Install the hotfix on the server.
Step 2: Stabilize files that will be replicated
After you install the latest version of Robocopy on the server, you should prevent locked files from blocking copying by using the methods described in the following table. Most applications do not exclusively lock files. However, during normal operations, a small percentage of files might be locked on file servers.
Source of the lock | Explanation | Mitigation |
---|---|---|
Users remotely open files on shares. | Employees connect to a standard file server and edit documents, multimedia content, or other files. Sometimes referred to as the traditional home folder or shared data workloads. | Only perform Robocopy operations during off-peak, non-business hours. This minimizes the number of files that Robocopy must skip during pre-seeding. Consider temporarily setting Read-only access on the file shares that will be replicated by using the Windows PowerShell Grant-SmbShareAccess and Close-SmbSession cmdlets. If you set permissions for a common group such as Everyone or Authenticated Users to READ, standard users might be less likely to open files with exclusive locks (if their applications detect the Read-only access when files are opened). You might also consider setting a temporary firewall rule for SMB port 445 inbound to that server to block access to files or use the Block-SmbShareAccess cmdlet. However, both of these methods are very disruptive to user operations. |
Applications open files local. | Application workloads running on a file server sometimes lock files. | Temporarily disable or uninstall the applications that are locking files. You can use Process Monitor or Process Explorer to determine which applications are locking files. To download Process Monitor or Process Explorer, visit the Process Monitor and Process Explorer pages. |
Step 3: Copy the replicated files to the destination server
After you minimize locks on the files that will be replicated, you can pre-seed the files from the source server to the destination server.
Note
You can run Robocopy on either the source computer or the destination computer. The following procedure describes running Robocopy on the destination server, which typically is running a more recent operating system, to take advantage of any additional Robocopy capabilities that the more recent operating system might provide.
pre-seed the replicated files onto the destination server with Robocopy
- Sign in to the destination server with an account that's a member of the local Administrators group on both the source and destination servers.
- Open an elevated command prompt.
- To pre-seed the files from the source to destination server, run the following command, substituting your own source, destination, and log file paths for the bracketed values:This command copies all contents of the source folder to the destination folder, with the following parameters: Narnia 1 full movie.
Parameter Description '<source replicated folder path>' Specifies the source folder to pre-seed on the destination server. '<destination replicated folder path>' Specifies the path to the folder that will store the pre-seeded files.
The destination folder must not already exist on the destination server. To get matching file hashes, Robocopy must create the root folder when it pre-seeds the files./e Copies subdirectories and their files, as well as empty subdirectories. /b Copies files in Backup mode. /copyall Copies all file information, including data, attributes, time stamps, the NTFS access control list (ACL), owner information, and auditing information. /r:6 Retries the operation six times when an error occurs. /w:5 Waits 5 seconds between retries. MT:64 Copies 64 files simultaneously. /xd DfsrPrivate Excludes the DfsrPrivate folder. /tee Writes status output to the console window, as well as to the log file. /log <log file path> Specifies the log file to write. Overwrites the file's existing contents. (To append the entries to the existing log file, use /log+ <log file path>
.)/v Produces verbose output that includes skipped files. For example, the following command replicates files from the source replicated folder, E:RF01, to data drive D on the destination server:NoteWe recommend that you use the parameters described above when you use Robocopy to pre-seed files for DFS Replication. However, you can change some of their values or add additional parameters. For example, you might find out through testing that you have the capacity to set a higher value (thread count) for the /MT parameter. Also, if you'll primarily replicate larger files, you might be able to increase copy performance by adding the /j option for unbuffered I/O. For more information about Robocopy parameters, see the Robocopy command-line reference.WarningTo avoid potential data loss when you use Robocopy to pre-seed files for DFS Replication, do not make the following changes to the recommended parameters:- Do not use the /mir parameter (that mirrors a directory tree) or the /mov parameter (that moves the files, then deletes them from the source).
- Do not remove the /e, /b, and /copyall options.
- After copying completes, examine the log for any errors or skipped files. Use Robocopy to copy any skipped files individually instead of recopying the entire set of files. If files were skipped because of exclusive locks, either try copying individual files with Robocopy later, or accept that those files will require over-the-wire replication by DFS Replication during initial synchronization.
Next step
After you complete the initial copy, and use Robocopy to resolve issues with as many skipped files as possible, you will use the Get-DfsrFileHash cmdlet in Windows PowerShell or the Dfsrdiag command to validate the pre-seeded files by comparing file hashes on the source and destination servers. For detailed instructions, see Step 2: Validate pre-seeded Files for DFS Replication.
-->Copies file data from one location to another.
Syntax
For example, to copy a file named yearly-report.mov from c:reports to a file share marketingvideos while enabling multi-threading for higher performance (with the /mt parameter) and the ability to restart the transfer in case it's interrupted (with the /z parameter), type:
Parameters
Parameter | Description |
---|---|
<source> | Specifies the path to the source directory. |
<destination> | Specifies the path to the destination directory. |
<file> | Specifies the file or files to be copied. Wildcard characters (* or ?) are supported. If you don't specify this parameter, *. is used as the default value. |
<options> | Specifies the options to use with the robocopy command, including copy, file, retry, logging, and job options. |
Copy options
Option | Description |
---|---|
/s | Copies subdirectories. This option automatically excludes empty directories. |
/e | Copies subdirectories. This option automatically includes empty directories. |
/lev:<n> | Copies only the top n levels of the source directory tree. |
/z | Copies files in restartable mode. |
/b | Copies files in Backup mode. |
/zb | Uses restartable mode. If access is denied, this option uses Backup mode. |
/efsraw | Copies all encrypted files in EFS RAW mode. |
/copy:<copyflags> | Specifies which file properties to copy. The valid values for this option are:
|
/dcopy:<copyflags> | Specifies what to copy in directories. The valid values for this option are:
|
/sec | Copies files with security (equivalent to /copy:DATS). |
/copyall | Copies all file information (equivalent to /copy:DATSOU). |
/nocopy | Copies no file information (useful with /purge). |
/secfix | Fixes file security on all files, even skipped ones. |
/timfix | Fixes file times on all files, even skipped ones. |
/purge | Deletes destination files and directories that no longer exist in the source. Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten. |
/mir | Mirrors a directory tree (equivalent to /e plus /purge). Using this option with the /e option and a destination directory, overwrites the destination directory security settings. |
/mov | Moves files, and deletes them from the source after they are copied. |
/move | Moves files and directories, and deletes them from the source after they are copied. |
/a+:[RASHCNET] | Adds the specified attributes to copied files. The valid values for this option are:
|
/a-:[RASHCNET] | Removes the specified attributes from copied files. The valid values for this option are:
|
/create | Creates a directory tree and zero-length files only. |
/fat | Creates destination files by using 8.3 character-length FAT file names only. |
/256 | Turns off support for paths longer than 256 characters. |
/mon:<n> | Monitors the source, and runs again when more than n changes are detected. |
/mot:<m> | Monitors the source, and runs again in m minutes, if changes are detected. |
/MT[:n] | Creates multi-threaded copies with n threads. n must be an integer between 1 and 128. The default value for n is 8. For better performance, redirect your output using /log option. The /mt parameter can't be used with the /ipg and /efsraw parameters. |
/rh:hhmm-hhmm | Specifies run times when new copies may be started. |
/pf | Checks run times on a per-file (not per-pass) basis. |
/ipg:n | Specifies the inter-packet gap to free bandwidth on slow lines. |
/sl | Don't follow symbolic links and instead create a copy of the link. |
Important
When using the /secfix copy option, specify the type of security information you want to copy, using one of these additional copy options:
- /copyall
- /copy:o
- /copy:s
- /copy:u
- /sec
File selection options
Robocopy A Single File
Option | Description |
---|---|
/a | Copies only files for which the Archive attribute is set. |
/m | Copies only files for which the Archive attribute is set, and resets the Archive attribute. |
/ia:[RASHCNETO] | Includes only files for which any of the specified attributes are set. The valid values for this option are:
|
/xa:[RASHCNETO] | Excludes files for which any of the specified attributes are set. The valid values for this option are:
|
/xf <filename>[ ..] | Excludes files that match the specified names or paths. Wildcard characters (* and ?) are supported. |
/xd <directory>[ ..] | Excludes directories that match the specified names and paths. |
/xc | Excludes changed files. |
/xn | Excludes newer files. |
/xo | Excludes older files. |
/xx | Excludes extra files and directories. |
/xl | Excludes 'lonely' files and directories. |
/is | Includes the same files. |
/it | Includes modified files. |
/max:<n> | Specifies the maximum file size (to exclude files bigger than n bytes). |
/min:<n> | Specifies the minimum file size (to exclude files smaller than n bytes). |
/maxage:<n> | Specifies the maximum file age (to exclude files older than n days or date). |
/minage:<n> | Specifies the minimum file age (exclude files newer than n days or date). |
/maxlad:<n> | Specifies the maximum last access date (excludes files unused since n). |
/minlad:<n> | Specifies the minimum last access date (excludes files used since n) If n is less than 1900, n specifies the number of days. Otherwise, n specifies a date in the format YYYYMMDD. |
/xj | Excludes junction points, which are normally included by default. |
/fft | Assumes FAT file times (two-second precision). |
/dst | Compensates for one-hour DST time differences. |
/xjd | Excludes junction points for directories. |
/xjf | Excludes junction points for files. |
Retry options
Option | Description |
---|---|
/r:<n> | Specifies the number of retries on failed copies. The default value of n is 1,000,000 (one million retries). |
/w:<n> | Specifies the wait time between retries, in seconds. The default value of n is 30 (wait time 30 seconds). |
/reg | Saves the values specified in the /r and /w options as default settings in the registry. |
/tbd | Specifies that the system will wait for share names to be defined (retry error 67). |
Logging options
Option | Description |
---|---|
/l | Specifies that files are to be listed only (and not copied, deleted, or time stamped). |
/x | Reports all extra files, not just those that are selected. |
/v | Produces verbose output, and shows all skipped files. |
/ts | Includes source file time stamps in the output. |
/fp | Includes the full path names of the files in the output. |
/bytes | Prints sizes, as bytes. |
/ns | Specifies that file sizes are not to be logged. |
/nc | Specifies that file classes are not to be logged. |
/nfl | Specifies that file names are not to be logged. |
/ndl | Specifies that directory names are not to be logged. |
/np | Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed. |
/eta | Shows the estimated time of arrival (ETA) of the copied files. |
/log:<logfile> | Writes the status output to the log file (overwrites the existing log file). |
/log+:<logfile> | Writes the status output to the log file (appends the output to the existing log file). |
/unicode | Displays the status output as Unicode text. |
/unilog:<logfile> | Writes the status output to the log file as Unicode text (overwrites the existing log file). |
/unilog+:<logfile> | Writes the status output to the log file as Unicode text (appends the output to the existing log file). |
/tee | Writes the status output to the console window, as well as to the log file. |
/njh | Specifies that there is no job header. |
/njs | Specifies that there is no job summary. |
Job options
Option | Description |
---|---|
/job:<jobname> | Specifies that parameters are to be derived from the named job file. |
/save:<jobname> | Specifies that parameters are to be saved to the named job file. |
/quit | Quits after processing command line (to view parameters). |
/nosd | Indicates that no source directory is specified. |
/nodd | Indicates that no destination directory is specified. |
/if | Includes the specified files. |
Exit (return) codes
Value | Description |
---|---|
0 | No files were copied. No failure was encountered. No files were mismatched. The files already exist in the destination directory; therefore, the copy operation was skipped. |
1 | All files were copied successfully. |
2 | There are some additional files in the destination directory that are not present in the source directory. No files were copied. |
3 | Some files were copied. Additional files were present. No failure was encountered. |
5 | Some files were copied. Some files were mismatched. No failure was encountered. |
6 | Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory. |
7 | Files were copied, a file mismatch was present, and additional files were present. |
8 | Several files did not copy. |
Note
Any value greater than 8 indicates that there was at least one failure during the copy operation.