What is Robocopy's "restartable" option?

Learn what is robocopy's "restartable" option? with practical examples, diagrams, and best practices. Covers command-line-arguments, robocopy development techniques with visual explanations.

Understanding Robocopy's "Restartable" Option (/Z)

Illustration of files being copied with a progress bar, symbolizing a robust and restartable transfer process.

Explore the Robocopy /Z (restartable) option, its benefits for large file transfers, and how it ensures data integrity and efficiency.

Robocopy (Robust File Copy) is a powerful command-line utility in Windows for copying files and directories. It offers a multitude of options to handle various copying scenarios, from simple transfers to complex synchronization tasks. Among its most valuable features is the ability to resume interrupted file transfers, a capability provided by the /Z (restartable) option. This article delves into what the /Z option does, why it's crucial for large or unreliable transfers, and how it works under the hood.

What is the /Z (Restartable) Option?

The /Z option in Robocopy enables "restartable mode." When this option is used, Robocopy writes a special marker within the destination file during the copy process. If the copy operation is interrupted—due to a network disconnection, power outage, or system crash—Robocopy can later detect this marker and resume the transfer from the point of interruption, rather than starting the entire file copy from scratch. This significantly saves time and bandwidth, especially for very large files or transfers over unstable networks.

flowchart TD
    A[Start Robocopy with /Z] --> B{File Copy Begins}
    B --> C{Data Written to Destination}
    C --> D{Restart Marker Updated}
    D --> E{Transfer Complete?}
    E -- No --> C
    E -- Yes --> F[End Robocopy]
    C -- Interruption --> G[Robocopy Restarted]
    G --> H{Detect Restart Marker}
    H -- Yes --> I[Resume Copy from Marker]
    H -- No --> B

Flowchart illustrating Robocopy's restartable copy process with the /Z option.

How /Z Works: Sparse Files and Checkpoints

When Robocopy copies a file with /Z, it essentially creates a sparse file on the destination. A sparse file is a type of computer file that attempts to use file system space more efficiently when the file is mostly empty. Robocopy then fills in the data. As it writes data, it periodically updates a special marker (often referred to as a 'restart marker' or 'checkpoint') within the destination file itself. This marker indicates how much of the file has been successfully transferred. If the transfer fails, Robocopy can read this marker upon restart and begin copying from the byte offset indicated by the marker, appending new data rather than overwriting existing, already-copied data.

Practical Usage and Considerations

Using the /Z option is straightforward: simply include it in your Robocopy command. It's particularly useful for large backups, migrating data over WAN links, or any scenario where transfer stability is a concern. However, be aware that the process of writing restart markers can introduce a slight overhead, making transfers marginally slower than without /Z for very small files or extremely stable local connections. For most practical purposes involving large files, the benefits of restartability far outweigh this minor overhead.

robocopy C:\SourceFolder D:\DestinationFolder /Z /E /R:5 /W:5

Example Robocopy command using the /Z option.

In the example above:

  • C:\SourceFolder is the source directory.
  • D:\DestinationFolder is the destination directory.
  • /Z enables restartable mode.
  • /E copies subdirectories, including empty ones.
  • /R:5 retries failed copies 5 times.
  • /W:5 waits 5 seconds between retries.