\\ Amazon パソコン・周辺機器 クーポンをチェックしよう!! //

How to Use the robocopy Command | Fast and Reliable File Copy in Windows

The robocopy command (Robust File Copy) is a powerful utility in Windows that allows for fast and reliable copying or moving of files and directories. Unlike the basic copy or xcopy commands, robocopy includes error handling and retry capabilities, making it ideal for network transfers and large-scale backups where reliability is critical.

目次

What is the robocopy Command?

robocopy (Robust File Copy) is a command-line utility in Windows designed for copying and moving files or directories with advanced features. It supports network file transfers, directory mirroring, and can resume interrupted copies, making it a go-to tool for backup and synchronization tasks.

Key Uses of the robocopy Command

  • File and Folder Backup: Ideal for synchronizing directories or performing differential backups.
  • Network File Transfers: Efficiently copy files across networks, with the ability to resume if interrupted.
  • Directory Mirroring: Create an exact copy of a source directory, including all subdirectories and files.

How to Use the robocopy Command

The robocopy command requires you to specify the source and destination directories. You can also apply various options to control how the copy operation is performed.

Basic Syntax

robocopy <source> <destination> [<file>] [<options>]
ParameterDescription
<source>Path to the source directory.
<destination>Path to the destination directory.
<file>(Optional) Specify the file(s) to copy. If omitted, defaults to *.*.
<options>Options to control the copy process (see below).

Key Options

OptionDescription
/sCopies subdirectories, but excludes empty ones.
/eCopies all subdirectories, including empty ones.
/mirMirrors the source and destination directories. Deletes files not present in the source.
/zEnables restartable mode, allowing copies to resume if interrupted.
/bRuns in backup mode to copy files.
/copyallCopies all file attributes (data, attributes, timestamps, ACLs, owner, etc.).
/secCopies security information (ACLs).
/purgeDeletes destination files that no longer exist in the source.
/movMoves files by copying and deleting from the source.
/mt[:n]Enables multi-threaded copying (default is 8 threads). Specify n for custom threads.
/log:<file>Creates a log file of the copy operation.

Examples

  1. Basic Directory Copy
   robocopy C:\SourceFolder C:\DestinationFolder

Explanation: Copies all files from C:\SourceFolder to C:\DestinationFolder. Subdirectories are not copied by default.

  1. Copy with Subdirectories
   robocopy C:\SourceFolder C:\DestinationFolder /e

Explanation: Copies all files and subdirectories, including empty directories, from C:\SourceFolder to C:\DestinationFolder.

  1. Restartable Network Copy
   robocopy C:\SourceFolder C:\DestinationFolder /z

Explanation: Copies files with the ability to resume if interrupted (useful for network transfers).

  1. Directory Mirroring
   robocopy C:\SourceFolder C:\DestinationFolder /mir

Explanation: Mirrors C:\SourceFolder to C:\DestinationFolder. Deletes any files in the destination that are not in the source.

  1. Copy with Security Information
   robocopy C:\SourceFolder C:\DestinationFolder /sec

Explanation: Copies files along with their security information (ACLs).

Use Cases for the robocopy Command

  • Large-scale Backups: Useful for copying large datasets across servers or for creating backups. The tool’s error handling and retry mechanism ensure reliable transfers.
  • File Synchronization: Keeps files in two directories synchronized, ensuring that the destination directory always matches the source.
  • Directory Mirroring: Ideal for server backup or restoration processes where exact replicas of directories are required.

Tips and Precautions When Using the robocopy Command

  • Be Cautious with /mir: The /mir option deletes files in the destination that no longer exist in the source, so use it carefully to avoid accidental data loss.
  • Monitor Network Load: For large file transfers over networks, be aware of potential network congestion. Consider using the /ipg option to introduce delays between packets and reduce the impact on the network.
  • Log Your Operations: Use the /log option to create a detailed log file of your robocopy operations, helpful for tracking errors or reviewing actions later.

Conclusion

The robocopy command is a powerful and reliable tool for copying or moving files and directories in Windows. Its advanced features, such as restartable copying, directory mirroring, and security attribute preservation, make it ideal for both small and large-scale operations. Whether you’re performing backups, synchronizing files, or transferring data over a network, robocopy can streamline the process with its extensive options.

Tamaglo

Thank you for reading!

Comments

To comment

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here

目次