robocopy - Directory replication

最後更新: 2016-01-11

介紹

robocopy (Robust File Copy)

由 Windows Server 2008 開始出現, OS 已有它, 不用另外安裝

好處:

* Ability to tolerate network interruptions and resume copying.
* A "mirror" mode
* Ability to skip files that already appear in the destination folder with identical size and timestamp.
* Multithreaded copying.

缺點:

Robocopy will not copy open files.

Any process may open files for exclusive read access by withholding the FILE_SHARE_READ[4] flag during opening.

Even robocopy's Backup mode will not touch those files. (Backup mode instead runs Robocopy as a "Backup Operator".

This allows Robocopy to override permissions settings (specifically, NTFS ACLs).[5] [6])

 


用法

 

robocopy <Source> <Destination> [<File>[ ...]] [<Options>]

<File>                # Specifies the file to be copied.

Options:

/e                       # Copies subdirectories. Note that this option includes empty directories.

/s                       # Copies subdirectories. Note that this option excludes empty directories.

/purge                # Deletes destination files and directories that no longer exist in the source

/sl                      # Copies the symbolic link instead of the target.

mode:

/b                       # Copies files in Backup mode.

/z                       # Copies files in Restart mode.

/zb                     # Uses Restart mode. If access is denied, this option uses Backup mode.

retry:

/r:N                   # number of retries on failed copies. The default 1,000,000

/W:N                  # wait time between retries. The default: 30 sec

/REG                 # 將 /R:n 和 /W:n 儲存至登錄中,變成預設值。

display

/unicode              # Displays the status output as Unicode text.

/eta                     # 顯示預計完成時間。

log

/log:<LogFile>     # overwrites the existing log file

/log+:<LogFile>   # appends the output to the existing log file

/UNILOG:file         # UNICODE log (覆寫現有的記錄檔)

/TEE                    # 輸出至主控台視窗,以及記錄檔。

/NP                     # 無進度 - 不顯示複製百分比

# log 時不會有類似行
  0%
2.0%
....
100%

alias

/copyall           # Copies all file information (equivalent to /copy:DATSOU)

/sec                # Copies files with security (equivalent to /copy:DAT)

/mir                # Mirrors a directory tree (equivalent to /e plus /purge)

 

 


Example

 

# 將 "c:\tmp" copy 到 "d:\tmp"

robocopy /eta /e c:\tmp d:\tmp


-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows

-------------------------------------------------------------------------------

  已啟動 : Mon May 28 17:54:15 2018

    來源 : c:\tmp\
  目的地 : d:\tmp\

    檔案 : *.*

    選項 : *.* /S /E /COPY:DAT /ETA /R:1000000 /W:30

-------------------------------------------------------------------------------

                           1    c:\tmp\
                           1    c:\tmp\test\

-------------------------------------------------------------------------------

                  總計       已複製        略過        不符        失敗
額外
      目錄 :         2         0         2         0         0         0
      檔案 :         2         0         2         0         0         0
     位元組 :         8         0         8         0         0         0
      時間 :   0:00:00   0:00:00                       0:00:00   0:00:00

     已結束 : Mon May 28 17:54:15 2018

# 只 copy 某類 File

robocopy \\Server1\image \\Server2\backup *.jpg *.bmp

# Mirror & Backup mode & Keep log. 一定要用 administrator shell 行

robocopy /mir /B  /W:10 /r:3  /NP /TEE /LOG:D:\backup\logs\tmp.log    C:\tmp    D:\backup\data

 

 


Backup 與 Restart Mode(/B)

 

Backup Mode(/B)

When Robocopy is executed in backup mode the software bypasses file permissions that would otherwise prevent a successful backup.

You must be an Administrator or a member of the backup operators group to run Robocopy in this way.

 * 需要 administrator shell 去行

Restart mode(/Z)

to do with a partially-copied file.

With this option, should the copy be interrupted while any particular file is partially copied,

the next execution of robocopy can pick up where it left off rather than re-copying the entire file.

 * 只有 mount net driver 的時候有效 ( local disk 不會續存 )

 * 只能回復以 /z 開始的 copy

 * 需要比沒有用 /z 更多時間去 copy

 

 

 

Creative Commons license icon Creative Commons license icon