
robocopy复制文件
Robocopy or Robust File and Folder Copy application is very popular amongst Windows system administrators. Robocopy will copy the local or given file to the remote or destination location.
Robocopy或“可靠的文件和文件夹复制”应用程序在Windows系统管理员中非常流行。 Robocopy会将本地或给定文件复制到远程或目标位置。
robocopy功能 (robocopy Features)
The command robocopy provides very useful features for files copying over network. Below we will list some of them.
robocopy命令为通过网络复制文件提供了非常有用的功能。 下面我们将列出其中一些。
Resume Interrupted Copy
when the network or remote host is down during a copy the copy operation can resume where it left.
Resume Interrupted Copy
当网络或远程主机在复制过程中关闭时,复制操作可以从其离开的地方继续进行。
Preserve File Attributes and timestamp
of the copied file where owner and audit information is also preserved.
Preserve File Attributes and timestamp
复制文件的Preserve File Attributes and timestamp
,其中还保留所有者和审核信息。
Ability To Update Copied File Attributes and Timestamps
of the copied files and folders which will set to the latest date and time.
Ability To Update Copied File Attributes and Timestamps
已复制文件和文件夹的Ability To Update Copied File Attributes and Timestamps
,这些Ability To Update Copied File Attributes and Timestamps
将设置为最新日期和时间。
Administrator Owned File Copy
is supported with the option /B
.
/B
选项支持Administrator Owned File Copy
。
Mirror Mode
is provided to sync or mirror given files and folder or directory updated files will be updated and deleted files will be deleted on the target.
提供了“ Mirror Mode
以同步或镜像给定的文件,并且将更新目标上的文件夹或目录更新的文件,并删除已删除的文件。
Skip Allready Existing Files
by checking size and timestamp information and comparing it to the source and target.
通过检查大小和时间戳信息并将其与源和目标进行比较,从而Skip Allready Existing Files
。
Progress Bar
will shown current copy operation graphically.
Progress Bar
将以图形方式显示当前的复制操作。
Multi-threaded copying
which will allow copy, mirror multiple files and directories at the same time which will decrease the complete copy operation time.
Multi-threaded copying
允许同时复制,镜像多个文件和目录,这将减少完整的复制操作时间。
robocopy命令语法 (robocopy Command Syntax)
The general syntax of robocopy
command is like below.
robocopy
命令的一般语法如下所示。
robocopy SOURCE DESTINATION FILE OPTIONS
- SOURCE is the source file or directory we want to copy SOURCE是我们要复制的源文件或目录
- DESTINATION is the destination file or directory we want to copyDESTINATION是我们要复制的目标文件或目录
- OPTIONS are different features or behaviors we want to use like recursive, verbose, extension filter, etc.选项是我们要使用的不同功能或行为,例如递归,详细,扩展过滤器等。
复制指定的文件夹 (Copy Specified Folder)
The most basic operation with robocopy
is copying sources folders to the destination. In this example, we will copy the directory named mytest
to the destination folder yourtest
robocopy
最基本操作是将源文件夹复制到目标位置。 在此示例中,我们将名为mytest
的目录复制到目标文件夹yourtest
> robocopy mytest yourtest

After copy operation, some statistics are provided by robocopy
复制操作后, robocopy
提供了一些统计信息
Start
shows start time of copy operationStart
显示复印操作的开始时间Source
shows source directorySource
显示源目录Dest
shows destination directoryDest
显示目的地目录Files
shows file filterFiles
显示文件过滤器Options
shows given optionsOptions
显示给定的选项Total
shows total files and folders countTotal
显示文件和文件夹总数Copied
shows copied files and folders countCopied
显示复制的文件和文件夹数Skipped
shows not copied files and foldersSkipped
显示未复制的文件和文件夹
从本地系统复制到远程系统(Copy From Local System To Remote System)
We can also copy a file and folders to the remote system. We will provide a remote system hostname or IP address before the destination path. We can use \\BACKUPSERVER or \\10.5.2.30 to specify the remote system.
我们还可以将文件和文件夹复制到远程系统。 我们将在目标路径之前提供一个远程系统主机名或IP地址。 我们可以使用\\ BACKUPSERVER或\\ 10.5.2.30来指定远程系统。
In this example, we will copy the source directory named mytest
to the remote system with IP address 192.168.122.46
under the path Users\ismail
with the named yourtest
.
在此示例中,我们将名为mytest
的源目录复制到IP地址为192.168.122.46
的远程系统上,并位于路径Users\ismail
,且名为yourtest
。
> robocopy mytest \\192.168.122.46\Users\ismail\yourtest

仅复制给定的文件类型或扩展名(Copy Only Given File Types or Extensions)
robocopy
provides some filtering features while copying files. We can specify the filenames and extensions we want to copy. This will skip other file names and extensions. We will provide the file name or extension after the destination folder.
robocopy
在复制文件时提供了一些过滤功能。 我们可以指定要复制的文件名和扩展名。 这将跳过其他文件名和扩展名。 我们将在目标文件夹之后提供文件名或扩展名。
In this example, we only want to copy *.txt
extension files.
在此示例中,我们只想复制*.txt
扩展名文件。
> robocopy mytest yourtest *.txt

We can see from the output that only one file is copied but there was more than one file. Copied file name and byte count is also printed.
从输出中我们可以看到仅复制了一个文件,但是有多个文件。 复制的文件名和字节数也会打印出来。
复制子文件夹 (Copy SubFolders)
By default, only first level directories are copied to the destination. If we need to copy all level and subdirectories folders we should enable /S
.
默认情况下,仅将第一级目录复制到目标。 如果需要复制所有级别和子目录文件夹,则应启用/S
> robocopy mytest yourtest /S

