robocopyrobocopy

将文件数据从一个位置复制到另一个位置。Copies file data from one location to another.

语法Syntax

robocopy <source> <destination> [<file>[ ...]] [<options>]

例如,若要将名为 yearly-report 的文件从 c:\reports 复制到文件共享 \ \ marketing\videos ,同时启用多线程以实现更高性能的 (使用 /mt 参数) 并且在 (与 /z 参数) 中断的情况下重启传输的功能,请键入:For example, to copy a file named yearly-report.mov from c:\reports to a file share \\marketing\videos 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:

robocopy c:\reports '\\marketing\videos' yearly-report.mov /mt /z

参数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> 指定用于 robocopy 命令的选项,包括 复制文件重试日志记录作业 选项。Specifies the options to use with the robocopy command, including copy, file, retry, logging, and job options.

复制选项Copy options

选项Option 说明Description
/s/s 复制子目录。Copies subdirectories. 此选项将自动排除空目录。This option automatically excludes empty directories.
/e/e 复制子目录。Copies subdirectories. 此选项将自动包含空目录。This option automatically includes empty directories.
列弗<n>/lev:<n> 仅复制源目录树的前 n 个级别。Copies only the top n levels of the source directory tree.
/z/z 在可重启模式下复制文件。Copies files in restartable mode. 在重新启动模式下,如果文件复制中断,则 Robocopy 可以从中断位置开始,而不是重新复制整个文件。In restartable mode, should a file copy be interrupted, Robocopy can pick up where it left off rather than re-copying the entire file.
/b/b 在备份模式下复制文件。Copies files in backup mode. 备份模式允许 Robocopy 覆盖 (Acl) 的文件和文件夹权限设置。Backup mode allows Robocopy to override file and folder permission settings (ACLs). 这允许您复制您可能没有访问权限的文件,前提是它是在具有足够权限的帐户下运行。This allows you to copy files you might otherwise not have access to, assuming it's being run under an account with sufficient privileges.
/zb/zb 在可重启模式下复制文件。Copies files in restartable mode. 如果文件访问被拒绝,则切换到备份模式。If file access is denied, switches to backup mode.
/j/j 对于大型文件) ,使用未缓冲的 i/o (建议的副本。Copies using unbuffered I/O (recommended for large files).
/efsraw/efsraw 复制 EFS RAW 模式下的所有加密文件。Copies all encrypted files in EFS RAW mode.
/copy<copyflags>/copy:<copyflags> 指定要复制的文件属性。Specifies which file properties to copy. 此选项的有效值为:The valid values for this option are:
  • D -数据D - Data
  • A -特性A - Attributes
  • T -时间戳T - Time stamps
  • S -NTFS 访问控制列表 (ACL) S - NTFS access control list (ACL)
  • O -所有者信息O - Owner information
  • U 审核信息U - Auditing information
此选项的默认值为 " DAT (数据、属性和时间戳) 。The default value for this option is DAT (data, attributes, and time stamps).
/dcopy:<copyflags>/dcopy:<copyflags> 指定要在目录中复制的内容。Specifies what to copy in directories. 此选项的有效值为:The valid values for this option are:
  • D -数据D - Data
  • A -特性A - Attributes
  • T -时间戳T - Time stamps
此选项的默认值为 DA (的数据和属性) 。The default value for this option is DA (data and attributes).
/秒/sec 复制安全 (等效于 /copy: dat) 的文件。Copies files with security (equivalent to /copy:DATS).
/copyall/copyall 复制 (等效于 /copy: DATSOU) 的所有文件信息。Copies all file information (equivalent to /copy:DATSOU).
/nocopy/nocopy 不复制任何文件信息 (对 /purge) 有用。Copies no file information (useful with /purge).
/secfix/secfix 修复了所有文件的文件安全问题,甚至会跳过文件。Fixes file security on all files, even skipped ones.
/timfix/timfix 修复所有文件上的文件时间,甚至是跳过的文件。Fixes file times on all files, even skipped ones.
/purge/purge 删除源中不再存在的目标文件和目录。Deletes destination files and directories that no longer exist in the source. 将此选项与 /e 选项和目标目录一起使用时,允许不覆盖目标目录安全设置。Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten.
/mir/mir 镜像目录树 (等效于 /e plus /purge) 。Mirrors a directory tree (equivalent to /e plus /purge). 将此选项与 /e 选项和目标目录一起使用将覆盖目标目录安全设置。Using this option with the /e option and a destination directory, overwrites the destination directory security settings.
/mov/mov 移动文件,并在复制后从源中删除它们。Moves files, and deletes them from the source after they are copied.
/move/move 移动文件和目录,并在复制后从源中删除这些文件和目录。Moves files and directories, and deletes them from the source after they are copied.
/a +: [RASHCNET]/a+:[RASHCNET] 将指定的属性添加到复制的文件。Adds the specified attributes to copied files. 此选项的有效值为:The valid values for this option are:
  • R -只读R - Read only
  • A -存档A - Archive
  • S -系统S - System
  • H -隐藏H - Hidden
  • C -压缩C - Compressed
  • N -未索引内容N - Not content indexed
  • E -已加密E - Encrypted
  • T -临时T - Temporary
/a-: [RASHCNET]/a-:[RASHCNET] 从复制的文件中删除指定的属性。Removes the specified attributes from copied files. 此选项的有效值为:The valid values for this option are:
  • R -只读R - Read only
  • A -存档A - Archive
  • S -系统S - System
  • H -隐藏H - Hidden
  • C -压缩C - Compressed
  • N -未索引内容N - Not content indexed
  • E -已加密E - Encrypted
  • T -临时T - Temporary
/create/create 仅创建目录树和长度为零的文件。Creates a directory tree and zero-length files only.
/fat/fat 仅使用8.3 的字符长度 FAT 文件名创建目标文件。Creates destination files by using 8.3 character-length FAT file names only.
/256/256 关闭对长度超过256个字符的路径的支持。Turns off support for paths longer than 256 characters.
<n>/mon:<n> 监视源,并在检测到超过 n 个更改时再次运行。Monitors the source, and runs again when more than n changes are detected.
/mot:<m>/mot:<m> 监视源,如果检测到更改,则在 m 分钟内再次运行。Monitors the source, and runs again in m minutes, if changes are detected.
/MT[:n]/MT[:n] n 个线程创建多线程副本。Creates multi-threaded copies with n threads. n 必须是介于1到128之间的整数。n must be an integer between 1 and 128. N 的默认值为8。The default value for n is 8. 为了获得更好的性能,请使用 /log 选项重定向你的输出。For better performance, redirect your output using /log option.

/Mt 参数不能与 /ipg/efsraw 参数一起使用。The /mt parameter can't be used with the /ipg and /efsraw parameters.

/rh: hhmm-hhmm/rh:hhmm-hhmm 指定可能启动新副本时的运行时间。Specifies run times when new copies may be started.
/pf/pf 检查每个文件上的运行时间 (不按) 。Checks run times on a per-file (not per-pass) basis.
/ipg: n/ipg:n 指定在慢速线路上释放带宽的数据包间间隔。Specifies the inter-packet gap to free bandwidth on slow lines.
/sl/sl 不要跟踪符号链接,而是创建链接的副本。Don't follow symbolic links and instead create a copy of the link.
/nodcopy/nodcopy (默认 /dcopy: DA) 完成复制目录信息。Copies no directory info (the default /dcopy:DA is done).
/nooffload/nooffload 在不使用 Windows 复制卸载机制的情况下复制文件。Copies files without using the Windows Copy Offload mechanism.
/compress/compress 在文件传输过程中请求网络压缩(如果适用)。Requests network compression during file transfer, if applicable.

重要

使用 /secfix copy 选项时,请使用以下附加复制选项之一指定要复制的安全信息类型:When using the /secfix copy option, specify the type of security information you want to copy, using one of these additional copy options:

  • /copyall/copyall
  • /copy: o/copy:o
  • /copy: s/copy:s
  • /copy: u/copy:u
  • /sec/sec

文件选择选项File selection options

选项Option 说明Description
/a/a 仅复制为其设置了 存档 属性的文件。Copies only files for which the Archive attribute is set.
/m/m 仅复制设置了 存档 属性的文件,并重置 存档 属性。Copies only files for which the Archive attribute is set, and resets the Archive attribute.
i[RASHCNETO]/ia:[RASHCNETO] 仅包括为其设置了任何指定属性的文件。Includes only files for which any of the specified attributes are set. 此选项的有效值为:The valid values for this option are:
  • R -只读R - Read only
  • A -存档A - Archive
  • S -系统S - System
  • H -隐藏H - Hidden
  • C -压缩C - Compressed
  • N -未索引内容N - Not content indexed
  • E -已加密E - Encrypted
  • T -临时T - Temporary
  • O -脱机O - Offline
xa[RASHCNETO]/xa:[RASHCNETO] 排除为其设置了任何指定属性的文件。Excludes files for which any of the specified attributes are set. 此选项的有效值为:The valid values for this option are:
  • R -只读R - Read only
  • A -存档A - Archive
  • S -系统S - System
  • H -隐藏H - Hidden
  • C -压缩C - Compressed
  • N -未索引内容N - Not content indexed
  • E -已加密E - Encrypted
  • T -临时T - Temporary
  • O -脱机O - Offline
/xf <filename>[ ...]/xf <filename>[ ...] 排除匹配指定名称或路径的文件。Excludes files that match the specified names or paths. 支持 (*) 的通配符。Wildcard characters (* and ?) are supported.
/xd <directory>[ ...]/xd <directory>[ ...] 排除匹配指定名称和路径的目录。Excludes directories that match the specified names and paths.
/xc/xc 排除具有相同时间戳但不同文件大小的现有文件。Excludes existing files with the same timestamp, but different file sizes.
/xn/xn 排除比源目录中的副本更新的现有文件。Excludes existing files newer than the copy in the source directory.
/xo/xo 排除源目录中早于副本的现有文件。Excludes existing files older than the copy in the source directory.
/xx/xx 排除在目标中存在但源中不存在的额外文件和目录。Excludes extra files and directories present in the destination but not the source. 排除多余文件将不会从目标中删除文件。Excluding extra files will not delete files from the destination.
/xl/xl 排除源中存在的 "孤立的" 文件和目录,但不包括目标。Excludes "lonely" files and directories present in the source but not the destination. 排除孤立的文件可防止将任何新文件添加到目标。Excluding lonely files prevents any new files from being added to the destination.
/is/is 包括相同的文件。Includes the same files. 相同文件的名称、大小、时间和所有属性相同。Same files are identical in name, size, times, and all attributes.
/it/it 包括 "调整" 文件。Includes "tweaked" files. 调整文件具有相同的名称、大小和时间,但具有不同的属性。Tweaked files have the same name, size, and times, but different attributes.
数量<n>/max:<n> 指定 (的最大文件大小以排除超过 n 个) 的文件。Specifies the maximum file size (to exclude files bigger than n bytes).
/min<n>/min:<n> 指定 (以排除小于 n 个字节) 的文件的最小文件大小。Specifies the minimum file size (to exclude files smaller than n bytes).
maxage<n>/maxage:<n> 指定要排除早于 n 天或日期) 的文件 (最长文件保留时间。Specifies the maximum file age (to exclude files older than n days or date).
/minage:<n>/minage:<n> 指定 "最短文件保留时间" (排除晚于 n 天或日期) 的文件。Specifies the minimum file age (exclude files newer than n days or date).
/maxlad:<n>/maxlad:<n> 指定最大上次访问日期 (排除自 n) 以来未使用的文件。Specifies the maximum last access date (excludes files unused since n).
/minlad:<n>/minlad:<n> 指定最小的上次访问日期 (排除 使用的文件,因为 n) 如果 n 小于1900,则 n 指定 天数。Specifies the minimum last access date (excludes files used since n) If n is less than 1900, n specifies the number of days. 否则, n 以 YYYYMMDD 格式指定日期。Otherwise, n specifies a date in the format YYYYMMDD.
/xj/xj 排除联接点,默认情况下这些联接点通常包括在内。Excludes junction points, which are normally included by default.
/fft/fft 采用 FAT 文件时间(精度为两秒)。Assumes FAT file times (two-second precision).
/dst/dst 补偿一小时的 DST 时间差异。Compensates for one-hour DST time differences.
/xjd/xjd 排除目录的交接点。Excludes junction points for directories.
/xjf/xjf 排除文件的交接点。Excludes junction points for files.

重试选项Retry options

选项Option 说明Description
/r:<n>/r:<n> 指定复制失败时的重试次数。Specifies the number of retries on failed copies. N 的默认值为 1000000 (1000000 重试) 。The default value of n is 1,000,000 (one million retries).
/w:<n>/w:<n> 指定等待重试的间隔时间,以秒为单位。Specifies the wait time between retries, in seconds. N 的默认值为 30 (等待时间) 为30秒。The default value of n is 30 (wait time 30 seconds).
/reg/reg /r/w 选项中指定的值保存为注册表中的默认设置。Saves the values specified in the /r and /w options as default settings in the registry.
/tbd/tbd 指定系统将等待定义共享名称 (重试错误 67) 。Specifies that the system will wait for share names to be defined (retry error 67).

日志记录选项Logging options

选项Option 说明Description
/l/l 指定只列出 (,而不会对文件进行) 复制、删除或时间戳。Specifies that files are to be listed only (and not copied, deleted, or time stamped).
/x/x 报告所有多余的文件,而不仅仅是所选的文件。Reports all extra files, not just those that are selected.
/v/v 生成详细输出,并显示跳过的所有文件。Produces verbose output, and shows all skipped files.
/ts/ts 在输出中包括源文件时间戳。Includes source file time stamps in the output.
/fp/fp 在输出中包括文件的完整路径名称。Includes the full path names of the files in the output.
/bytes/bytes 将大小打印为字节。Prints sizes, as bytes.
/ns/ns 指定不记录文件大小。Specifies that file sizes are not to be logged.
/nc/nc 指定不记录文件类。Specifies that file classes are not to be logged.
/nfl/nfl 指定不记录文件名。Specifies that file names are not to be logged.
/ndl/ndl 指定不记录目录名。Specifies that directory names are not to be logged.
/np/np 指定不要显示复制操作的进度(到目前为止复制的文件或目录数)。Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.
/eta/eta 显示所复制文件 (ETA) 的预计到达时间。Shows the estimated time of arrival (ETA) of the copied files.
/log<logfile>/log:<logfile> 将状态输出写入到日志文件(覆盖现有的日志文件)。Writes the status output to the log file (overwrites the existing log file).
/log +:<logfile>/log+:<logfile> 将状态输出写入日志文件 (将输出追加到现有日志文件) 。Writes the status output to the log file (appends the output to the existing log file).
/unicode/unicode 将状态输出显示为 Unicode 文本。Displays the status output as Unicode text.
/unilog:<logfile>/unilog:<logfile> 将状态输出作为 Unicode 文本写入日志文件 (覆盖现有日志文件) 。Writes the status output to the log file as Unicode text (overwrites the existing log file).
/unilog +:<logfile>/unilog+:<logfile> 将状态输出作为 Unicode 文本写入日志文件 (将输出追加到现有日志文件) 。Writes the status output to the log file as Unicode text (appends the output to the existing log file).
/tee/tee 将状态输出写入控制台窗口以及日志文件。Writes the status output to the console window, as well as to the log file.
/njh/njh 指定没有作业标头。Specifies that there is no job header.
/njs/njs 指定没有作业摘要。Specifies that there is no job summary.

作业选项Job options

选项Option 说明Description
/作业<jobname>/job:<jobname> 指定参数将从命名作业文件派生。Specifies that parameters are to be derived from the named job file.
<jobname>/save:<jobname> 指定将参数保存到指定的作业文件中。Specifies that parameters are to be saved to the named job file.
/quit/quit 处理命令行 (后退出,以便查看) 的参数。Quits after processing command line (to view parameters).
/nosd/nosd 指示未指定源目录。Indicates that no source directory is specified.
/nodd/nodd 指示未指定目标目录。Indicates that no destination directory is specified.
/if/if 包含指定的文件。Includes the specified files.

退出 (返回) 代码Exit (return) codes

Value 说明Description
00 未复制文件。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.
11 已成功复制所有文件。All files were copied successfully.
22 目标目录中有一些其他文件在源目录中不存在。There are some additional files in the destination directory that are not present in the source directory. 未复制文件。No files were copied.
33 已复制某些文件。Some files were copied. 存在其他文件。Additional files were present. 未遇到任何故障。No failure was encountered.
55 已复制某些文件。Some files were copied. 某些文件不匹配。Some files were mismatched. 未遇到任何故障。No failure was encountered.
66 其他文件和文件不匹配。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.
77 文件已复制,存在文件不匹配,并存在其他文件。Files were copied, a file mismatch was present, and additional files were present.
88 几个文件没有复制。Several files did not copy.

备注

任何大于 8 的值都表示在复制操作过程中至少出现一次失败。Any value greater than 8 indicates that there was at least one failure during the copy operation.

其他参考Additional References