次の方法で共有


robocopy

ある場所から別の場所にファイル データをコピーします。

Syntax

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

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

Important

If any data is copied from the root of a device, the destination directory adopts the "hidden" and "system" attributes during the copy process.

Parameters

Parameter Description
<source> コピー元ディレクトリのパスを指定します。
<destination> コピー先ディレクトリのパスを指定します。
<file> ファイルをコピーするファイルを指定します。 Wildcard characters (* or ?) are supported. このパラメーターを指定しない場合は、既定値として *.* が使用されます。
<options> Specifies the options to use with the robocopy command, including copy, file, retry, logging, and job options.

Copy options

Option Description
/s Copies subdirectories. このオプションでは、空のディレクトリを自動的に除外します。
/e Copies subdirectories. このオプションでは、空のディレクトリ自動的に含めます。
/lev:<n> Copies only the top n levels of the source directory tree.
/z 再開可能モードでファイルをコピーします。 再起動可能モードでは、ファイルコピーが中断された場合、robocopy はファイル全体を再コピーするのではなく、中断した場所から再開できます。
/b バックアップ モードでファイルをコピーします。 バックアップ モードでは、robocopy によってファイルとフォルダーのアクセス許可設定 (ACL) がオーバーライドされ、それ以外の場合はアクセスがブロックされる可能性があります。
/zb 再開可能モードでファイルをコピーします。 ファイル アクセスが拒否された場合は、バックアップ モードに切り替えます。
/j バッファリングされない I/O を使用してコピーします (大きなファイルに推奨されます)。
/efsraw EFS の RAW モードでは、すべての暗号化されたファイルをコピーします。
/copy:<copyflags> コピーするファイルのプロパティを指定します。 このオプションの有効な値は次のとおりです。
  • D - Data
  • A - Attributes
  • T - Time stamps
  • X - Skip alt data streams
  • S - NTFS access control list (ACL)
  • O - Owner information
  • U - Auditing information
The default value for the /COPY option is DAT (data, attributes, and time stamps). The X flag is ignored if either /B or /ZB is used.
/dcopy:<copyflags> ディレクトリで何をコピーするかを指定します。 このオプションの有効な値は次のとおりです。
  • D - Data
  • A - Attributes
  • T - Time stamps
  • E - Extended attribute
  • X - Skip alt data streams
The default value for this option is DA (data and attributes).
/sec Copies files with security (equivalent to /copy:DATS).
/copyall Copies all file information (equivalent to /copy:DATSOU).
/nocopy Copies no file information (useful with /purge).
/secfix でも、すべてのファイルに修正プログラム ファイルのセキュリティには、ものがスキップされます。
/timfix でも、すべてのファイルに修正プログラム ファイルの時間には、ものがスキップされます。
/purge リンク先のファイルとソースに存在しなくなったディレクトリを削除します。 Using this option with the /e option and a destination directory, allows the destination directory security settings to not be overwritten.
/mir Mirrors a directory tree (equivalent to /e plus /purge). Using this option with the /e option and a destination directory, overwrites the destination directory security settings.
/mov ファイルを移動し、コピーした後に、ソースから削除します。
/move ファイルとディレクトリを移動し、コピーした後に、ソースから削除します。
/a+:[RASHCNET] コピーしたファイルに指定された属性を追加します。 このオプションの有効な値は次のとおりです。
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
/a-:[RASHCNETO] コピーしたファイルから、指定された属性を削除します。 このオプションの有効な値は次のとおりです。
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/create ディレクトリ ツリー、長さゼロのファイルのみを作成します。
/fat 8.3 形式の文字長 FAT ファイル名のみを使用して、リンク先のファイルを作成します。
/256 256 文字より長いパスのサポートを無効にします。
/mon:<n> Monitors the source and runs again when more than n changes are detected.
/mot:<m> Monitors the source and runs again in m minutes if changes are detected.
/rh:hhmm-hhmm 新しいコピーを開始できる実行時間を指定します。
/pf (パスごとではなく) ファイルごとに実行時間をチェックします。
/ipg:<n> 低速回線の帯域幅を解放する間のパケットの間隔を指定します。
/sj ジャンクション (ソフト リンク) をリンク ターゲットではなく宛先パスにコピーします。
/sl シンボリック リンクに従わず、代わりにリンクのコピーを作成します。
/mt:<n> Creates multi-threaded copies with n threads. n must be an integer between 1 and 128. The default value for n is 8. For better performance, redirect your output using /log option.