列出文件(List Files)
There is a very useful feature for robocopy where source files are not copied and just listed. This feature can be useful if we want to check existing files and folders. We can use /L
option to print the list of files and directories.
robocopy有一个非常有用的功能,其中的源文件不会被复制,而是被列出。 如果我们要检查现有文件和文件夹,则此功能很有用。 我们可以使用/L
选项来打印文件和目录的列表。
> robocopy mytest yourtest /L

As we can see from the output that all files and folders are skipped and not copied.
从输出中可以看到,所有文件和文件夹都被跳过而不复制。
递归列出文件 (List Files Recursively)
While robocopy is mainly used to copy files from remote to local or local to remove we can use /L
and /S
options in order to list remote files. We can merge two options list and recursive to list all level files and folders.
尽管robocopy主要用于将文件从远程复制到本地或本地删除,但我们可以使用/L
和/S
选项列出远程文件。 我们可以合并两个选项列表和递归列表所有级别的文件和文件夹。
> robocopy mytest yourtest /L /S
复制小于给定大小的文件 (Copy Files Lower Than Given Size)
While copying files we can specify the size of files we want to copy. In this example we will copy files those sizes are lower than 1K
. We will use the /MAX
option for this.
复制文件时,我们可以指定要复制的文件大小。 在此示例中,我们将复制那些大小小于1K
。 我们将使用/MAX
选项。
> robocopy mytest yourtest /S /MAX:1000

As we can see from the results some of the files are copied but some of them are not copied because of the size restriction.
从结果中我们可以看到,由于大小限制,某些文件被复制了,但有些文件没有被复制。
复制大于给定大小的文件 (Copy Files Higher Than Given Size)
The reverse of the previous option is /MIN
option . This will only copy files higher than the given size. In this example, we will copy files higher than 1K which is 1000 kilobytes.
上一个选项的相反是/MIN
选项。 这只会复制大于给定大小的文件。 在此示例中,我们将复制大于1K(即1000 KB)的文件。
> robocopy mytest yourtest /S /MIN:1000

移动文件(Move Files)
The default behavior of robocopy
is copying files. Sometimes we may need to move files. This can be done with robocopy
too. We will provide /MOV
option in order to move files and folders.
robocopy
的默认行为是复制文件。 有时我们可能需要移动文件。 这也可以用robocopy
完成。 我们将提供/MOV
选项以移动文件和文件夹。
> robocopy mytest yourtest /S /MOVE
记录作业 (Logging Operations)
While doing copy and move operations we can also need some logs, especially in bulk data operations. We can write a log about specified operations with /LOG
option. We can also specify the log file name y adding at the end of /LOG
option. In this example, we will write robocopy
operation log to log file named backup.log
. This will prevent regular output
在执行复制和移动操作时,我们还需要一些日志,尤其是在批量数据操作中。 我们可以使用/LOG
选项编写有关指定操作的/LOG
。 我们还可以指定在/LOG
选项末尾添加的日志文件名y。 在此示例中,我们将robocopy
操作日志写入名为backup.log
日志文件。 这将阻止常规输出
> robocopy mytest yourtest /S /LOG:backup.log
The log file can be listed with type
command in MS-DOS command line like below.
可以在MS-DOS命令行中使用type
命令列出日志文件,如下所示。
> type backup.log

复制给定的文件属性(Copy Given File Properties)
Files and folders may have different properties. These properties can be used for different purposes like the listing owner, audit information, timestamps, etc. We can copy these attributes too with the robocopy command. Here are the attributes we can specify for the copy. We will also use /copy:
option by adding the property we want to copy.
文件和文件夹可能具有不同的属性。 这些属性可用于列表所有者,审核信息,时间戳等不同目的。我们也可以使用robocopy命令复制这些属性。 这是我们可以为副本指定的属性。 我们还将通过添加要复制的属性来使用/copy:
选项。
D
is used to copy data propertiesD
用于复制数据属性A
used for attributesA
用于属性T
for time stampsT
为时间戳S
is used for NTFS access control list simply ACLS
用于NTFS访问控制列表,仅用于ACLO
is used for the owner informationO
用于所有者信息U
is used for Auditing informationU
用于审核信息
In this example, we will copy time stamp attributes or properties with the following command.
在此示例中,我们将使用以下命令复制时间戳记属性或属性。
> robocopy mytest yourtest /copy:T
使用/ copyall复制所有属性 (Copy All Attributes with /copyall)
We can also copy files with all properties of attributes with the /copyall
parameter like below. This is equal to the /copy:DATSOU
.
我们还可以使用/copyall
参数复制具有属性的所有属性的文件,如下所示。 这等于/copy:DATSOU
。
> robocopy mytest yourtest /copyall
删除或删除源中不再存在的目标文件和目录 (Delete or Remove Destination Files and Directories That No Longer Exist In The Source)
If we are trying to make an identical copy of the local files and directories to the remote we need to purge or remove remote files and directories that no longer exist in the source. We can use /purge
option for this.
如果我们尝试将本地文件和目录复制到远程目录,则需要清除或删除源文件中不再存在的远程文件和目录。 我们可以使用/purge
选项。
> robocopy mytest yourtest /purge
翻译自: https://www.poftut.com/windows-robocopy-command-tutorial-examples-copy-files-safe-way/
robocopy复制文件