The /mt parameter can't be used with the /ipg and /efsraw parameters.

/nodcopy Copies no directory info (the default /dcopy:DA is done).
/nooffload Windows コピー オフロード メカニズムを使用せずにファイルをコピーします。
/compress ファイル転送中のネットワーク圧縮を要求します (該当する場合)。
/sparse:<y|n> コピー処理中におけるファイルのスパース状態の保持を有効または無効にします。 If no option is selected, it defaults to yes (enabled).
/noclone 最適化としてのブロック複製を試行しません。

Important

When using the /secfix copy option, specify the type of security information you want to copy, using one of these additional copy options:

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

Note

The /mt parameter was introduced in Windows Server 2008 R2 and its functionality applies to current versions of Windows Server.

ファイルの調整オプションをコピーします

Option Description
/iomaxsize:<n>[kmg] The requested max i/o size per read/write cycle in nkilobytes, megabytes, or gigabytes.
/iorate:<n>[kmg] The requested i/o rate in nkilobytes megabytes, or gigabytes per second.
/threshold:<n>[kmg] The file size threshold for throttling in nkilobytes, megabytes, or gigabytes (see Remarks).

これらの調整オプションは、Robocopy で使用できる最大の I/O 帯域幅を 1 秒あたりのバイト数で指定するために使用されます。 If not specifying in bytes per second, whole numbers can be used if k, m, or g are specified. The minimum I/O bandwidth that is throttled is 524288 bytes even if a lesser value is specified.

ファイルの選択オプション

Option Description
/a Copies only files for which the Archive attribute is set.
/m Copies only files for which the Archive attribute is set, and resets the Archive attribute.
/ia:[RASHCNETO] 指定した属性のいずれかが設定する対象のファイルのみが含まれます。 このオプションの有効な値は次のとおりです。
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/xa:[RASHCNETO] 指定した属性のいずれかが設定する対象のファイルを除外します。 このオプションの有効な値は次のとおりです。
  • R - Read only
  • A - Archive
  • S - System
  • H - Hidden
  • C - Compressed
  • N - Not content indexed
  • E - Encrypted
  • T - Temporary
  • O - Offline
/xf <filename>[ ...] 指定した名前またはパスに一致するファイルを除外します。 Wildcard characters (* and ?) are supported.
/xd <directory>[ ...] 指定した名前とパスに一致するディレクトリを除外します。
/xc タイムスタンプは同じであるが、ファイル サイズが異なる既存のファイルを除外します。
/xn 宛先より新しいソース ディレクトリ ファイルが、コピーから除外されます。
/xo 宛先より古いソース ディレクトリ ファイルが、コピーから除外されます。
/xx 宛先に存在するが、ソースには存在しない追加のファイルとディレクトリを除外します。 追加のファイルを除外しても、コピー先からファイルは削除されません。
/xl ソースに存在するが、宛先には存在しない "孤立した" ファイルとディレクトリを除外します。 孤立したファイルを除外すると、すべての新しいファイルが宛先に追加されなくなります。
/im 変更されたファイル (変更時刻は異なります) を含めます。
/is 同じファイルを含めます。 同じファイルは、名前、サイズ、時刻、すべての属性が同じです。
/it ファイル「調整」にはが含まれます。 調整されたファイルは、名前、サイズ、時刻は同じですが、属性が異なります。
/max:<n> Specifies the maximum file size (to exclude files bigger than n bytes).
/min:<n> Specifies the minimum file size (to exclude files smaller than n bytes).
/maxage:<n> Specifies the maximum file age to exclude files older than n days or a date based on when the files were last modified.
/minage:<n> Specifies the minimum file age to exclude files newer than n days or a date based on when the files were last modified.
/maxlad:<n> Specifies the maximum last access date (excludes files unused since n).
/minlad:<n> Specifies the minimum last access date (excludes files used since n) If n is less than 1900, n specifies the number of days. Otherwise, n specifies a date in the format YYYYMMDD.
/xj 通常は既定で含まの接合ポイントは含まれません。
/fft FAT ファイル時間 (2 秒の精度) を想定します。
/dst 1 時間 DST 時刻の違いを補正します。
/xjd ディレクトリの接合ポイントは含まれません。
/xjf ファイルの接合ポイントは含まれません。

Retry options

Option Description
/r:<n> 失敗したコピーの再試行回数を指定します。 The default value of n is 1,000,000 (one million retries).
/w:<n> 再試行間の待ち時間 (秒) を指定します。 The default value of n is 30 (wait time 30 seconds).
/reg Saves the values specified in the /r and /w options as default settings in the registry.
/tbd 共有名が定義されるのをシステムが待機することを示します (再試行エラー 67)。
/lfsm Operate in low free space mode that enables copy, pause, and resume (see Remarks).
/lfsm:<n>[kmg] Specifies the floor size in nkilobytes, megabytes, or gigabytes.

Logging options

Option Description
/l ファイルのみリストに表示されることを指定 (およびコピーされず、削除、またはタイムスタンプ) です。
/x 選択されているものだけでなく、すべての余分なファイルを報告します。
/v 詳細出力を生成し、すべてのスキップしたファイルを示します。
/ts 出力には、ソース ファイルのタイムスタンプが含まれています。
/fp 出力にはファイルの完全パス名が含まれます。
/bytes バイトとして、サイズを印刷します。
/ns ファイル サイズをログに記録しないことを指定します。
/nc ファイル クラスをログに記録しないことを指定します。
/nfl ファイル名をログに記録しないことを指定します。
/ndl ディレクトリ名をログに記録しないことを指定します。
/np コピー操作の進行状況 (これまでにコピーしたファイルまたはディレクトリの数) を表示しないように指定します。
/eta コピーしたファイルの到着 (予定) の推定時間を示します。
/log:<logfile> 状態出力をログ ファイルに書き込みます (既存のログ ファイルを上書きします)。
/log+:<logfile> 状態の出力を (既存のログ ファイルに出力を追加する)、ログ ファイルに書き込みます。
/unilog:<logfile> (既存のログ ファイルを上書きする) の Unicode 文字としてログ ファイルに状態の出力を書き込みます。
/unilog+:<logfile> (出力を既存のログ ファイルに追加する) の Unicode 文字としてログ ファイルに出力のステータスを書き込みます。
/tee 状態の出力をコンソール ウィンドウ、およびログ ファイルに書き込みます。
/njh ジョブのヘッダーがないことを示します。
/njs ジョブの概要がないことを示します。
/unicode Unicode テキストとして状態の出力を表示します。

Job options

Option Description
/job:<jobname> パラメーターをジョブの名前付きのファイルから派生するように指定します。 /job:jobname を実行するには、まず /save:jobname パラメーターを実行して、ジョブ ファイルを作成する必要があります。
/save:<jobname> パラメーターを名前付きのジョブのファイルに保存するように指定します。 これは、/job:jobname を実行する前に実行される必要があります。 コピー、再試行、ログ記録のオプションはすべて、このパラメーターの前に指定する必要があります。
/quit (パラメーターを表示する) のコマンドラインの処理の後に終了します。
/nosd ソース ディレクトリが指定されていないことを示します。
/nodd インストール先ディレクトリが指定されていないことを示します。
/if 指定したファイルが含まれます。

Remarks

  • Using /PURGE or /MIR on the root directory of the volume formerly caused robocopy to apply the requested operation on files inside the System Volume Information directory as well. どちらかが指定されているかのように、robocopy はコピー セッションの最上位のソースディレクトリとコピー先ディレクトリでその名前を持つファイルまたはディレクトリをスキップします。

  • 変更されたファイルの分類は、ソース ファイル システムとコピー先ファイル システムの両方が変更タイムスタンプ (NTFS など) をサポートしており、ソース ファイルとコピー先ファイルの変更時刻が異なるがそれ以外は同じである場合にのみ適用されます。 これらのファイルは、既定ではコピーされません。 Specify /IM to include them.

  • The /DCOPY:E flag requests that extended attribute copying should be attempted for directories. Robocopy は、ディレクトリの EA をコピーできなかった場合でも、コピー操作を続行します。 This flag isn't included in /COPYALL.

  • If either /IoMaxSize or /IoRate are specified, robocopy enables copy file throttling to reduce system load. どちらも最適な値とコピーパラメータに調整できますが、システムと robocopy では、必要に応じて許可された値に調整できます。

  • If /Threshold is used, it specifies a minimum file size for engaging throttling. そのサイズを下回るファイルは調整されません。 3つのパラメーターはすべて、値の後に、[KMG] (キロバイト、メガバイト、ギガバイト) など、オプションのサフィックスを付けることができます。

  • Using /LFSM requests robocopy to operate in 'low free space mode'. このモードでは、ファイル コピーによってコピー先ボリュームの空き領域が "floor" 値を下回るたびに robocopy が一時停止します。 This value can be explicitly specified using /LFSM:n[KMG] flag.

  • If /LFSM is specified with no explicit floor value, the floor is set to 10% of the destination volume's size. Low free space mode is incompatible with /MT and /EFSRAW.

終了 (リターン) コード

Value Description
0 ファイルはコピーされませんでした。 エラーは発生しませんでした。 一致しないファイルはありませんでした。 ファイルが宛先ディレクトリに既に存在するため、コピー操作はスキップされました。
1 すべてのファイルが正常にコピーされました。
2 ソース ディレクトリには存在しない追加のファイルが宛先ディレクトリにいくつか存在します。 ファイルはコピーされませんでした。
3 一部のファイルがコピーされました。 追加のファイルが存在しました。 エラーは発生しませんでした。
5 一部のファイルがコピーされました。 一部のファイルが一致しませんでした。 エラーは発生しませんでした。
6 追加のファイルと一致しないファイルが存在します。 ファイルがコピーされず、エラーも発生しなかったので、ファイルが既に宛先ディレクトリに存在していることを意味します。
7 ファイルがコピーされ、ファイルの不一致が存在し、さらに追加のファイルが存在しました。
8 複数のファイルがコピーされませんでした。

Note

Any value equal to or greater than 8 indicates that there was at least one failure during the copy operation.

Examples

robocopy コマンドを実行するときは、プロセスで整合性の検証が完了したら表示できるログ ファイルを作成することを強くお勧めします。 次の例では、それぞれ /LOG: パラメーターを使用します。 ログ情報を同じログ ファイルに追加するには、代わりに /LOG+: パラメーターを使用します。

空のディレクトリを含むすべてのファイルとサブディレクトリを "Records" フォルダーからドライブ "D" の "Backup" フォルダーにコピーするには、次のように入力します。

robocopy C:\Users\Admin\Records D:\Backup /E /ZB /LOG:C:\Logs\Backup.log

"Records" フォルダーの内容をドライブ "D" の "Backup" フォルダーにミラーリングするには、2 回の再試行を行い、各再試行の間に 5 秒間待機しているソースに存在しないファイルをすべて削除します。次のように入力します。

robocopy C:\Users\Admin\Records D:\Backup /MIR /R:2 /W:5 /LOG:C:\Logs\Backup.log

空ではないすべてのファイルとサブディレクトリを "Records" フォルダーからドライブ "D" の "Backup" フォルダーにコピーし、16 個のマルチスレッド コピー操作でファイル データ、属性、タイムスタンプを保持するには、次のように入力します。

robocopy C:\Users\Admin\Records D:\Backup /S /E /COPY:DAT /MT:16 /LOG:C:\Logs\Backup.log

空のディレクトリを除くファイルとサブディレクトリを "Records" フォルダーからドライブ "D" の "Backup" フォルダーに移動し、7 日より前のファイルを除外するには、次のように入力します。

robocopy C:\Users\Admin\Records D:\Backup /S /MAXAGE:7 /MOV /LOG:C:\Logs\Backup.log

空のディレクトリを含むすべてのファイルとサブディレクトリを "Records" フォルダーからドライブ "D" の "Backup" フォルダーにコピーし、各ファイルの推定時間を示し、ソースから存在しない宛先内のファイルとディレクトリをすべて削除するには、次のように入力します。

robocopy C:\Users\Admin\Records D:\Backup /ETA /PURGE /LOG:C:\Logs\Backup.log

コピー操作中に I/O レートを 1 MB/秒に制限しながら、"C" ドライブの "Records" という名前のフォルダーから "D" ドライブの "Backup" という名前のフォルダーにすべてのファイルとサブディレクトリをコピーするには、次のように入力します。

robocopy C:\Records D:\Backup /iorate:1m

ファイルが新しい、古い、または変更されているかどうかに関係なく、コピー先フォルダーにファイルが既に存在する場合に、ソース フォルダーからコピー先フォルダーへのファイルのコピーをスキップするには、次のように入力します。

robocopy C:\Source C:\Destination /XC /XN /XO