Go to list of users who liked
Share on X(Twitter)
Share on Facebook
Robocopy コマンド作成及び実行作業手順及びパラメーター、オプション、Tips、History. How to Make and Execute Robocopy with Option, Parameter, and so on
Robocopyの問題点
📁 RobocopyD2Ai
🎯 目的
Robocopyの実行において、環境・用途に応じた最適なオプション設計を体系的に行う。
🧱 基本構造とレイヤー階層
1. 問題点の認識
- バージョン依存(Windows 10 2004以降での改善あり)
- 公式ドキュメントの不完全性
- GUI世代との理解ギャップ
- サンプルやTipsが古いことによる実害
2. 構文レイヤー
| レベル | 内容 |
|---|---|
| L0 | GUIツール代替(基本) |
| L1 | オプション付きコピー |
| L2 | ログ・ミラー設定追加 |
| L3 | スケジューラ・スクリプト連携 |
| L4 | PowerShell統合+変数使用 |
⚙️ オプション一覧(抜粋)
| オプション | 説明 |
|---|---|
/E | 空ディレクトリ含む再帰コピー |
/Z | 中断可能なコピーモード |
/DCOPY:T | フォルダの時刻保持 |
/COPY:DAT | 権限/属性/時刻をコピー |
/R:3 | リトライ3回 |
/W:5 | リトライ間隔5秒 |
/LOG+:file.log | ログ追記 |
/MT:8 | 8スレッド並列実行(高負荷注意) |
🔁 実行パターン
📂 通常バックアップ
Robocopy"D:\DATA""E:\Backup"/E/COPY:DAT/DCOPY:T/R:3/W:5/LOG+:backup.log/TEE```💻PowerShell経由```powershell$src="$env:USERPROFILE\Documents"$dst="D:\UserBackup"robocopy$src$dst/E/COPY:DAT/DCOPY:T/LOG+:log.txt🧠 語呂合わせ & Tips
/E → Everything
/Z → Zzz(中断OK)
/MT → マルチタスク
🕘 バージョンヒストリー
| 年 | イベント |
|---|---|
| 2020 | /Compress オプション導入(Ver.2004) |
| 2022 | PowerShell連携構文が浸透 |
| 2025 | D2Ai構文化構文として整理 |
📎 参考リンク
Qiita: Robocopy導入記事
アメリカにも本音と建前がある
RobocopyはもちろんRobocopのようにRobotの如く堅牢で何があってもミラーリングする。
公式はRobust Copyと言っているが、それは建前でしかない。それならRobuCopyにしかならないのでおかしい。/ZBなどどうみてもゾンビでしかない。いわゆる日本人でいう建前と本音であろう。
記事が削除されて経緯がわからない
問題点としては、古くからある割に、公式のソースや、解説のブログも消えていることが多く、現在残っているものでは、オプションの追加や経緯がわかりにくくなっている。とくに/DCopyオプションは次第に機能が追加され、デフォルトの意味が変わっている。
Sampleがその時代のバージョンを反映しているため、Windows10では改善したほうがいい場合がある
上記とも関連するが、Sampleを検索するといろいろな目的のものがあるが、基本的にその書かれたときのRobocopyのバージョンである。このため、目的と違うと意図しない動作となるし、フォルダのタイムスタンプが移らないことが起きる。このため、ある程度オプションの知識をもち、サンプルを改善したほうがいい場合がある。
現在の公式の解説はすべて不完全である
公式の解説はWindows10ではなくサーバーのコマンドとして記述されている。
WindowsExplorerでのコピー、CMDラインrobocopy、CMDラインcopyのファイル属性の扱いの違いを教えてください 2020/02/16
sakuramoti 独立アドバイザー
こんにちは
Windows 10 での robocopy の仕様は下記になります。
https://docs.microsoft.com/ja-jp/windows-server/administration/windows-commands/robocopy
LTFS についてはそのバージョンでの違いもあるでしょう。
と言っっているが、/BYTEオプションログファイルを作成するときに必ずByte単位でサイズを記録することを強制するオプションは上記
Docs Windows Server Windows コマンド サーバーの役割別のコマンド robocopy 2020/06/07のWindows Serverのヘルプには出てくるが、Windows 10のコマンドプロンプトのROBOCOPYのヘルプにはない。
どういった手順でRobocopyコマンドのオプションを組み立てて実行するのか
また、そもそも根本的に、どういう手順でRobocopyを作っていき、実行すればいいのかが分かりづらい。オプションの数も多く、最初はなにをしていいのかわからない。公式の解説はミラーしかないが、通常のROBOCOPYは/CopyAll /DCopy:DATが安全であるしそこから始めたほうがよい。また/Lや/QUITでプレビューやジョブファイルを作ることもあまり知られていない。
レベルを設定して理解していく
近年はWindows Subsystem for LinuxのRsyncからRobocopyに来ることもあるだろう。Robocopyもまた枯れた技術になりつつある。
とはいうものの、Windowsから入ることを前提とすると、難易度は以下のようなレベルレイヤーになると思われる。下に行くほど難しい。最後はRobocopyすら使っていないが。
WSL対応 rsyncでリモートバックアップや世代管理するPowerShellスクリプト
robocopyがシンボリックリンクに捕まってしまってうまく動いてくれない→/XJDオプションでうまくいった - Mar 09, 2009
2020年1月7日追記。ここから10年が経過した現在は、Windowsのバッチファイルを使わずにrsyncを使っています。重要なのは以下の2点です。
- QNAPのNASを導入(GUIを使わずSSH接続できる)
- Windows 10でWSLを使ってrsyncで /mnt/c/ 配下の任意のディレクトリをQNAPに同期する
Robocopyのレベルレイヤー
Robocopyのデフォルトはヘルプではミラー(リング)とされている。
しかし、ミラーリングは不用意な削除を引き起こす可能性がある。(と、マイクロソフト自身がかつて言っていました)
なので、ミラーリングは次のレベルで最初は/DCopy:DAT /Copy:DAT/DCopy:DAT /CopyAllから始めるべきだろう。
管理者権限がないと/CopyALLは失敗する。このため管理者権限がなくても始められる/DCopy:DAT /Copy:DATから試行して、これが稼働できるようになってから/MIRに移行すること。
- [RobocopyのTips](https://qiita.com/fmfm29/items/23ed492c906194c300c1)の安全にコピーするの項目を理解する。また /R:3 /W:30の意味を理解する。最後に`/L`をつけて確認後、`/L`を外して実行する。
- Cmdを起動し、`Robocopy /?`でヘルプを表示する。このとき、ヘルプが英語だったり、最初にXP010と記載してあれば注意。とりあえずC:\Windows\System32/Robocopy.exe と記述する。
- フォルダの複写 `/DCopy:DAT`オプション付き
- フォルダの複写 Log+を付けて複写(以下はすべてLog+はつく)
- ファイルを指定して複写
- ディレクトリのみ複写
- ドライブの複写
- セキュリティの複写(修正)
- ミラーリング
- Purgeオプション
- ファイル選択、ファイルクラス、リトライ、ログなどのジャンルごとオプションがあることを理解する。
- ネットワークドライブの複写
- ネットワークドライブで権限をつけて複写
- cmdとPowershellを使い分ける
- Copy,XCopyをつかいわける
- ジョブファイル(rcj),bat,vbs,psのようなスクリプトから実行
- タスクスケジューラで自動化
- 帯域制限と高速化
- Rsyncを使い始める
ROBOCOPYオプション概要
Robocopyは豊富なオプションがある。これはネットワークサーバー管理者のコマンドだからである。
このコマンドの意味や、組み合わせについて知る必要がある。
次にRObocopyにはバージョンの違いがあり、オプションの違いがある。
これらを知るにはまず以下のリンクを知っておくべきであろう。
RobocopyのTips
Robocopyに入る前にフォルダオプションの設定などに注意。
https://web.archive.org/web/20171113170346/http://yarcgui.wilkes.es/De/RoboCopy/
ドイツ語で削除されているが、バージョンごとにオプションが変わっている点についてまとまっており、このバージョンによる違いまで入っている一覧があるこのページが最強ではないか。デザインとしても見やすいと思ういい感じだと思うが、どうだろうか。
古いRobocopyにDCOPYのTオプションがない yanor.net/wiki
XP010はWindoes Server 2003 resoruce KitにXP010版が入っており、このトラブルを体感できる。なお、/DCopyそのものがない。/Dcopy:Tは削除されたWindows Server 2008のRobocopyに記載されている。また、2013年のヘルプも/Dcopy:Tと記述されている
[Robocopy (Robust File Copy for Windows) - DOS コマンド一覧](https://www.pg-fl.jp/program/dos/doscmd/robocopy.htm)
こちらもバージョンごとのオプションの違いを記載されている。日本語では最強か。オプションごとの組み合わせや/Saveオプションの位置についても記載がある。
Robocopyでフォルダをコピー
ファイルクラス Lonely Sameなどの解説が詳しい
Robocopyの基本動作とコマンドオプション解説
n-archives.netはRobocopynoGUI版RoboSyncを開発、公開されている。この基本動作の解析はすごい
上記の定義を理解してもファイル・フォルダ コピー時のクラス分類とコピー動作などさらなる挙動の違いがある。さすがにGUIを開発しているだけあってとても詳しい。
Robocopy インフラエンジニアになるまで 2012年3月28日水曜日
この記事はジョブファイルについての説明が詳しい。最初のジョブファイルの作り方がとても参考になる。
なお、/Saveオプションの前までしか保存されない。
/Compress Windows 10 バージョン2004
Xcopyでも使える。
圧縮してコピーすることで、回線の帯域の使用を抑える。
SMB Compression: Deflate your IO
「compress」オプションでデータのコピーを高速化する
この他にも/DCopyのオプションの追加、/MIRオプションにおける"System Volume Infomation"のスキップなど2013年から2020年までに2回は変わっている。
Robocopyのコマンドラインの作成及び実行手順
- ドライブの電源設定、フォルダオプションの確認を行う
- Robocopyのバージョンを確認
- コピー元(ソース)コピー先(Distination 転送先)とログファイル、ジョブファイルのフォルダがあるか、確認。既存のログファイル、ジョブファイルは上書きされる恐れがあるので、以前のファイルは名前を変更するなど、しておく。
- メモ帳を起動する
- メモ帳に、コピー元とコピー先を記入する。除外ファイル、フォルダ、モードなど、ジョブファイル、ログファイルの場所、ファイル名など、オプションに付け加える事項も書いておく。コマンドラインは必ずメモ帳に書いて、貼り付けて実行すること。このとき、改行を含まないように注意すること。怖い場合は、最初n`C:\windows\system32\robocopy.exe /L Srouce Destination` と`/L`オプションを先付けして書き始めること。(これでもエラーにならない)
- cmd.exeを「管理者権限」で起動する
※PowershellでもこのcmdからPowershellと入力すれば管理者権限のPowershellとなり、Cmdを入力するとコマンドプロンプトになる。 - コピー先のフォルダを作る。
- Cmd.exeは
cd、Powershellはslでコピー元をカレントフォルダにする - メモ帳に戻り、と記入する。改行は含めてはいけない。(メモ帳の右端を折り返すオプションは改行ではないため、つけてもよい)
C:\Windows\System32\Robocopy.exe /L /Log+:"C:\Robolog.log /NP /TS /Save:"C:\Robojob"/Quit"
たとえばEドライブのRoboというフォルダにコピーしたい場合にはそのフォルダ自体をmkDirで作成しておくこと。 - コピー元、コピー先を入力する。このままで誤作動するとミラーになるため、サンプルはあらかじめコピーモードにしてある `/Copy:DAT /DCopy:T` を付してある。
C:\Windows\System32\Robocopy.exe "D:\hogehoge" "G:\hogehoge" /DCopy:T /Copy:DAT /XD "$RECYCLE.BIN” /XD “System Volume Information” /Log+:"C:\Robolog.log" /L /Save:"C:\Robojob" /Quit
これをCmdの画面にコピペして、エラーが出ないか確認する。
存在しないフォルダを指定するとエラーになる。
コピーされるフォルダは必ず\から下である。表示されているフォルダ自体からコピーされない。上記のサンプルの場合、D:\hogehoge自体はコピーされずD:\hogehogeの下にあるファイル、フォルダからコピーされる。
また、ドライブごとコピーする場合はD:のように表記し、\は不要。d:\Windows\System32\Robocopy.exe D:\hogehoge G:\hogehoge /XD "Temporary Internet Files" /XD "System Volume Information" /XD "`$$RECYCLE.BIN" /L - 外付けドライブの場合は、`/XD "System Volume Information" /XD "$RECYCLE.BIN"`を指定。
- Robocopyに複写をさせるか、ミラーリングさせるかを決める。デフォルトはミラーなので、上記のサンプルではCopyにしているが、ミラーにする場合には書き換える。
`/CopyAll /DCopy:DAT``/Copy:DAT /DCopy:DAT``/MIR /Dcopy:DAT`
のいずれかを選択する。
新規購入したドライブはCreate
`/CopyAll /DCopy:DAT /Create`
`/Copy:DAT /DCopy:DAT /Create`
`/MIR /Create`
後述するようにミラーは削除したものを削除してしまう。なのでミラーと言うか同期というべきではないか。
PurgeやMoveはもとを削除してしまうため、理解していない場合は使うべきではない。
削除するなら、複写を確認後、Delや手動で削除するほうが安全。
また/CopyAllは権限で選べないときもある
その時はコピーできる分だけコピーする
また/Dcopy:DAT
のディレクトリのみコピーもある。 - 再試行回数と時間(Retry Option)の制限設定
USBの設定を忘れていた当方では外付けドライブをコピーするときはエラーが出ていた。
このためリトライ回数と、待ち秒数を制限していた。デフォルトの値が極端に大きく、この2つは必ず設定したほうが良い。
これって秒単位だったのか。。。
`/R:3 /W:10`
3回リトライ、1回失敗するごとに10秒待つ。
くらいは入れておいたほうが良いようだ。
ところでこれを入れないと無限ループに陥る理由はなぜだろう。というのが以下の記事だが、納得はできるが、このひとは一体何者だ!
"Windowsのバックアップはrobocopyが簡単便利で早い">ようやく本題ですが、Windowsには昔から、それこそWindows 2000の時代からrobocopyというツールがあります。OSに標準搭載されたのはXPからですが、2000の頃からMS社内では使われていました。
Microsoft社などのグローバル企業はアメリカにある本社と各国の支社との間で毎日最新のデータをミラーリングしなければならないため、堅牢性が高く信頼性のあるコピーコマンドが必要でした。
当時は海外の回線なんてめっちゃ細かったですからね…。ぼくと同年代のおっさんにわかりやすく言うと、モデム…は大袈裟にしてもISDNで通信しているようなレベルですよ。だから、普通のcopyコマンドやxcopyコマンドではタイムアウトされてしまって困るのです。
タイムアウトしても何度も再試行してほしいわけです。そうした社内事情もあって、作られたのがrobocopyなんですね。だからrobocopyはコピーが失敗しても30秒待機した後に再試行を繰り返す設定がデフォルトなのです。モデム、昔はアナログ回線と言って、電話は電線(銅)でつないでいました。そしてデータを送るときに音に変えて送っていました。平成生まれの人はFAXを見たことがある最後の世代でしょう。ぴーひゃららーというおと、あれで通信していたのです。
そして、この銅線で高速通信をしようとしました、これがISDN(Integrated Services Digital Network)です。/XDは複数ある場合には上記のようにその都度指定してよい
特に外付けドライブはSystem Volume Infomationと$RECYCLE.BINを除外する必要がある。 - 設定した仕様に応じて、新旧、容量、ファイル名による除外を付け加える。
- オプションを足してはコマンドラインにコピペして確認する。
- メモ帳をできればコピー元、転写先以外のドライブ、またはネットワークサーバー以外の場所に保存。(複写、ミラーリングを防ぐため)
- 最後に`/L`と`/QUIT`を外して実行開始
完成したサンプル(複写)
上記のながれでさらに/TEEとジャンクション、シンボリックリンクの除外を付け加えて完成。
まず最新のRobocopyで複写元、複写先、モード、リトライ回数、除外フォルダ、ログファイル、とそれに関するオプション、ジャンクションやシンボリックリンクの除外、ジョブファイルの保存という流れになっている。
このようにしてCMDの画面にコピペしてEnterで実行し、エラーがなければ、/Lを消してコピペし、実行となる。/Saveオプションでジョブファイルを作成している場合には/QUITもはずす。
C:\Windows\System32\Robocopy.exe"D:\hogehoge""G:\hogehoge"/DCopy:DAT/Copy:DAT/E /R:3/W:10/XD"$RECYCLE.BIN” /XD “System Volume Information” /Log+:"C:\Robolog.log" /TEE /NP /TS /XJ /XJD /XJF /L /Save:"C:\Robojob" /Quit旧バージョンを含めた手順
パソコンのファイルをrobocopyで手堅くバックアップする方法
XPはWindows Server 2003 Resource Kitをどこからかダウンロードするといいと思われる。
Windowsのrobocopyコマンドでコピーするファイルの種類を選択/変更する
なおWindows XP/Windows Server 2003の場合、robocopyは付属していないのでリソースキットを入手してインストールする必要がある。入手方法についてはTIPS「Windows OS向けリソースキット・ツールを入手する」を参照していただきたい(ただしリソースキット版のrobocopyでは、本TIPSで紹介するオプションがすべて使えるわけではない)。(Version XP010のため
/J,/BYTE,/DCOPYが使えない。
ドライブ丸ごと(システムドライブ以外)
robocopyでドライブを丸ごとコピーするサンプル | Windows
これはシステムドライブを前提としているが、危険。また、ゴミ箱を除外する
ドライブごと(Powershell)
robocopyでドライブの内容を丸ごとコピーする方法
エスケープ文字。/XDが一括して記述しているのは絶対パスなら可能
ドライブ丸ごと(ユーザープロファイルというかシステムドライブ)
▼ユーザープロファイルのバックアップ用
robocopy C:\Users\xxxx D:\BackupData\xxxx /mir /R:1 /W:0 /LOG:robocopy.log /NP /TEE /XD "INetCache" /XD "Temporary Internet Files" /XD "%temp%" /XF "*.tmp" /XJD
※一般用に加え、各種テンポラリをコピーしないようにし、かつジャンクションフォルダを除外するようにしている(※無限ループ化を防ぐため)
最終処理
Robocopyの手順をまとめている過程で実行後の問題点が発生することがわかったので、確認手順をまとめる。
- ルートからコピーしている場合、コピー先のフォルダが隠し属性になっていないか。なっていたら解除する。
- セキュリティ権限が適切に複写されているか。(/ZB,/B)
- コピー元から必要なファイルが無くなっていないか、コピー先で必要なファイルがなくなっていないか。特に、ミラーリング`/MIR`、移動`/MOVE`/MOV`のときはファイルが削除されるので注意する。
- フォルダやファイルの日付はコピー元とコピー先で同じかいくつかファイルやフォルダを確認する。(/CopyALLは覚えていても/DCopy:DATは忘れがち)
- ログにエラーがないか。
- ログにエラーがある場合、下記のようにファイル総数と容量をカウントし、極端に差があれば、再度コピーし直す。
- エラーが頻発する場合、PC自体の電源設定、ハード自体、LANケーブルを点検する。
- 必要があれば、出力したログ・ファイル等を別の名前で、別の場所に保存する。
- 自分が使っているサーバーやシステム、状況に最適なオプションの組み合わせ、意味、注意点を記録する。
- 1年に1度はROBOCOPYのヘルプをだしてみて、なにか更新がないか確認する。
語呂合わせ
Robocopy 行く先円すらいらずファイルだと、開示モードは必須です。エヌピー記録はプラスでログってえええ、くすくすくす、フォルダ、ファイル、ジャンクション、パワーちょんドル、安全のために得るつけてセーブできっと出来上がり。
行く Source
先 Destination
フォルダの場合円(スラッシュ)はいらない
開示 リトライ回数 /R: 時間(秒) /W:10
モード /Copy:DAT /CopyALL /MIRのいずれかでRobocopyの挙動のモードを決定
ここまでは必須
です。
/TS ログファイルにタイムスタンプ
エヌピー記録はプラスでログってえええ
/NP /Log+:"C:\robocopylog.log"
プロセスは記録しない
追記型 ANSI
てええ え
/TEE ログと画面に表示
/E 空のサブフォルダもコピー
くすくすくす、フォルダ、ファイル、ジャンクション
/XD /XF /XDJ
無限ループを防ぐ、ジャンクションを除外
パワーちょんドル
"$RECYCLE.BIN" Powershellでロボコピーを実行する場合に、$RECYCLE.BINを除外指定するには"$RECYCLE.BIN"のようにエスケープが必須。
安全のために得るつけろ。
/Lを付けておき、正しく動くか確認
セーブできっと出来上がり
セーブは拡張子は付けない。またSaveの後ろは記録されない。しかし、Quitはそれより後ろを実行しないので、この順番になる。
ジョブファイルの拡張子はrcjで同名は上書きされる。
/Save:"C:\robojob" /Quit
Powershellからも実行できる
ほぼ同じ書き方で動く。通常はオプションはハイフンだが、Robocopyはスラッシュで良い。
また、Windows Server 2003 Resource Kitがインストールされていると、環境変数によって優先されるのも同様である。
しかし、若干違いがある。
いまのところ、ログファイルに環境変数を使用していると、Powershellではうまく展開されない。$RECYCLE.BINはPowershellの場合``/$RECYCLE.BINエスケープが必要。$がつくとPowershellでは変数となってしまう
Powershellの環境変数を使ったスクリプト
管理者権限で、起動したPowerhsellで、chcp 65001でうにコードのログを出力する。exeの部分は&を使う
chcp65001;&$env:SystemRoot\system32\robocopy.exe/L$env:Userprofile\documentsH:/UNILOG+:$env:userprofile\Documents\zoom\unirobolog.log/TEE/XD$env:userprofile\documents\zoom/XD'`$RECYCLE.BIN';ChCp932GUIで誰でも使えるRobocopyをPowerShellで実装する
これはPowershellでGUIを作っている点でもすごい。
相対パス表記の問題
batファイルの例
オプションが多い robocopy.exe で必要最小限覚えておけばよい書き方
ここで言われているように、同名のフォルダを設定していれば違和感がないが、同名のフォルダを設定していないと、その下からコピーしかしないところが間違う原因となる。また、相対パス表記が可能だが、必ずロボコピーをするときに、その上のフォルダに位置していなければならない。ここではバッチファイルを組むことでCDで移動させている。
UNIXの場合は移動先に同名のフォルダを作ってくれるという。そういう省略はRobocopyにはない。
ROBOCOPYの欠点ログファイルの文字コード
Robocopyのログ出力の文字コードについて調べてみた
Logしか確実ではないため、文字化けはやむを得ない。
しかし、後述する65001かませログリダイレクト方式で出せることがわかったが、こういうのを出力できるとは到底言えない。
USB外付けドライブのRobocopyは電源設定に注意
Windows10 USBセレクティブサスペンドを無効にする
Windows 10でUSB機器の電源が自動的に切れてしまう場合の対処方法
USBの外付けドライブは必ずこれを行い、変更したことを上記の手順のメモ帳に記録すること。
また、サーバーでも電源が不安定でUPSが壊れている、ということは本当にあったので、空調、電源周りの点検もおろそかにはできない。
時間がかかり、物理的な負担がかかるため、ハード面でもROBOCOPYは確認が重要である。
差分バックアップの前提となるRobocopyの挙動
Robocopyの日付とは更新日時である
Windowsのrobocopyコマンドでコピーするファイルの種類を選択/変更する
robocopyのデフォルト設定では、ファイルの更新時刻やサイズに基づいてコピーするかしないかを決定しているが、オプションを指定することにより、ファイルの属性などに基づいて選択的にコピーさせることができる。本TIPSでは、そのためのオプションを紹介する。
Robocopyの差分に対するデフォルトの挙動
Windowsのrobocopyコマンドでコピーするファイルの種類を選択/変更する
デフォルトでは、robocopyは「Changed」「Newer」「Older」となっているファイルだけをコピーするようになっている。つまり、内容が変更されているか、コピー元の方が新しいか、逆にコピー元の方が古い(コピー先の方が新しい)ファイルだけをコピーする。
作成日時はCopyするとCopyした日付になることがよく知られている。
Robocopyは作成日付があてにならないことを知っているので、更新日時になる。
更新日時は DateLastModified(FilesystemObject)、LastWriteTime(PowerShell)と言語やDLLで呼び名が変わる。
これ以外の日付を基準とするのであれば、FilesystemObjectやPowershellを使ったほうが良い。
なお、Windowsのrobocopyコマンドでコピーするファイルの種類を選択/変更するの表は2013年の記事なので、その時点に存在していたファイルクラスのオプションについてはわかりやすい。しかし、2020年のRobocopyはこれ以外にもオプションがある。
/MIRには要注意
/MIRを使うと、削除したファイルは次にROBOCOPYでミラーを使うと削除されてしまう。
【技術系】robocopyでバックアップしてみる 日々是適当 2012.01.15
今回イチオシにしてるのは2番目の「ミラーリング可能」という点。
これは『コピー元とコピー先の構成を全て同じ状態にする』というものです。
コピー元に追加されているデータがコピー先に追加されるのはもちろん、
コピー元から削除されたデータはコピー先からも削除されるというものです。
これによって前述の「不要になったデータが削除されていること」がクリアできます。
たしかに技術としてはこの発想は頷ける。しかしCopyという言葉の異イメージからは、削除したファイルを削除したくない場合。例えば外付けドライブの容量がなくなり、より容量の大きなドライブにバックアップして、削除して容量をあけるような場合は、次にMirを使うと削除されてしまうというネガティブな捉え方になる。
ここは、MIRの性質を理解して、慣れるまで本番では使わない方が良い。
【技術系】robocopyでバックアップしてみる日々是雑記
なおコマンドは必ず一行でまとめてください。
途中で改行がないように注意してください。
最悪の場合、重要なデータを失う可能性があります。
Notepad(メモ帳)で記入するとき要注意である。ミラーリング/MIRの注意点についても丁寧で、ミラーリングの問題点を理解にするにあたって参照すべきであろう。
/MOVEの挙動
Windows10で「robocopy /move がスキップ(フォルダが移動しない)」原因と対処法/E(Q11Q推奨)または/Sが確実に必要
なぜなら、Robocopyは指定したフォルダ下の階層しかコピー、ムーヴ、パージ、ミラーしない。
というか/MIR 自体が/Eと/PURGEの組み合わせたものだから。フォルダを移動させるには必ず指定が必要。
なお、Cドライブを前提にしたこのサンプルは危ない。
Cドライブを前提にすると、Documentsフォルダをコピーするため。
ジャンクションを除かなければ無限コピーになりかねない。ROBOCOPY “C:TEST_1” “C:TEST_2” /MOVE
この記事のサンプルは以下のようなバッチファイルを組むべきだろう。
ろう。
REM 管理者権限で起動することREM このBatファイルは以下のフォルダの階層以外のフォルダに置くこと。REM source CドライブのTEST_1 C:\TEST_1REM Destiny CドライブのTEST_2 C:\TEST_2REM /MOVE 移動モードREM リトライは1回、10秒後、/E 空のフォルダもコピー /DCOPY フォルダの日付もコピーREM ANSI 追記型ログファイルをC:\直下ROBolog.logを作成 /TEE /NPREM ジャンクションを除外REM ジョブファイルをC:\直下 ROBOJOB.RCJを作成REM エラーがなく正しく作動するのを確認後、/Lと/QUITを外してバッチファイルを実行するCD/DC:CD\C:\Windows\System32\ROBOCOPY.exeTEST_1TEST_2/MOVE /E /R:1/W:10/DCoopy:DAT/XDJ /XJ /LOG+:"C:\Robolog.log"/TEE /NP /L /SAVE:"C:\ROBOJOB"/L /QUIT/Moveと/Movの違い
Movはファイルのみ移動。
このため、/MOVEと違い/Eや/Sがなくても、Sourceフォルダ直下のファイルは移動する。
/Move はフォルダのみ。
/Jオプション
[Robocopy/Jオプションの長所と短所はありますか(バッファリングされないコピー)](https://www.it-swarm.jp.net/ja/windows/j-robocopy%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3%E3%81%AE%E9%95%B7%E6%89%80%E3%81%A8%E7%9F%AD%E6%89%80%E3%81%AF%E3%81%82%E3%82%8A%E3%81%BE%E3%81%99%E3%81%8B%EF%BC%88%E3%83%90%E3%83%83%E3%83%95%E3%82%A1%E3%83%AA%E3%83%B3%E3%82%B0%E3%81%95%E3%82%8C%E3%81%AA%E3%81%84%E3%82%B3%E3%83%94%E3%83%BC%EF%BC%89/944831975/)
Robocopyで/Jオプションがデフォルトで有効になっていない理由はバージョンによって/Jオプションが存在していない場合があるからでしょう。しかし/Jオプションの解説としては詳細。なぜ、必ず有効ではないのかも詳しく記載。
バッファなしI/Oは、ソースの場所から宛先の場所への単純なファイルコピーです。バッファI/Oは、仮想メモリの領域である filesystem cache にファイルをコピーすることにより、同じファイルの将来の読み取り(および書き込み)を最適化するために単純なコピーを拡張します。バッファリングされたI/Oは、メモリにファイルをコピーする必要があるため、最初にファイルにアクセスするときにパフォーマンスが低下します。ただし、メモリアクセスはディスクアクセスよりも高速であるため、その後のファイルアクセスも高速になります。オペレーティングシステムは、ディスクへのファイルの書き込みの同期を処理し、読み取りはメモリから直接プルできます。
初期費用は高くつきます。バッファードI/Oによるパフォーマンスの低下は、大きなファイルの場合は大幅に低下します。見返りはほとんどありません。比較的大きなメモリがない限り、大きなファイルブロックは非常に長い間キャッシュにとどまる傾向はありません。ファイルサイズ。ディスクI/Oを回避できない場合があります。大きなファイルデータブロックの読み取りと書き込みを行うと、ディスクI/Oが必要になる可能性が高くなります。おそらくとにかくバッファリングする必要はありません。大きなファイルは、小さなファイルよりも実際にアクセスされる頻度が低くなる傾向があります。したがって、トレードオフがありますが、どちらが適切かは、特定のケースによって異なります。大量のファイルを圧縮して、Zipをバックアップターゲットに送信する場合は、バッファなしの方法が適しています。変更されたばかりの一連のファイルをコピーしていますか?バッファリングされた方が速いはずです。使用上の注意では、バッファI/Oに対して大きなファイルについて言及しています。
最後に、ファイルサイズは、バッファリングと非バッファリングを決定する唯一の要素ではないことに注意してください。
Dcopyの問題
Robocopyでコピー先フォルダが非表示になる
robocopy後のコピー先フォルダが隠しフォルダになってしまう
ドライブレターに割り当てられたサーバーを知るにはNET USE
CMD前提\\SERVER001\unc\
で\\SERVER001\unc\Z:\
に割り当てられた状態
NET USE サーバーに割り当てられたドライブレター
NET USE Z:
スラッシュはつけない
これでUNC表記を知ることができる。(管理者にブロックされて見えない場合もあります)
サーバーのUNCは大文字小文字を含め、正確に記述する
ローカルからサーバーにコピーするときは正確にUNCを表記する。
大文字や小文字も正確に
ローカルのルートドライブのファイルをサーバーにバックアップすると、そのフォルダが隠し属性になる
NTSFは仕様でルートディレクトリが隠し属性になっているため、ルートのファイルをROBOCOPYでCOpyすると属性までCopyされるのが原因らしい。
このような場合、コピー先のサーバーのフォルダが(およびその上くらい?)は隠し属性になる。Z:\DriveにROBOCOPYで転送すると、Driveは隠し属性になる。
これを解除するには
コピー後、attrib -H -S <コピー先フォルダ>
とする必要がある。
つまり、日付は犠牲になるがドライブのルートからファイルだけをコピーする場合はXCOPYが安全。
フォルダやドライブごとなら起きない。
セキュリティ設定の複写
Robocopyでセキュリティ情報を正しくコピーする方法と注意点
NAS上のフォルダをセキュリティ設定ごと複製
/NoDcopyオプション
このオプションは高速化などに取り上げられているが、例えばファイルだけをコピーする状況において、
C:\WINDOWS\system32>c:\windows\system32\robocopy.exe g:\backup2\testdir1 g:\BackUp2\testdir2 t.txt
-------------------------------------------------------------------------------ROBOCOPY ::Windows の堅牢性の高いファイル コピー------------------------------------------------------------------------------- 開始: コピー元 :g:\backup2\testdir1\ コピー先 :g:\BackUp2\testdir2\ ファイル:t.txt オプション:/DCOPY:DA/COPY:DAT/R:1000000/W:30単純にミラーリングするだけでも自動的に/DCOPY:DAがついている。これが管理者権限がない場合、Robocopyは動作しないことがある。
こんなファイル一つだけの場合にはRobocopy の/Dcopyオプションが付与されるのを防ぐために/NODCOPYが必要になる。
/NODCOPY:: ディレクトリ情報をコピーしません(既定では/DCOPY:DA が実行されます)。XP010時代はこの/DCOPYがなく、/NODCOPY状態だといえる。このため、このオプションを追加すると、ある程度のその動きが復元できてしまうが、逆に言うと現在では書いていなくても/DCOPY:DAが効いてしまうため、古いサンプルをネットで検索して用いるときはいつ頃のものか、確認が必要である。でないとファイルをコピーするだけなら/NODCOPY /Copy:DATでなければならない場合があるからだ。
なお、この/DCOPY:DAは/MIR、/Purge、/COPY:DAT、/MOVE、/MOVのときは自動的に付与され、`/CopyALL`のときはつかない。しかし/Copy:DATのときは自動的に付与される。これは明らかにサーバー管理者権限がないものがファイルをサーバーのフォルダの中でROBOCOPYでコピーしようとすると、必要があるときはエラーが生じるようになっている。文章ではわかりにくいと思うが、権限がない人間がうかつにROBOCOPYを使いフォルダの属性が変わらないようになっている。なので、/Lオプションで確認する必要がある。
/Bオプションについて
robocopyのバックアップモードとは?管理者権限はいらないの?
【robocopy /B】で『アクセスが拒否されました』と表示される場合の対処
エラーコード、ログファイルの見方
【ROBOCOPY】ログの見方や表示の説明!失敗やEXTRAなど
【robocopy】のログの見方、エラーコード一覧〜不一致、EXTRAS〜 SEの道標
上記記事によると、RobocopyのエラーはWin32のものとのこと。
Win32 Error Codes
シンボリックリンク
シンボリックリンクの作成
シンボリックリンクとジャンクションは大体一組で覚えておくと良い。
互換性のためなどに設けられている実態のないファイルやフォルダで、ショートカットに近い。いわば虚像である。
例えば古いプログラムで、My Documentsと記載していてもDocumentsにつながる効果がある。
これは複写する上では排除すべきだし、ミラーリングならこれを虚像のまま反映させるか、虚像の実態を反映させるか。
MKLINK コマンド
シンボリックリンクはWindows Vista以降、mklinkで作成できる
NTSFフォーマットのディスクで使用できるが、FAT/FAT32でフォーマットされていると使用できない。
MKLINK[[/D]|[/H]|[/J]]<linkName><Target>/D` ディレクトリのシンボリック リンクを作成します。既定では、ファイルのシンボリック リンクが作成されます。/H シンボリック リンクではなく、ハード リンクを作成します。/J ディレクトリ ジャンクションを作成します。/Link 新しいシンボリック リンク名を指定します。/Target 新しいリンクが参照するパス (相対または絶対)を指定します。シンボリックリンクとジャンクションの実物をDirでみることができる
SymbolikLinkとJunctionの表示を見たいときには管理者権限でcmd.exeを起動しCD\ && CD C:\users && Dir /A /P
で見ることができます。
Windowsのシンボリックリンクとジャンクションとハードリンクの違い atmarkIT
Windows OSで利用できるリンクには、シンボリック・リンクやジャンクション、ハードリンクなどがある。これらは機能が少しずつ異なるので、使い分ける必要がある。それらの違いを解説する。
2013年06月07日 17時13分 公開
シンボリックリンクの使い方と落とし穴
上記2つが大体の概要を把握するのに有用。
ジャンクションやシンボリックリンクを除外しない場合
robocopyでドライブを丸ごとコピーするときの注意点 | Windows 2020.02.06
まず、とてつもなく長いファイルが作られてしまう(無限ループ)
無限に長いファイル名のため、Robocopyが失敗してエラーになり、無限回のリトライを繰り返して終わらない。
この点でも、/R /Wのretryのオプションを設定する必要がある。
WindowVista以降のrobocopyにおける無限ディレクトリの罠。
(前略)これが、Vista以降のディレクトリ構成変更で対応できないアプリのために規定で作成されているそう。
今回の例だと、
C:\Documents and Settings\All Users\Application Data\Application Data...
(1)"c:"は実体。
(2)"Documents and Settings"はジャンクションで、リンク先は"C:\Users"。
(3)"All Users"はジャンクションで、実体は"Public"。(これは確認できなかった。ジャンクションと違うのかな?)
(4)"Application Data"はジャンクションで、実体は"C:\ProgramData"。
(5)実体"C:\ProgramData"には、ジャンクション"Application Data"がある。
(6) (4)に戻る。
ということで無間地獄に陥っていた模様。
その間にあるファイルを何回も何回もバックアップしてくれた模様。対策1:バックアップデータが消せない対策。
はい。消せませんでした。バックアップデータ。
削除したら、Windwosさんが「パスが長すぎる」って。誰のせいでこんな事をしていると…!!
今回、バックアップ先が幸いNASだったので、ネットワークドライブを切って解決。
対策2:無間地獄対策。
robocopyでは、そのへんも考えてくれていたようで、オプション"/XJD"と"/XJF"を加えて解決できそう。
参考:Latest topics > robocopyがシンボリックリンクに捕まってしまってうまく動いてくれない→/XJDオプションでうまくいった - outsider reflex
…前の参考記事にもさりげなく書いてあったのねorz
まとめ
ジャンクションに気をつけよう!高速道路と同じだね!
/XCTオプションは/XC
Windows Server 2008の解説に/XCTというのが出てくる。また、海外でもそういう解説がある。
これは/XCに相当するようだ。/XCTで記述するとエラーになるため、/XCに書き換える。
除外オプションの挙動
ROBOCOPY の除外オプションの挙動を検証してみた。 人跡既踏 2017年9月22日金曜日
ROBOCOPYは、ファイルの更新判定を、メタ情報 (更新日時とファイルサイズ) だけで行っている。→ ファイルの中身は比較していない。
検証の結果分かったこと: 「/XC」の「Changed」(変更された/変更済み) というのは、
「ファイルサイズが変更されていて、更新日時が変更されていない」という意味だった。
このオプションを単独で使う状況が思いつかない。
まずこの更新日時が同じでファイルサイズが違うのは、外付けUSBドライブ同士をコピーするとき、勝手に電源が着れる場合にエラーで発生するサイズが0のファイルがある。これは異常なファイルのなので、ひとまず原因を確認するようなケースでは除外があると思われる。もしくは、改ざんされたファイルである。
コピー元だけに存在するファイルのみをコピーしたいとき (= 両方に存在するファイルは無視したいとき) には、「/XC /XN /XO」を指定すればよい。
除外オプションを試行錯誤するときには、あわせて「/V」オプションも指定しておくと捗る。
ROBOCOPYをコピー実行中に Ctrl+C で強制停止させた場合、コピー先にコピー途中の不完全なファイル(更新日付が1980年のファイル)が残るので、適宜手作業で取り除くこと。
たとえば、「/XN」というオプションの説明文として、
「/XN :: 新しいファイルを除外します。」
とあるが、このオプションでは 画面上で「新しいファイル」と表示されるファイルは除外されない。このオプションで実際に除外されるのは、画面上で「より新しい」と表示されるファイルである。
「新しいファイル」と表示されるファイルを除外するには、「/XL」を指定する必要がある。
先人の苦闘が忍ばれる。この記事は表を含め大変重要なので、リンク先で確認していただきたい。
/IFオプション
これはヘルプを読んでも意味がわからないが、ファイルを指定するRobocopyで複数のファイルを指定するとき使う。特に複数のファイルを使うときに使うC:\WINDOWS\system32>c:\windows\system32\robocopy.exe g:\backup2\testdir1 g:\BackUp2\testdir2 /if *.txt *.log /L
Robocopyの性質からすると、このオプションは、ファイルというより、複数の拡張子を絞り込んでrobocopyを用いる場合のオプションと言えるだろう。
Jobファイル(rcj形式)
最初の1行目は空白
CドライブをD:\Backupにコピー
レベル1
ファイルはワイルドカード
それでも/IFが現れる。/IFは記載がなくても現れる。また説明書きも現れる。
改行がCRLF文字コードがUTF-8?
今の新しいメモ帳の文字コード表示は信用ができない。ANSIで作成したほうが良い。
UTF-8だとどうなるかは、
https://www.pg-fl.jp/program/dos/doscmd/robocopy.htm#details_jobfile
ここにあった。Batと同様chcp 65001のあと使える。
ただし日本語のファイルがバグを起こす時があるようだ。
rcjファイルは同名のファイルは上書きされるらしい
重要なものは同名で出力して上書きされないように変更しておくこと。
下のサンプルはまとめているためいらないものがある
出現する順番を知るためにオプションを並べた面がある
もともとはC:\をD:\BackUpへ/CopyALlでログを作る。除外フォルダありという設定だ
なので以下の行は必要がなければ削除する必要がある。
/LEV:1:: only copy the top n LEVels of the source directory tree./PF:: check run hours on a Per File (not per pass) basis./CREATE:: CREATE directory tree and zero-length files only./PURGE:: delete dest files/dirs that no longer exist in source./MIR:: MIRror a directory tree (equivalent to /E plus /PURGE)./ZB:: use restartable mode; if access denied use Backup mode./XC:: eXclude Changed files./MAX:1000:: MAXimum file size - exclude files bigger than n bytes./NJH:: No Job Header./NJS:: No Job Summary./NS:: No Size - don't log file sizes./NC:: No Class - don't log file classes./NDL:: No Directory List - don't log directory names./NFL:: No File List - don't log file names./TS:: include source file Time Stamps in the output./FP:: include Full Pathname of files in the output.Jobファイル(rcj形式)サンプル
Options : *.* /FFT /256 /NS /NC /NDL /NFL /NJH /NJS /L /TEE /S /E /COPYALL /PURGE /MIR /CREATE /ZB /NP /IT /XC /XJ /MA X:1000 /MAXAGE:20210201 /LEV:1 /MON:5 /MOT:5 /PF /R:1 /W:0
これらに/Quit /Saveが加わっている
これで出力した結果が以下のようになる
:::: Robocopy Job C:\Hoge\ROBOTEST.RCJ:::: Created by username on Tue Feb 01 2021 at 19:55:58:::::: Source Directory :::/SD:C:\::SourceDirectory.:::: Destination Directory :::/DD:D:\Backup\::DestinationDirectory.:::: Include These Files :::/IF::IncludeFilesmatchingthesenames::*.*:: Include all names (currently - Command Line may override):::: Exclude These Directories :::/XD::eXcludeDirectoriesmatchingthesenamesINetCacheTemporaryInternetFilesSystemVolumeInformation$RECYCLE.BIN:::: Exclude These Files :::/XF::eXcludeFilesmatchingthesenames:::: eXclude no names (currently - Command Line may override)/XC::eXcludeChangedfiles./MAX:1000::MAXimumfilesize-excludefilesbiggerthannbytes.:: Copy options :::/S::copySubdirectories,butnotemptyones./E::copysubdirectories,includingEmptyones./LEV:1::onlycopythetopnLEVelsofthesourcedirectorytree./PF::checkrunhoursonaPerFile(notperpass)basis./COPYALL::COPYALLfileinfo(equivalentto/COPY:DATSOU)./CREATE::CREATEdirectorytreeandzero-lengthfilesonly./PURGE::deletedestfiles/dirsthatnolongerexistinsource./MIR::MIRroradirectorytree(equivalentto/Eplus/PURGE)./ZB::userestartablemode;ifaccessdenieduseBackupmode.:::: Retry Options :::/R:1::numberofRetriesonfailedcopies:default1million./W:0::Waittimebetweenretries:defaultis30seconds.:::: Logging Options :::/TS::includesourcefileTimeStampsintheoutput./FP::includeFullPathnameoffilesintheoutput./NS::NoSize-don't log file sizes./NC:: No Class - don'tlogfileclasses./NDL::NoDirectoryList-don't log directory names./NFL:: No File List - don'tlogfilenames./NJH::NoJobHeader./NJS::NoJobSummary./NP::NoProgress-don't display% copied./LOG+:C:\robocopy.log:: output status to LOG file (append to existing log)./TEE:: output to console window, as well as the log file.Option エラーメッセージ
Windows Server 2008 または Windows Server 2008 の Robocopy ユーティリティで使用されるリターン Windows Server 2008 R2
Robocopyのエラーコードの公式の解説
https://docs.microsoft.com/ja-jp/troubleshoot/windows-server/backup-and-storage/return-codes-used-robocopy-utility
0から8までしかない。
注意
8 より大きい値は、コピー操作中に少なくとも 1 つのエラーが発生したかどうかを示します。
詳細
Robocopy ユーティリティの使い方の詳細については、コマンド プロンプトを開き、次のコマンドを入力して Enter キーを押 します。
Robocopy /?
いや書いてないでしょ。
Option Error Messageはバッチファイルを組まないと返らない
XP010にあるバッチファイル
ただし上記にあるように現在は8より値が大きい場合にエラーを返す。
iferrorlevel16echo***FATALERROR***&gotoendiferrorlevel15echoFAILMISMXTRACOPY&gotoendiferrorlevel14echoFAILMISMXTRA&gotoendiferrorlevel13echoFAILMISMCOPY&gotoendiferrorlevel12echoFAILMISM&gotoendiferrorlevel11echoFAILXTRACOPY&gotoendiferrorlevel10echoFAILXTRA&gotoendiferrorlevel9echoFAILCOPY 差分があったのでコピー操作をしたが、失敗した。&gotoendiferrorlevel8echoFAIL 差分がなかったが、操作に失敗した。&gotoendiferrorlevel7echoMISMXTRACOPY&gotoendiferrorlevel6echoMISMXTRA&gotoendiferrorlevel5echoMISMCOPY&gotoendiferrorlevel4echoMISM&gotoendiferrorlevel3echoXTRACOPY 差分があったのでコピー操作をした&コピー元にないファイルがコピー先にあったので削除操作をして、成功した&gotoendiferrorlevel2echoXTRA コピー元にないファイルがコピー先にあったので削除操作をして、成功した。&gotoendiferrorlevel1echoCOPY 複写操作精巧&gotoendiferrorlevel0echo--nochange-- 差分なし無変更終了&gotoend:endXTRA 差分コピー元になく、コピー先にある。ミラーリングの場合削除対象。
MISM ファイルミスマッチ
Option エラーメッセージの欠点
つまり、Robocopyの戻り値は、ディレクトリコピー同士のミラーリングを行ったような場合に
"一回のコピー全体でどのような操作をしたか、その操作群はどれも失敗なしで完了したか"を表すもので、
コピーは成功したけど削除は失敗した、といったような、各操作の成否判別には使えないものとなっている。
ではどの操作が失敗したのか?という情報は取れないかというと、そんなことはない。
その情報はRobocopyのログに吐かれている。
ここで若干日本語化されている。つまり、エラーメッセージについて公式な完全な解説はないのである。
またエラーメッセージは上記のようにBatファイルを組まなければならず、出力されるメッセージは1行しかない。
おそらく、ミラーリングを何回か繰り返し、8以下か、0になるまで行い、終了するような設計だと思われる。
バッチでしか返らないのはそのためであろう。
ネットワークの距離も高速化に影響する
「robocopy」コマンドでファイルコピー速度を上げる方法いろいろ
L2、レイヤー2レベル
https://www.cisco.com/c/m/ja_jp/products/switches/lan-switches.html
コピー時の帯域について
https://teratail.com/questions/94553
ついにPingを使って遅延を測定する領域に
/MTマルチスレッド数の制限オプションによる高速化
Windowsの「robocopy」コマンドで、より高速にコピーするためのテクニック
これはかなりの量の処理になるため、サーバーの
robocopy の速度向上ノウハウ~遅い原因と見直すべき5点~/MTオプションを明示すると/NPオプションが無効化される
Windowsの「robocopy」コマンドで、より高速にコピーするためのテクニック
/IPG帯域制限
Robocopyの帯域制限はWindowsの機能でやりましょう
Windows7, Windows 2012以降は/ipgではなくアウトバウンド制御で帯域を制限するほうが安定する。
アウトバウンドの帯域制限をWindows標準機能で行う
QOSポリシーを作成し、Robocopywo指定する。
その前に、このオプションの理解も必要だろう
Windowsのrobocopyコマンドでファイルコピー中断後に自動再開させるatmarkit 2014年04月30日 16時22分 公開
●/IPGオプションで帯域制御を行う場合の注意点
robocopyのオプションで、「/ipg:<ミリ秒>」を指定すると、1ブロックコピーするごとに指定した時間だけ、ウェイト(待ち時間)を入れることができる(ipg=inter packet gap)。これは、robocopyのファイルコピーでネットワーク帯域(ローカルディスク間でのコピーの場合は、ディスクインターフェースの帯域)を100%占有させないようにするためのオプションだが、これを使う場合は少し注意が必要である。
バージョンにもよるが、robocopyでは通常1ブロックのサイズは1Mbytesである。コピー元から1Mbytes読み出しては、コピー先に1Mbytes書き込み、/ipgオプションがあれば、そこで指定した時間(ミリ秒)だけ待ってから、次のブロックをコピーする、というふうに動作している。だが/zオプションを指定するとブロックサイズは64Kbytesになる。そのため/ipgオプションで同じ時間だけ待つとウェイトの時間が多くなり(単純計算で1Mbytes÷64Kbytes=16倍になる)、コピー時間が非常に長くなってしまう。
このような事情があるため、/zと/ipgオプションを両方使用する場合はウェイト時間の設定に注意していただきたい。/ipgオプションを使う場合は、最初に/ipg:10(10ミリ秒待つ、つまり1秒間に100ブロックコピーするという意味)や/ipg:100(100ミリ秒待つ。つまり1秒間に10ブロックコピーする)などの値でテストしてみて、適切な値を探すとよいだろう。
ネットワークドライブ上のファイルのローカルバックアップをスケジューリングする
この中でnet useでネットワークドライブを使用できるようにする過程が記述。
テクニック:エラースキップリダイレクト
ROBOCOPY(エラーを無視してコピーする) 2009年8月5日水曜日 めもちょうrobocopy C:\userdata \\server\userdata /R:0 /E /NFL /NP > COPY.LOG
こうするとエラーがあったものだけがCopy.LOGに残る。/NFL ファイル名を記録しない。と英語を直訳するとそうなるが、「エラーの発生したファイルを記録する。という意味。/NDLはいらないのかな。
テクニック:ログファイル除外
ログファイルを除外しておくと、ログファイルはコピー元における
c:\Users\very_>c:\windows\System32\Robocopy.exe"E:\""D:\BackUp\My Documents""*.*"/R:3/W:30/CopyAll /Dcopy:Dat/F /XF"E:\rst20210213.log"/XD"System Volume Information"/XD"D:\$RECYCLE.BIN"/Xj /XJD /LOG+:"E:\rst20210213.log"/NP /Tee /TS /Compress /Lattrib-s -h"D:\BackUp"テクニック:Powershellにおける、ドライブ名を指定した$RECYCLE.BIN
cd'.\$RECYCLE.BIN\'cd'H:\$RECYCLE.BIN\'この場合はアクサングラーブ、エスケープ文字はいらない。相対パスで、フォルダ名だけ指定するときに最初がドル記号になるときに必要。
シングルクォーテーションはむしろ失敗する。ダブルクォーテーションは成功する
'H:`$RECYCLE.BIN'は失敗する
cd'H:\`$RECYCLE.BIN\'"H:`$RECYCLE.BIN"は成功する
シングルクォーテーションと異なり、ダブルクォーテーションは変数として展開するようになっており、それを、エスケープで防止するため。
cd"H:\`$RECYCLE.BIN\"テクニック:ユニコード環境依存文字を使用しているファイルやフォルダのログ
CMD Powershell 共通 日本語の場合
Chcp 932
がデフォルトなので
chcp 65001
に変更する。終わったらChcp 932でもとに戻すこと。
現在のWindows 10はutf-8でバッチファイルを書ける。ただし上記のサイト記事のように設定に注意する必要がある。
Dirと同じ理屈
Chcp65001Cd/DH:DEL"H:\rst20210213.log"&&DEL"H:\RedLog.log"&&DEL"H:\RoboUni.Log"c:\windows\System32\Robocopy.exe"H:""G:\BackUp""*.*"/E /DCOPY:DAT/CopyAll /R:3/W:30/XD"$RECYCLE.BIN"/IM /IT /J /Xj /XJD /LOG+:"H:\rst20210213.log"/XF"H:\rst20210213.log""H:\RedLog.log"/UNILOG+:"H:\RoboUni.Log"/XF"H:\RoboUni.Log"/NP /Tee /TS /Compress /L /IS>H:\RedLog.logChcp932NOTE:最新のWindowsでは自動的に"System Volume Information"が除外されます
NOTE:65001においてはヘルプが英語になり、ログファイルも英語になります。
H:\rst20210213.log
New File 148 2020/09/11 14:07:53韜・ - .txtSame 148 2020/09/11 14:07:53韜・.txtRedLog.log
New File 148 2020/09/11 14:07:53♥㈲èéêëアイウエオქართული - コピー.txtSame 148 2020/09/11 14:07:53♥㈲èéêëアイウエオქართული.txtこのようにUnicode文字を使ったファイル名がある場合、リダイレクト出力させると良い
Recirectの謎の仕様。かませLogがないとリダイレクトも文字化けする
ところで、上記のオプションはUnicodeのLOGとリダイレクトのログは正常に出力されるが、ANSIのLOGは出力されない。
そこで、ANSIのLOGは削除する。
しかし、CHCP 65001C:\windows\system32\robocopy H: G:\BackUp2 /CopyAll /Xj /XJD /DCopy:DAT /TEE /NP /TS /L > H:\dbfolder\robolog.txt
このrobolog.txtは文字化けする。H:\>C:\windows\system32\robocopy H: G:\BackUp2 /CopyAll /Xj /XJD /DCopy:DAT /TEE /NP /TS /L /UNILOG+:H:\dbfolder\log.log > H:\dbfolder\robolog.txt
こちらは文字化けしない。
つまり、Log.Logをかませると正常に出力される。
Cmd.exeのみ
ただし、65001かませログリダイレクト方式はPosershellでは成功しない
Powershellがうまく行かないのはリダイレクトがUTF-16LEのためと考えられる
バッチファイルの文字コードは?Windows Script Programming 2008年12月25日 (木)
シフトJIS(932) だけ? いいえ、そんなことはありません。例えば、EUC-JP(20932) も可能です。しかし、Unicode(1200)、UTF-7(65000)、UTF-8(65001)、JIS(50220) はダメです。
なので、実際上?は、シフトJIS(932) だけのようなものです。
これらコードページのバッチファイル可否は、%SystemRoot%System32\C_コードページ.NLS の有無によるようです。
もし、コンソールのコードページを UTF-7(65000)、UTF-8(65001)、JIS(50220)に変えると、バッチファイルが全く実行できなくなります。
また、これらのコードページでは、単にバッチファイルが実行できなくなるだけでなく、TYPE コマンドを除いて、ファイルの読み書きが全くできなくなるようです。
バッチファイルを UTF-8 で書く2018-04-16 itpc.blog 2018-04-16
現在の Windows では、コードページ指定をすればコマンドラインで UTF-8 を書くことができます。
そこで、バッチファイルを UTF-8 で書く際に気をつけるべき点をご紹介します。
chcp65001chxp932- 改行コードはCR+LF
- 対応フォントに注意
- それでもうまく表示できない文字もある
PowerShellの場合
PowerShellではコードページ 932 と 65001 の何れでも、echo コマンドなどをリダイレクトしてファイルに保存すると、UTF-16LE(BOM付き)として出力されます。
また、コマンドプロンプトでは 932 のままだと文字化けするようなケースでも、PowerShell だと上手く動作する場合がありますが、65001 に変更したほうが確実に動作しますので、それについては省略します。
Robocopyのログは文字化けというより文字が消失する
上記のようなタイ文字は????ならまだしもそもそも消えてスペースすら残らない。つまり完全に別のファイル名になる。
このため、多言語環境では、この方式を使わざるを得ないだろう。
`/UNICODE'オプションは不要
このUnicodeはUTF-16LEで、リダイレクトがユニコードオプションで文字化けする。
##テクニック:エラーが出た場合には、そのファイル以外も犠牲になっているケースがある

一見コピーされたようでも、容量は0。
ファイル数をカウントする
では数が大体あう。
Systemフォルダを除外するDirのオプションはディレクトリは使わず、ファイルは使う。
Robocopyのため"System Volume Information"と"$RECYCLE.BIN"を除外している場合/AD-Sとしたほうがように思えるが、合計がわからないので、これは使わなくて良い。しかし、ファイル数は大幅に違うため、除外する必要がある。
容量を確認してみる
CHCP 932の場合
たとえばDドライブをG:\Backupsにコピーしたときエラーになった場合
上とは違いGの名称が違います。
chcp 932cd /d D:\Dir /A-D-S-H-L /S | FindStr" 個のファイル ">"D:\dbFolder\rst932_D_Files.txt"dir /s /AD | Findstr" 個のディレクトリ ">"D:\dbFolder\rst932_D_Dircs.txt"dir"G:\BackUps\" /s /a-d | Findstr " 個のファイル" > "D:\dbFolder\rst932_G_Files.txt"dir "G:\BackUps\" /s /AD | Findstr" 個のディレクトリ ">"D:\dbFolder\rst932_G_Dircs.txt" 3982 個のファイル 103,974,454,521 バイト一番最後の行が、ファイル数と合計
ファイル数はdir /A-D /S /B | find /c /v ""と一致する
フォルダ数は
384 個のディレクトリ 11,841,548,288 バイトの空き領域About_Dirディレクトリ数は/Findと/FindStrで大きく違う
H:\testado\vbasampetabl.files のディレクトリ2020/05/24 17:49 <DIR> .2020/05/24 17:49 <DIR> ..例えばこれを3階層として数えるか、1フォルダとして数えるかという違いが生じるようだ。
dir /S /B /AD | find /c /v ""
とは一致しない。
上記の場合は階層も重複して数えているが行数で数えるため、重複が生じない。
この場合、どっちが正しいかではなく、どっちもやるべきだろう。
できれば/ADとの違いも見るべきだろう
空き領域は同容量のときは参考になる。
英語またはUTF8(65001)の場合
ちょっとBatにしてみた。
もちろん、除外条件等で違うが、フォルダ数はFindのほうがほぼあう。しかし、ファイル数はFindとFindstrは一致するものの、RobocopyのLogとはあわず、目安にしかならない。ジャンクションや隠し、システムファイルが入ってくる、ルートではカウントは難しい。
Serverともなれば権限が絡み、ファイル数すらうまくいくかどうかはわからない。しかし、目安になるのは確実だ。
CHCP65001cd/dD:\DEL"D:\dbfolder\log.log"DEL"D:\dbfolder\robolog.txt"DEL"D:\dbFolder\rstUTF8_D_Files.txt"DEL"D:\dbFolder\rstUTF8_D_Dircs.txt"DEL"D:\dbFolder\rstUTF8_G_Files.txt"DEL"D:\dbFolder\rstUTF8_G_Dircs.txt"REM LogファイルはD:\DbfolderにあるC:\windows\system32\robocopyD:G:\BackUps/E /CopyAll /XF /Xj /XJD /DCopy:DAT/TEE /NP /TS /XD"$RECYCLE.BIN"/L /UNILOG+:D:\dbfolder\log.log>D:\dbfolder\robolog.txtREM Source FilesDir/A-D-S-H-L /S|FindStr" File(s) ">"D:\dbFolder\rstUTF8_D_Files.txt"Dir/A-D-S-H-L /S /B|Find/C /V"">>"D:\dbFolder\rstUTF8_D_Files.txt"REM Source Directories(Folder)Dir/AD /S|FindStr" Dir(s) ">"D:\dbFolder\rstUTF8_D_Dircs.txt"Dir/AD /S /B|Find/C /V"">>"D:\dbFolder\rstUTF8_D_Dircs.txt"REM Distination FilesDir"G:\BackUps\"/A-D-S-H-L /S|FindStr" File(s) ">"D:\dbFolder\rstUTF8_G_Files.txt"Dir"G:\BackUps\"/A-D-S-H-L /S /B|Find/C /V"">>"D:\dbFolder\rstUTF8_G_files.txt"REM Distination Directories(Folder)Dir"G:\BackUps\"/AD /S|FindStr" Dir(s) ">"D:\dbFolder\rstUTF8_G_Dircs.txt"Dir"G:\BackUps\"/AD /S /B|Find/C /V"">>"D:\dbFolder\rstUTF8_G_Dircs.txt"chcp932テクニック:エラーが出た場合等にもう一度コピーし直す'/IM' `/IS'
コピーに失敗すると、サイズ以外は属性等が同じで、更新日付を基準にするとおなじになる。
このため、Robocopyがきかない。MSはそういう状況のためにオプションを作ったらしい。/IMこのオプションはかなり新しい、この2つは名前が同じなら複写、更新されていても複写になる。/ISだけでも行けると思うが、この2つはそういうエラーを起こした状況に対応するもののようだ。
/ISオプションは強制上書きではない
robocopy で毎回「強制上書き」はできますか?
質問者としては同じファイルでも強制的に上書きをしてほしいということだが、/ISオプションの挙動は同じファイルでも内容が同じならスキップする。
テクニック:実行中やプロセスが掴んでいても/Bオプションでコピーできる
robocopyコマンドで、プロセスが掴んでいるファイルを強制的にコピーする方法C:\Windows\System32\robocopy.exe "C:\Windows\System32" "G:\BackUp2" "Robocopy.exe" /B
権限だけに限らず、実行中のRobocopyすらコピーできてしまう
ただしCopy:DATまたはCooyAllを忘れてはいけない
slG:\backup2\testdir1\notepad.\test.txt#ファイルができたら閉じるcd\C:\Windows\System32\Robocopy.exeG:\backup2\testdir1G:\backup2\testdir2/B/L-a----1980/01/029:000test.txtもっともこのエラーは次は起きなかった。しかし、属性のコピーオプションは忘れては行けないようだ。
テクニック:Robocopyを使用してインターネット経由でファイルを転送する方法
サーバーレベルではなく共有フォルダを用いた上で、Robocopywoするというもの。さほど大きくないものは可能だが、作業ステップが多い。
【Windows】robocopyでユーザIDとパスワードが必要な共有フォルダに接続する方法
これはサーバーからサーバーへRObocopyで移動するレシ
テクニック:ROBOCOPY はPythonでも使える
Python Tips & Memos by Physical Oceanography & Climate Laboratory in Hokkaido University
robocopyd:\i:\/mir/DCOPY:T/XD$RECYCLE.BIN$"System Volume Information"となっているが
c:\Windows\System32\robocopyd:i:/mir/DCOPY:DAT/R:3/W:10/XD$RECYCLE.BIN$"System Volume Information /XJ /XJD"d:\ i:\はd: i:ではないのか。ルートドライブはコマンド プロンプトや Powershellではスラッシュがつかないのだが。
ヒストリー:最新のWindows10までのROBOCOPYの変更
Compressだけでなく、Windows10であっても仕様が変更されている。しかも直近は2年おきくらいに変更がある。
ただし、今回の記事では2006年のGUI1版はほとんど資料がない上に、使う人を見たことがないため、取り扱っていない。
OSのバージョンでまとめているがのが、以下の記事。
ROBOCOPY コマンドのヘルプ 2010-12-14
2003年、2006年、2008年、2018年、2020年あたりに変更があったことが確認されている。
XP010
Windows Server 2003 Resource kit Toools
------------------------------------------------------------------------------- ROBOCOPY :: Robust File Copy for Windows :: Version XP010------------------------------------------------------------------------------- Started : Usage :: ROBOCOPY source destination [file [file]...] [options] source :: Source Directory (drive:\path or \\server\share\path). destination :: Destination Dir (drive:\path or \\server\share\path). file :: File(s) to copy (names/wildcards: default is "*.*").:::: Copy options ::: /S :: copy Subdirectories, but not empty ones. /E :: copy subdirectories, including Empty ones. /LEV:n :: only copy the top n LEVels of the source directory tree. /Z :: copy files in restartable mode. /B :: copy files in Backup mode. /ZB :: use restartable mode; if access denied use Backup mode. /COPY:copyflag[s] :: what to COPY (default is /COPY:DAT). (copyflags : D=Data, A=Attributes, T=Timestamps). (S=Security=NTFS ACLs, O=Owner info, U=aUditing info). /SEC :: copy files with SECurity (equivalent to /COPY:DATS). /COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU). /NOCOPY :: COPY NO file info (useful with /PURGE). /PURGE :: delete dest files/dirs that no longer exist in source. /MIR :: MIRror a directory tree (equivalent to /E plus /PURGE). /MOV :: MOVe files (delete from source after copying). /MOVE :: MOVE files AND dirs (delete from source after copying). /A+:[RASHNT] :: add the given Attributes to copied files. /A-:[RASHNT] :: remove the given Attributes from copied files. /CREATE :: CREATE directory tree and zero-length files only. /FAT :: create destination files using 8.3 FAT file names only. /FFT :: assume FAT File Times (2-second granularity). /256 :: turn off very long path (> 256 characters) support. /MON:n :: MONitor source; run again when more than n changes seen. /MOT:m :: MOnitor source; run again in m minutes Time, if changed. /RH:hhmm-hhmm :: Run Hours - times when new copies may be started. /PF :: check run hours on a Per File (not per pass) basis. /IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.:::: File Selection Options ::: /A :: copy only files with the Archive attribute set. /M :: copy only files with the Archive attribute and reset it. /IA:[RASHCNETO] :: Include only files with any of the given Attributes set. /XA:[RASHCNETO] :: eXclude files with any of the given Attributes set. /XF file [file]... :: eXclude Files matching given names/paths/wildcards. /XD dirs [dirs]... :: eXclude Directories matching given names/paths. /XC :: eXclude Changed files. /XN :: eXclude Newer files. /XO :: eXclude Older files. /XX :: eXclude eXtra files and directories. /XL :: eXclude Lonely files and directories. /IS :: Include Same files. /IT :: Include Tweaked files. /MAX:n :: MAXimum file size - exclude files bigger than n bytes. /MIN:n :: MINimum file size - exclude files smaller than n bytes. /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date. /MINAGE:n :: MINimum file AGE - exclude files newer than n days/date. /MAXLAD:n :: MAXimum Last Access Date - exclude files unused since n. /MINLAD:n :: MINimum Last Access Date - exclude files used since n. (If n < 1900 then n = n days, else n = YYYYMMDD date). /XJ :: eXclude Junction points. (normally included by default).:::: Retry Options ::: /R:n :: number of Retries on failed copies: default 1 million. /W:n :: Wait time between retries: default is 30 seconds. /REG :: Save /R:n and /W:n in the Registry as default settings. /TBD :: wait for sharenames To Be Defined (retry error 67).:::: Logging Options ::: /L :: List only - don't copy, timestamp or delete any files. /X :: report all eXtra files, not just those selected. /V :: produce Verbose output, showing skipped files. /TS :: include source file Time Stamps in the output. /FP :: include Full Pathname of files in the output. /NS :: No Size - don't log file sizes. /NC :: No Class - don't log file classes. /NFL :: No File List - don't log file names. /NDL :: No Directory List - don't log directory names. /NP :: No Progress - don't display % copied. /ETA :: show Estimated Time of Arrival of copied files. /LOG:file :: output status to LOG file (overwrite existing log). /LOG+:file :: output status to LOG file (append to existing log). /TEE :: output to console window, as well as the log file. /NJH :: No Job Header. /NJS :: No Job Summary.:::: Job Options ::: /JOB:jobname :: take parameters from the named JOB file. /SAVE:jobname :: SAVE parameters to the named job file /QUIT :: QUIT after processing command line (to view parameters). /NOSD :: NO Source Directory is specified. /NODD :: NO Destination Directory is specified. /IF :: Include the following Files.C:\>2013
-------------------------------------------------------------------------------ROBOCOPY :: Windows の堅牢性の高いファイル コピー-------------------------------------------------------------------------------開始: Wed Dec 11 13:15:59 2013使用法:: ROBOCOPY コピー元 コピー先 [ファイル [ファイル]...][オプション]コピー元 :: コピー元ディレクトリ (ドライブ:\パスまたは \\サーバー\共有\パス)。コピー先 :: コピー先ディレクトリ (ドライブ:\パスまたは \\サーバー\共有\パス)。ファイル :: コピーするファイル (名前/ワイルドカード: 既定値は「*.*」です):::: コピー オプション:::/S :: サブディレクトリをコピーしますが、空のディレクトリはコピーしません。/E :: 空のディレクトリを含むサブディレクトリをコピーします。/LEV:n :: コピー元ディレクトリ ツリーの上位 n レベルのみをコピーします。/Z :: 再起動可能モードでファイルをコピーします。/B :: バックアップ モードでファイルをコピーします。/ZB :: 再起動可能モードを使用します。アクセスが拒否された場合、バックアップ モードを使用します。/EFSRAW :: 暗号化されたすべてのファイルを EFS RAW モードでコピーします。/COPY:コピーフラグ :: ファイルにコピーする情報 (既定値は /COPY:DAT)。(コピーフラグ: D= データ、A= 属性、T= タイムスタンプ)。(S= セキュリティ =NTFS ACL、O= 所有者情報、U= 監査情報)。/DCOPY:T :: ディレクトリ タイムスタンプをコピーします。/SEC :: セキュリティと共にファイルをコピーします (/COPY:DATS と同等)。/COPYALL :: ファイル情報をすべてコピーします (/COPY:DATSOU と同等)。/NOCOPY :: ファイル情報をコピーしません (/PURGE と共に使用すると便利)/SECFIX :: スキップしたファイルも含むすべてのファイルのファイル セキュリティを修正します。/TIMFIX :: スキップしたファイルも含むすべてのファイルのファイル時刻を修正します。/PURGE :: 既にコピー元に存在しないコピー先のファイル/ディレクトリを削除します。/MIR :: ディレクトリ ツリーをミラー化します (/E および /PURGE と同等)/MOV :: ファイルを移動します (コピー後にコピー元から削除)。/MOVE :: ファイルとディレクトリを移動します (コピー後にコピー元から削除)。/A+:[RASHCNET] :: コピーされたファイルに指定の属性を追加します。/A-:[RASHCNET] :: コピーされたファイルから指定の属性を削除します。/CREATE :: ディレクトリ ツリーと長さ 0 のファイルのみを作成します。/FAT :: 8.3 FAT ファイル名のみを使用してコピー先ファイルを作成します。/256 :: 256 文字を超える非常に長いパスのサポートをオフにします。/MON:n :: コピー元を監視し、n 回を超える変更があった場合に再度実行します。/MOT:m :: コピー元を監視し、変更があった場合 m 分間再度実行します。/RH:hhmm-hhmm :: 実行時間 - 新しいコピーを開始できる時刻です。/PF :: 実行時間をファイルごと (パスごとではない) に確認します。/IPG:n :: 低速回線で帯域幅を解放するためのパケット間ギャップ (ミリ秒) 。/SL :: 対象ではなくシンボリック リンクをコピーします。/MT[:n] :: n 個のスレッドのマルチスレッド コピーを実行します(既定値 8)。n は 1 から 128 までの値である必要があります。このオプションは、/IPG および /EFSRAW オプションと互換性がありません。パフォーマンスの向上のため、/LOG オプションを使用して出力をリダイレクトします。:::: ファイル選択オプション:::/A :: アーカイブ属性が設定されているファイルのみをコピーします。/M :: アーカイブ属性のあるファイルのみをコピーし、リセットします。/IA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルのみを含みます。/XA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルを除外します。/XF ファイル [ファイル]... :: 指定された名前/パス/ワイルドカードに一致するファイルを除外します。/XD ディレクトリ [ディレクトリ]... :: 指定された名前/パスに一致するディレクトリを除外します。/XC :: 変更されたファイルを除外します。/XN :: 新しいファイルを除外します。/XO :: 古いファイルを除外します。/XX :: コピー先にだけ存在するファイルとディレクトリを除外します。/XL :: コピー元にだけ存在するファイルとディレクトリを除外します。/IS :: 同一ファイルを含みます。/IT :: 異常なファイルを含めます。/MAX:n :: 最大ファイル サイズ - n バイトより大きいファイルを除外します。/MIN:n :: 最小ファイル サイズ - n バイトより小さいファイルを除外します。/MAXAGE:n :: 最長ファイル有効期間 - n 日より古いファイルを除外します。/MINAGE:n :: 最短ファイル有効期間 - n 日より新しいファイルを除外します。/MAXLAD:n :: 最大最終アクセス日 - n で指定する値以後に使用していないファイルを除外します。/MINLAD:n :: 最小最終アクセス日 - n で指定する値以後に使用されたファイルを除外します。(n < 1900 の場合、n = n 日です。それ以外は、n = YYYYMMDDの日付です)。/XJ :: 接合ポイントを除外します (通常、既定で含まれます)。/FFT :: FAT ファイル時間 (2 秒の粒度) を仮定します。/DST :: 1 時間の DST 時間差を補正します。/XJD :: ディレクトリの接合ポイントを除外します。/XJF :: ファイルの接合ポイントを除外します。:::: 再試行オプション:::/R:n :: 失敗したコピーに対する再試行数: 既定値は 1,000,000。/W:n :: 再試行と再試行の間の待機時間: 既定値は、30 秒です。/REG :: /既定の設定としてレジストリに R:n と /W:n を保存します。/TBD :: 共有名が定義されるのを待ちます (再試行エラー 67)。:::: ログ オプション:::/L :: リストのみ - いずれのファイルにも、コピー、タイムスタンプの追加、または削除を実施しません。/X :: 選択されたファイルのみではなく、余分なファイルをすべて報告します。/V :: スキップされたファイルを示す詳細出力を作成します。/TS :: 出力にコピー元ファイルのタイム スタンプを含めます。/FP :: 出力にファイルの完全なパス名を含めます。/BYTES :: サイズをバイトで出力します。/NS :: サイズなし - ファイル サイズをログに記録しません。/NC :: クラスなし - ファイル クラスをログに記録しません。/NFL :: ファイル リストなし - ファイル名をログに記録しません。/NDL :: ディレクトリなし - ディレクトリ名をログに記録しません。/NP :: 進行状況なし - コピーの完了率を表示しません。/ETA :: コピーするファイルの推定完了時刻を表示します。/LOG:ファイル :: ログ ファイルに状態を出力します (既存のログを上書きします)。/LOG+:ファイル :: ログ ファイルに状態を出力します (既存のログ ファイルに追加します)。/UNILOG:ファイル :: ログ ファイルに UNICODE で状態を出力します (既存のログを上書きします)。/UNILOG+:ファイル :: ログ ファイルに UNICODE で状態を出力します (既存のログに追加します)。/TEE :: コンソール ウィンドウとログ ファイルに出力します。/NJH :: ジョブ ヘッダーがありません。/NJS :: ジョブ概要がありません。/UNICODE :: 状態を UNICODE で出力します。:::: ジョブ オプション:::/JOB:ジョブ名 :: 名前の付いたジョブ ファイルからパラメーターを取得します。/SAVE:ジョブ名 :: 名前の付いたジョブ ファイルにパラメーターを保存します。/QUIT :: コマンド ラインの処理後に終了します (パラメーターの表示のため)。/NOSD :: コピー元ディレクトリを指定しません。/NODD :: コピー先ディレクトリを指定しません。/IF :: 後続のファイルを含みます。2018
robocopyコマンドの有用なオプション
2013年と比較すると、/DCopyの記述が変更されている。単純なヘルプのコピペでも、貴重な資料となりうる。
------------------------------------------------------------------------------- ROBOCOPY :: Windows の堅牢性の高いファイル コピー ------------------------------------------------------------------------------- 開始: 2018年9月15日 19:50:13 使用法:: ROBOCOPY コピー元 コピー先 [ファイル [ファイル]...] [オプション] コピー元 :: コピー元ディレクトリ (ドライブ:\パスまたは \\サーバー\共有\パス)。 コピー先 :: コピー先ディレクトリ (ドライブ:\パスまたは \\サーバー\共有\パス)。 ファイル :: コピーするファイル (名前/ワイルドカード: 既定値は「*.*」です):::: コピー オプション::: /S :: サブディレクトリをコピーしますが、空のディレクトリはコピーしません。 /E :: 空のディレクトリを含むサブディレクトリをコピーします。 /LEV:n :: コピー元ディレクトリ ツリーの上位 n レベルのみをコピーします。 /Z :: 再起動可能モードでファイルをコピーします。 /B :: バックアップ モードでファイルをコピーします。 /ZB :: 再起動可能モードを使用します。アクセスが拒否された場合、バックアップ モードを使用します。 /J :: バッファーなし I/O を使用してコピーします (大きなファイルで推奨)。 /EFSRAW :: 暗号化されたすべてのファイルを EFS RAW モードでコピーします。 /COPY:コピーフラグ :: ファイルにコピーする情報 (既定値は /COPY:DAT)。 (コピーフラグ: D= データ、A= 属性、T= タイムスタンプ)。 (S= セキュリティ =NTFS ACL、O= 所有者情報、U= 監査情報)。 /SEC :: セキュリティと共にファイルをコピーします (/COPY:DATS と同等)。 /COPYALL :: ファイル情報をすべてコピーします (/COPY:DATSOU と同等)。 /NOCOPY :: ファイル情報をコピーしません (/PURGE と共に使用すると便利)。 /SECFIX :: スキップしたファイルも含むすべてのファイルのファイル セキュリティを修正します。 /TIMFIX :: スキップしたファイルも含むすべてのファイルのファイル時刻を修正します。 /PURGE :: 既にコピー元に存在しないコピー先のファイル/ディレクトリを削除します。 /MIR :: ディレクトリ ツリーをミラー化します (/E および /PURGE と同等)。 /MOV :: ファイルを移動します (コピー後にコピー元から削除)。 /MOVE :: ファイルとディレクトリを移動します (コピー後にコピー元から削除)。 /A+:[RASHCNET] :: コピーされたファイルに指定の属性を追加します。 /A-:[RASHCNET] :: コピーされたファイルから指定の属性を削除します。 /CREATE :: ディレクトリ ツリーと長さ 0 のファイルのみを作成します。 /FAT :: 8.3 FAT ファイル名のみを使用してコピー先ファイルを作成します。 /256 :: 256 文字を超える非常に長いパスのサポートをオフにします。 /MON:n :: コピー元を監視し、n 回を超える変更があった場合に再度実行します。 /MOT:m :: コピー元を監視し、m 分後に変更があった場合に再度実行します。 /RH:hhmm-hhmm :: 実行時間 - 新しいコピーを開始できる時刻です。 /PF :: 実行時間をファイルごと (パスごとではない) に確認します。 /IPG:n :: 低速回線で帯域幅を解放するためのパケット間ギャップ (ミリ秒)。 /SL :: 対象ではなくシンボリック リンクをコピーします。 /MT[:n] :: n 個のスレッドのマルチスレッド コピーを実行します (既定値 8)。 n は 1 から 128 までの値である必要があります。 このオプションは、/IPG および /EFSRAW オプションと互換性 がありません。 パフォーマンスの向上のため、/LOG オプションを使用して出力 をリダイレクトします。 /DCOPY:コピーフラグ :: ディレクトリにコピーする情報 (既定値は /DCOPY:DA)。 (コピーフラグ: D= データ、A= 属性、T= タイムスタンプ)。 /NODCOPY :: ディレクトリ情報をコピーしません (既定では /DCOPY:DA が実行されます)。 /NOOFFLOAD :: Windows のオフロードをコピーするメカニズムを使用せずに、ファイルをコピーします。:::: ファイル選択オプション::: /A :: アーカイブ属性が設定されているファイルのみをコピーします。 /M :: アーカイブ属性のあるファイルのみをコピーし、リセットします。 /IA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルのみを含みます。 /XA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルを除外します。/XF file [ファイル]... :: 指定された名前/パス/ワイルドカードに一致するファイルを除外します。/XD dir [ディレクトリ]... :: 指定された名前/パスに一致するディレクトリを除外します。 /XC :: 変更されたファイルを除外します。 /XN :: 新しいファイルを除外します。 /XO :: 古いファイルを除外します。 /XX :: コピー先にだけ存在するファイルとディレクトリを除外します。 /XL :: コピー元にだけ存在するファイルとディレクトリを除外します。 /IS :: 同一ファイルを含みます。 /IT :: 異常なファイルを含めます。 /MAX:n :: 最大ファイル サイズ - n バイトより大きいファイルを除外します。 /MIN:n :: 最小ファイル サイズ - n バイトより小さいファイルを除外します。 /MAXAGE:n :: 最長ファイル有効期間 - n 日より古いファイルを除外します。 /MINAGE:n :: 最短ファイル有効期間 - n 日より新しいファイルを除外します。 /MAXLAD:n :: 最大最終アクセス日 - n で指定する値以後に使用していないファイルを除外します。 /MINLAD:n :: 最小最終アクセス日 - n で指定する値以後に使用されたファイルを除外します。 (n < 1900 の場合、n = n 日です。それ以外は、n = YYYYMMDDの日付です)。 /XJ :: 接合ポイントを除外します (通常、既定で含まれます)。 /FFT :: FAT ファイル時間 (2 秒の粒度) を仮定します。 /DST :: 1 時間の DST 時間差を補正します。 /XJD :: ディレクトリの接合ポイントを除外します。 /XJF :: ファイルの接合ポイントを除外します。:::: 再試行オプション::: /R:n :: 失敗したコピーに対する再試行数: 既定値は 1,000,000。 /W:n :: 再試行と再試行の間の待機時間: 既定値は、30 秒です。 /REG :: /既定の設定としてレジストリに R:n と /W:n を保存します。 /TBD :: 共有名が定義されるのを待ちます (再試行エラー 67)。:::: ログ オプション::: /L :: リストのみ - いずれのファイルにも、コピー、タイムスタンプの追加、または削除を実施しません。 /X :: 選択されたファイルのみではなく、余分なファイルをすべて報告します。 /V :: スキップされたファイルを示す詳細出力を作成します。 /TS :: 出力にコピー元ファイルのタイム スタンプを含めます。 /FP :: 出力にファイルの完全なパス名を含めます。 /BYTES :: サイズをバイトで出力します。 /NS :: サイズなし - ファイル サイズをログに記録しません。 /NC :: クラスなし - ファイル クラスをログに記録しません。 /NFL :: ファイル リストなし - ファイル名をログに記録しません。 /NDL :: ディレクトリなし - ディレクトリ名をログに記録しません。 /NP :: 進行状況なし - コピーの完了率を表示しません。 /ETA :: コピーするファイルの推定完了時刻を表示します。 /LOG:ファイル :: ログ ファイルに状態を出力します (既存のログを上書きします)。 /LOG+:ファイル :: ログ ファイルに状態を出力します (既存のログ ファイルに追加します)。 /UNILOG:ファイル :: ログ ファイルに UNICODE で状態を出力します (既存のログを上書きします)。 /UNILOG+:ファイル :: ログ ファイルに UNICODE で状態を出力します (既存のログに追加します)。 /TEE :: コンソール ウィンドウとログ ファイルに出力します。 /NJH :: ジョブ ヘッダーがありません。 /NJS :: ジョブ要約がありません。 /UNICODE :: 状態を UNICODE で出力します。:::: ジョブ オプション::: /JOB:ジョブ名 :: 名前の付いたジョブ ファイルからパラメーターを取得します。 /SAVE:ジョブ名 :: 名前の付いたジョブ ファイルにパラメーターを保存します。 /QUIT :: コマンド ラインの処理後に終了します (パラメーターの表示のため)。 /NOSD :: コピー元ディレクトリを指定しません。 /NODD :: コピー先ディレクトリを指定しません。 /IF :: 後続のファイルを含みます。:::: 注釈 ::: ボリュームのルート ディレクトリで /PURGE または /MIR を使用すると、 robocopy は、要求した操作を System Volume Information 内のファイル にも適用します。この動作が意図したものでない場合は、 /XD スイッチを使用して、そのディレクトリをスキップするように robocopy に指示することができます。2021年
-------------------------------------------------------------------------------ROBOCOPY ::Windows の堅牢性の高いファイル コピー------------------------------------------------------------------------------- 開始:2021年2月1日13:16:04 使用法::ROBOCOPY コピー元 コピー先[ファイル[ファイル]...][オプション] コピー元 :: コピー元ディレクトリ(ドライブ:\パスまたは \\サーバー \共有\パス)。 コピー先 :: コピー先ディレクトリ(ドライブ:\パスまたは \\サーバー \共有\パス)。 ファイル :: コピーするファイル(名前/ワイルドカード: 既定値は「*.*」 です):::: コピー オプション:::/S:: サブディレクトリをコピーしますが、空のディレクトリはコピ ーしません。/E:: 空のディレクトリを含むサブディレクトリをコピーします。/LEV:n :: コピー元ディレクトリ ツリーの上位n レベルのみをコピーし ます。/Z:: 再起動可能モードでファイルをコピーします。/B:: バックアップ モードでファイルをコピーします。/ZB:: 再起動可能モードを使用します。アクセスが拒否された場合、 バックアップ モードを使用します。/J:: バッファーなしI/Oを使用してコピーします(大きなファイル で推奨)。/EFSRAW:: 暗号化されたすべてのファイルをEFSRAW モードでコピーし ます。/COPY:コピーフラグ :: ファイルにコピーする情報(既定値は/COPY:DAT)。(copyflags :D=データ、A=属性、T=タイムスタンプ、X=代替データ ストリームをスキップ)。(S= セキュリティ=NTFSACL、O= 所有者情報、U= 監査情報)。/SEC:: セキュリティと共にファイルをコピーします(/COPY:DATS と 同等)。/COPYALL:: ファイル情報をすべてコピーします(/COPY:DATSOU と同等)。/NOCOPY:: ファイル情報をコピーしません(/PURGEと共に使用すると便 利)。/SECFIX:: スキップしたファイルも含むすべてのファイルのファイル セ キュリティを修正します。/TIMFIX:: スキップしたファイルも含むすべてのファイルのファイル時刻 を修正します。/PURGE:: 既にコピー元に存在しないコピー先のファイル/ディレクトリ を削除します。/MIR:: ディレクトリ ツリーをミラー化します(/Eおよび/PURGEと 同等)。/MOV:: ファイルを移動します(コピー後にコピー元から削除)。/MOVE:: ファイルとディレクトリを移動します(コピー後にコピー元か ら削除)。/A+:[RASHCNET] :: コピーされたファイルに指定の属性を追加します。/A-:[RASHCNET] :: コピーされたファイルから指定の属性を削除します。/CREATE:: ディレクトリ ツリーと長さ0 のファイルのみを作成します。/FAT::8.3FAT ファイル名のみを使用してコピー先ファイルを作成し ます。 /256 ::256 文字を超える非常に長いパスのサポートをオフにします。/MON:n :: コピー元を監視し、n 回を超える変更があった場合に再度実行 します。/MOT:m :: コピー元を監視し、m 分後に変更があった場合に再度実行 します。/RH:hhmm-hhmm:: 実行時間- 新しいコピーを開始できる時刻です。/PF:: 実行時間をファイルごと(パスごとではない) に確認します。/IPG:n :: 低速回線で帯域幅を解放するためのパケット間ギャップ(ミリ 秒)。/SJ:: 接合のターゲットとしてではなく接合としてJunctions をコピーします。/SL:: リンクのターゲットとしてではなくリンクとしてシンボリック リンクをコピーします。/MT[:n] ::n 個のスレッドのマルチスレッド コピーを実行します(既定値8)。n は1 から128 までの値である必要があります。 このオプションは、/IPG および/EFSRAWオプションと互換性がありません。 パフォーマンス向上のため、/LOG オプションを使用して出力をリダイレクトします。/DCOPY:コピーフラグ :: ディレクトリにコピーする情報(既定値は/DCOPY:DA)。(copyflags :D=データ、A=属性、T=タイムスタンプ、E=EA、X=代替データ ストリームをスキップ)。/NODCOPY:: ディレクトリ情報をコピーしません(既定では/DCOPY:DA が実行されます)。/NOOFFLOAD::Windows のオフロードをコピーするメカニズムを使用せずに、 ファイルをコピーします。/COMPRESS:: ファイル転送中にネットワーク圧縮を要求します(適用可能な場合)。:::: ファイル選択オプション:::/A:: アーカイブ属性が設定されているファイルのみをコピーしま す。/M:: アーカイブ属性のあるファイルのみをコピーし、リセットしま す。/IA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルのみを含 みます。/XA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルを除外し ます。/XFfile[ファイル]... :: 指定された名前/パス/ワイルドカードに一致するファイルを 除外します。/XDdir[ディレクトリ]... :: 指定された名前/パスに一致するディレクトリを除外します。/XC:: 変更されたファイルを除外します。/XN:: 新しいファイルを除外します。/XO:: 古いファイルを除外します。/XX:: コピー先にだけ存在するファイルとディレクトリを除外し ます。/XL:: コピー元にだけ存在するファイルとディレクトリを除外し ます。/IS:: 同一ファイルを含みます。/IT:: 異常なファイルを含めます。/MAX:n :: 最大ファイル サイズ-n バイトより大きいファイルを除外し ます。/MIN:n :: 最小ファイル サイズ-n バイトより小さいファイルを除外し ます。/MAXAGE:n :: 最長ファイル有効期間-n 日より古いファイルを除外します。/MINAGE:n :: 最短ファイル有効期間-n 日より新しいファイルを除外しま す。/MAXLAD:n :: 最大最終アクセス日-n で指定する値以後に使用していない ファイルを除外します。/MINLAD:n :: 最小最終アクセス日-n で指定する値以後に使用されたファ イルを除外します。(n<1900 の場合、n=n 日です。それ以外は、n=YYYYMMDD の日付です)。/FFT::FAT ファイル時間(2 秒の粒度) を想定します。/DST::1 時間のDST 時間差を補正します。/XJ:: シンボリック リンク(ファイルとディレクトリの両方) と接合ポイントを除外します。/XJD:: ディレクトリのシンボリック リンクと接合ポイントを除外します。/XJF:: ファイルのシンボリック リンクを除外します。/IM:: 変更されたファイルを含めます(変更日時が異なる)。:::: 再試行オプション:::/R:n :: 失敗したコピーに対する再試行数: 既定値は1,000,000。/W:n :: 再試行と再試行の間の待機時間: 既定値は、30 秒です。/REG:: /既定の設定としてレジストリにR:n と/W:n を保存します。/TBD:: 共有名が定義されるのを待ちます(再試行エラー67)。/LFSM:: 空き領域不足モードで動作し、コピーの一時停止と再開を有効にします(「注釈」を参照)。/LFSM:n[KMG] :: 下限サイズをn[K:kilo,M:mega,G:giga] バイトで指定した/LFSM。:::: ログ オプション:::/L:: リストのみ- いずれのファイルにも、コピー、タイムスタン プの追加、または削除を実施しません。/X:: 選択されたファイルのみではなく、余分なファイルをすべて報 告します。/V:: スキップされたファイルを示す詳細出力を作成します。/TS:: 出力にコピー元ファイルのタイム スタンプを含めます。/FP:: 出力にファイルの完全なパス名を含めます。/BYTES:: サイズをバイトで出力します。/NS:: サイズなし- ファイル サイズをログに記録しません。/NC:: クラスなし- ファイル クラスをログに記録しません。/NFL:: ファイル リストなし- ファイル名をログに記録しません。/NDL:: ディレクトリなし- ディレクトリ名をログに記録しません。/NP:: 進行状況なし- コピーの完了率を表示しません。/ETA:: コピーするファイルの推定完了時刻を表示します。/LOG:ファイル :: ログ ファイルに状態を出力します(既存のログを上書きしま す)。/LOG+:ファイル :: ログ ファイルに状態を出力します(既存のログ ファイルに 追加します)。/UNILOG:ファイル :: ログ ファイルにUNICODE で状態を出力します(既存のログを 上書きします)。/UNILOG+:ファイル :: ログ ファイルにUNICODE で状態を出力します(既存のログに 追加します)。/TEE:: コンソール ウィンドウとログ ファイルに出力します。/NJH:: ジョブ ヘッダーがありません。/NJS:: ジョブ要約がありません。/UNICODE:: 状態をUNICODE で出力します。:::: ジョブ オプション:::/JOB:ジョブ名 :: 名前の付いたジョブ ファイルからパラメーターを取得します。/SAVE:ジョブ名 :: 名前の付いたジョブ ファイルにパラメーターを保存します。/QUIT:: コマンド ラインの処理後に終了します(パラメーターの表示の ため)。/NOSD:: コピー元ディレクトリを指定しません。/NODD:: コピー先ディレクトリを指定しません。/IF:: 後続のファイルを含みます。:::: 注釈 ::: ボリュームのルート ディレクトリに対して/PURGEまたは/MIRを使用すると、これまでは、robocopy は要求された操作をシステム ボリューム情報ディレクトリ内のファイル にも適用していました。この動作は変更されました。 どちらかを指定すると、robocopy はその名前を持つファイルまたはディレクトリを(コピー セッションの最上位レベルのソースと宛先ディレクトリで) スキップします。 変更されたファイルの分類は、コピー元とコピー先両方の ファイル システムが変更タイムスタンプ(NTFS など) をサポートしていて、 コピー元とコピー先のファイルの変更日時が異なり、しかし それ以外は同じ場合に適用されます。これらのファイルは既定ではコピーされません。/IM を指定して、 それらを含めます。/DCOPY:E フラグは、拡張属性コピーを ディレクトリに対して試行することを要求します。現時点ではrobocopy が継続されます(ディレクトリのEA をコピーできなかった場合)。このフラグは/COPYALL内。/LFSMを使用することで、robocopy に'空き領域不足モード' での動作を要求します。 そのモードでは、次の場合にrobocopy が一時停止します。すなわち、ファイルのコピーによって コピー先ボリュームの空き領域が'下限' 値を下回る場合です。この値は フラグのLFSM:n[KMG] 形式によって明示的に指定できます。/LFSMが明示的な下限値なしで指定されている場合、下限は コピー先ボリュームのサイズの10% に設定されます。 空き領域不足モードは、/MT、/EFSRAW、/B、および/ZB と互換性がありません。2023年 Windows11
2021年のWindow10とおなじと思われる。
-------------------------------------------------------------------------------ROBOCOPY ::Windows の堅牢性の高いファイル コピー------------------------------------------------------------------------------- 開始:2023年6月26日23:02:34 使用法::ROBOCOPY コピー元 コピー先[ファイル[ファイル]...][オプション] コピー元 :: コピー元ディレクトリ(ドライブ:\パスまたは \\サーバー \共有\パス)。 コピー先 :: コピー先ディレクトリ(ドライブ:\パスまたは \\サーバー \共有\パス)。 ファイル :: コピーするファイル(名前/ワイルドカード: 既定値は「*.*」 です):::: コピー オプション:::/S:: サブディレクトリをコピーしますが、空のディレクトリはコピ ーしません。/E:: 空のディレクトリを含むサブディレクトリをコピーします。/LEV:n :: コピー元ディレクトリ ツリーの上位n レベルのみをコピーし ます。/Z:: 再起動可能モードでファイルをコピーします。/B:: バックアップ モードでファイルをコピーします。/ZB:: 再起動可能モードを使用します。アクセスが拒否された場合、 バックアップ モードを使用します。/J:: バッファーなしI/Oを使用してコピーします(大きなファイル で推奨)。/EFSRAW:: 暗号化されたすべてのファイルをEFSRAW モードでコピーし ます。/COPY:コピーフラグ :: ファイルにコピーする情報(既定値は/COPY:DAT)。(copyflags :D=データ、A=属性、T=タイムスタンプ、X=代替データ ストリームをスキップ(/Bまたは/ZBの場合はX は無視されます)。(S= セキュリティ=NTFSACL、O= 所有者情報、U= 監査情報)。/SEC:: セキュリティと共にファイルをコピーします(/COPY:DATS と 同等)。/COPYALL:: ファイル情報をすべてコピーします(/COPY:DATSOU と同等)。/NOCOPY:: ファイル情報をコピーしません(/PURGEと共に使用すると便 利)。/SECFIX:: スキップしたファイルも含むすべてのファイルのファイル セ キュリティを修正します。/TIMFIX:: スキップしたファイルも含むすべてのファイルのファイル時刻 を修正します。/PURGE:: 既にコピー元に存在しないコピー先のファイル/ディレクトリ を削除します。/MIR:: ディレクトリ ツリーをミラー化します(/Eおよび/PURGEと 同等)。/MOV:: ファイルを移動します(コピー後にコピー元から削除)。/MOVE:: ファイルとディレクトリを移動します(コピー後にコピー元か ら削除)。/A+:[RASHCNET] :: コピーされたファイルに指定の属性を追加します。/A-:[RASHCNETO] :: コピーされたファイルから指定の属性を削除します。/CREATE:: ディレクトリ ツリーと長さ0 のファイルのみを作成します。/FAT::8.3FAT ファイル名のみを使用してコピー先ファイルを作成し ます。 /256 ::256 文字を超える非常に長いパスのサポートをオフにします。/MON:n :: コピー元を監視し、n 回を超える変更があった場合に再度実行 します。/MOT:m :: コピー元を監視し、m 分後に変更があった場合に再度実行 します。/RH:hhmm-hhmm:: 実行時間- 新しいコピーを開始できる時刻です。/PF:: 実行時間をファイルごと(パスごとではない) に確認します。/IPG:n :: 低速回線で帯域幅を解放するためのパケット間ギャップ(ミリ 秒)。/SJ:: 接合のターゲットとしてではなく接合としてJunctions をコピーします。/SL:: リンクのターゲットとしてではなくリンクとしてシンボリック リンクをコピーします。/MT[:n] ::n 個のスレッドのマルチスレッド コピーを実行します(既定値8)。n は1 から128 までの値である必要があります。 このオプションは、/IPG および/EFSRAWオプションと互換性がありません。 パフォーマンス向上のため、/LOG オプションを使用して出力をリダイレクトします。/DCOPY:コピーフラグ :: ディレクトリにコピーする情報(既定値は/DCOPY:DA)。(copyflags :D=データ、A=属性、T=タイムスタンプ、E=EA、X=代替データ ストリームをスキップ)。/NODCOPY:: ディレクトリ情報をコピーしません(既定では/DCOPY:DA が実行されます)。/NOOFFLOAD::Windows のオフロードをコピーするメカニズムを使用せずに、 ファイルをコピーします。/COMPRESS:: ファイル転送中にネットワーク圧縮を要求します(適用可能な場合)。/SPARSE:: コピー中にスパース状態を保持できるようにする:::: ファイル調整オプションをコピーします:::/IoMaxSize:n[KMG]::{read,write} サイクルあたりの最大i/oサイズが要求されました。(n[KMG] バイト)/IoRate:n[KMG]:: 要求されたi/oレート(n[KMG] バイト/秒)。 /しきい値:n[KMG]:: 調整のためのファイルサイズのしきい値です。n[KMG] バイト(「解説」を参照)。:::: ファイル選択オプション:::/A:: アーカイブ属性が設定されているファイルのみをコピーしま す。/M:: アーカイブ属性のあるファイルのみをコピーし、リセットしま す。/IA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルのみを含 みます。/XA:[RASHCNETO] :: 指定されたいずれかの属性が設定されているファイルを除外し ます。/XFfile[ファイル]... :: 指定された名前/パス/ワイルドカードに一致するファイルを 除外します。/XDdir[ディレクトリ]... :: 指定された名前/パスに一致するディレクトリを除外します。/XC:: 変更されたファイルを除外します。/XN:: 新しいファイルを除外します。/XO:: 古いファイルを除外します。/XX:: コピー先にだけ存在するファイルとディレクトリを除外し ます。/XL:: コピー元にだけ存在するファイルとディレクトリを除外し ます。/IS:: 同一ファイルを含みます。/IT:: 異常なファイルを含めます。/MAX:n :: 最大ファイル サイズ-n バイトより大きいファイルを除外し ます。/MIN:n :: 最小ファイル サイズ-n バイトより小さいファイルを除外し ます。/MAXAGE:n :: 最長ファイル有効期間-n 日より古いファイルを除外します。/MINAGE:n :: 最短ファイル有効期間-n 日より新しいファイルを除外しま す。/MAXLAD:n :: 最大最終アクセス日-n で指定する値以後に使用していない ファイルを除外します。/MINLAD:n :: 最小最終アクセス日-n で指定する値以後に使用されたファ イルを除外します。(n<1900 の場合、n=n 日です。それ以外は、n=YYYYMMDD の日付です)。/FFT::FAT ファイル時間(2 秒の粒度) を想定します。/DST::1 時間のDST 時間差を補正します。/XJ:: シンボリック リンク(ファイルとディレクトリの両方) と接合ポイントを除外します。/XJD:: ディレクトリのシンボリック リンクと接合ポイントを除外します。/XJF:: ファイルのシンボリック リンクを除外します。/IM:: 変更されたファイルを含めます(変更日時が異なる)。:::: 再試行オプション:::/R:n :: 失敗したコピーに対する再試行数: 既定値は1,000,000。/W:n :: 再試行と再試行の間の待機時間: 既定値は、30 秒です。/REG:: /既定の設定としてレジストリにR:n と/W:n を保存します。/TBD:: 共有名が定義されるのを待ちます(再試行エラー67)。/LFSM:: 空き領域不足モードで動作し、コピーの一時停止と再開を有効にします(「注釈」を参照)。/LFSM:n[KMG] ::/LFSM、 下限サイズをn[K:kilo,M:mega,G:giga] バイトで指定します。:::: ログ オプション:::/L:: リストのみ- いずれのファイルにも、コピー、タイムスタン プの追加、または削除を実施しません。/X:: 選択されたファイルのみではなく、余分なファイルをすべて報 告します。/V:: スキップされたファイルを示す詳細出力を作成します。/TS:: 出力にコピー元ファイルのタイム スタンプを含めます。/FP:: 出力にファイルの完全なパス名を含めます。/BYTES:: サイズをバイトで出力します。/NS:: サイズなし- ファイル サイズをログに記録しません。/NC:: クラスなし- ファイル クラスをログに記録しません。/NFL:: ファイル リストなし- ファイル名をログに記録しません。/NDL:: ディレクトリなし- ディレクトリ名をログに記録しません。/NP:: 進行状況なし- コピーの完了率を表示しません。/ETA:: コピーするファイルの推定完了時刻を表示します。/LOG:ファイル :: ログ ファイルに状態を出力します(既存のログを上書きしま す)。/LOG+:ファイル :: ログ ファイルに状態を出力します(既存のログ ファイルに 追加します)。/UNILOG:ファイル :: ログ ファイルにUNICODE で状態を出力します(既存のログを 上書きします)。/UNILOG+:ファイル :: ログ ファイルにUNICODE で状態を出力します(既存のログに 追加します)。/TEE:: コンソール ウィンドウとログ ファイルに出力します。/NJH:: ジョブ ヘッダーがありません。/NJS:: ジョブ要約がありません。/UNICODE:: 状態をUNICODE で出力します。:::: ジョブ オプション:::/JOB:ジョブ名 :: 名前の付いたジョブ ファイルからパラメーターを取得します。/SAVE:ジョブ名 :: 名前の付いたジョブ ファイルにパラメーターを保存します。/QUIT:: コマンド ラインの処理後に終了します(パラメーターの表示の ため)。/NOSD:: コピー元ディレクトリを指定しません。/NODD:: コピー先ディレクトリを指定しません。/IF:: 後続のファイルを含みます。:::: 注釈 ::: ボリュームのルート ディレクトリに対して/PURGEまたは/MIRを使用すると、これまでは、robocopy は要求された操作をシステム ボリューム情報ディレクトリ内のファイル にも適用していました。この動作は変更されました。 どちらかを指定すると、robocopy はその名前を持つファイルまたはディレクトリを(コピー セッションの最上位レベルのソースと宛先ディレクトリで) スキップします。 変更されたファイルの分類は、コピー元とコピー先両方の ファイル システムが変更タイムスタンプ(NTFS など) をサポートしていて、 コピー元とコピー先のファイルの変更日時が異なり、しかし それ以外は同じ場合に適用されます。これらのファイルは既定ではコピーされません。/IM を指定して、 それらを含めます。/DCOPY:E フラグは、拡張属性コピーを ディレクトリに対して試行することを要求します。現時点ではrobocopy が継続されます(ディレクトリのEA をコピーできなかった場合)。このフラグは/COPYALL内。/IoMaxSizeまたは/IoRate が指定されている場合、robocopy は 以下 を有効にします ファイルの調整をコピーします(システム負荷を減らすための目的)。 両方とも、許容値または最適値に調整できます。つまり、両方の 必要なコピーパラメーターを指定していますが、システムとrobocopy は 必要に応じて、これらの値を妥当/許容される値に調整し ます。/Thresholdも使用されている場合は、以下の最小ファイルサイズを指定します。 調整に従事することを可能にしています;そのサイズは調整されません。3つのすべてのパラメーターの値の後に省略可能なサフィックスを指定することができる場合もあります セット[KMG](キロ、メガ、giga) の文字。/LFSMを使用することで、robocopy に'空き領域不足モード' での動作を要求します。 このモードでは、次の場合にrobocopy が一時停止します。すなわち、ファイルのコピーによって 以下が生じる場合 コピー先ボリュームの空き領域が'下限' 値を下回る場合です。この値は フラグのLFSM:n[KMG] 形式によって明示的に指定できます。/LFSMが明示的な下限値なしで指定されている場合、下限は コピー先ボリュームのサイズの10%。 空き領域不足モードは、/MT、/EFSRAW と互換性がありません。/MIRの動作の変更
System Volume Infomationがデフォルトで除外。以下のサンプルでは除外で設定しているが、コピーはミラーリングのため、一応付けてある。
新しいファイル選択オプション
/IM 異なる更新日時のファイルを含む
Copyコマンドを使えばわかるが、作成日付はコピーされた日になる。このため、真の最終作成日時は更新日である。これに着目したオプション
/DCOPYの変更
/DCOPY:コピーフラグ :: ディレクトリにコピーする情報 (既定値は /DCOPY:DA)。(コピーフラグ: D= データ、A= 属性、T= タイムスタンプ)。
/DCOPY:コピーフラグ :: ディレクトリにコピーする情報 (既定値は /DCOPY:DA)。(copyflags : D=データ、A=属性、T=タイムスタンプ、E=EA、X=代替データ ストリームをスキップ)。
[2020 Windows 10 V1809/190x]空き容量不足モードの新設、/SJオプションの追加
Windows 10 V1809/190x: Preview Updates (September 16, 2020)
Windows 10, version 1809/190x: robocopy extensions
####The robocopy extensions
German blog reader jss has left the following information as a comment – so the new commands and options are probably fixed..
/IM:: Contains modified files (different modification times).
/LFSM :: Operation in “little free space” mode, allows copying, pausing and resuming (see comments).
/LFSM:n [CMM] :: /LFSM, specifies the floor size in [K:Kilo,M:Mega,G:Giga] bytes.
Besides that, the current 2004 robocopy help, according to the comment of jss, mentions two more switches that the 1809 does not throw out even with the update:
/SJ :: Copies connections as connections instead of as connection targets.
/COMPRESS :: Requests network compression during file transfer if necessary.
XP010のRobocopyはEmpty.exeを使おうとしていたのが原因
Windows 10 でメモリを自動的に解放してくれるMicrosoft純正ツール
Microsoft純正のメモリ解放ツールで重いWindowsPCを軽くする方法!
Windows Server 2003 Resource Kit toolsのempty.exeを利用する方法。
Windows10でインストールできた純正のメモリ解放ソフトResource Kit Toolsは現
まぁ、現状の環境だと、あまり効果的なものではありませんが・・・
Windows Server 2003の頃と比較したら、普通に4GB以上の8GBとか当たり前に積んでいる時代。
今だと、クライアント版では、Windows10ってOSで利用している人も多い。
Windows10 ver 1511以降ってメモリの圧縮プロセスがバックグランドで自動実行されちゃうんですよね・・・
https://www.atmarkit.co.jp/ait/articles/1711/21/ …
確かにやると若干だけ効果があるよ。
今ではempty.exeの効果は薄く、わざわざrktools.exeを入れてみる必要はない。自分も使ってみたがあまり効果がなく、メモリを開放する時点で処理が重くなるため安定しなかった。
しかし、これらの記事で参考にすべきなのはempty.exeそのものではない。
実行形式exeファイルからrobocopy.exeを取り出す。それをSystem32に入れる。さらにそれをCMD.exeだけでなく、バッチやVBSにする。さらに、タスクスケジューラに登録する。という流れである。この流れは現在でも価値がある。
さらに、最新版のRobocopy.exeもやはりタスクスケジューラに登録して自動実行するというサーバー管理者のテクニックがあるからである。記事の内容そのものより、一つの実行形式ファイルを取り出し、登録し、様々なスクリプトで活用する。この流れはWindowsの他の実行形式ファイルにも共通している。
ただし、それはWindows Server 2003 Resorce Kit Tools以外でやるほうが良い。
Windows Server 2003 リソースキットの compress.exe について
Windows 2003 リソースキットに含まれる compress.exe には問題があり、これを使用して圧縮したファイルの解凍 (expand.exe、LZCopy() 関数) に失敗する場合があります。Windows 2003 リソースキットに含まれる compress.exe を使用した場合、解凍が失敗するため、圧縮したファイルを復元することができません。本現象は、compress.exe 使用時に "-Z" パラメータを使用し、zip を指定した場合には発生しません。
なお、compress.exe は NTFS ボリュームではサポートされていません。
[Windows]
KZBY152 “ファイル”の処理で異常が発生しました。
このようにバグが放置されているし、NTSF似未対応というのは今日では流石に無理があると思う。
Robocopyのタスクスケジューラへの登録
ここも登録するだけではなく、それを止める方法、ネットワークドライブの権限などいろいろなポイントがある。
なので、まずempty.exeを登録して見るところから始めてみてもいいかもしれない。
それにしてもこのテーマについて2020年に絞ってもゴロゴロ記事が出てくるのは、Windows Serverが使いにくいからである。
この原因はWindowsがそもそもDOSであり、サーバーを管理する発送がないためである。こういうとろこでその弱さが出ている。WSLとか言っているのもLinuxに勝てないからではないか。
毎日12時にrobocopyでパソコンを自動的にバックアップする方法
robocopy の動作をタスクスケジューラで止める方法 | 新人SEの備忘録
ユーザーログオフ時にタスクスケジューラでネットワークドライブにrobocopyに失敗する
タスクスケジューラーでxcopyが動かなかった話
Windows – ROBOCOPYとタスクスケジューラでファイルを安全にバックアップする
古いエラー情報や解説
以下は削除されたものもあり、発表当時は該当しても今は違う場合があります。
プログラムが Windows Vista またはそれ以降のオペレーティング システムのユーザー アカウント制御を有効にした後いくつかのネットワークの場所にアクセスできない可能性があります。
Windows Vista Ultimate Windows Vista Business Windows Vista Enterprise Windows 7 Enterprise Windows 7 Professional Windows 7 Ultimate Windows 7 Home Basic Windows 7 Home Premium Windows Vista Home Basic Windows Vista Home Premium Windows 8
Programs may be unable to access some network locations after you turn on User Account Control in Windows Vista or newer operating systems
UAC(ユーザーアカウント制御)をWindows Vista以降のOSで有効にすると、いくつかのネットワークロケーションからプログラムがアクセスを拒否される場合がある
現象
Windows Vista またはそれ以降のオペレーティング システムのユーザー アカウント制御を有効にすると、プログラムはいくつかのネットワークの場所にアクセスできない場合があります。コマンドプロンプトを使用してネットワーク上の場所にアクセスした場合ででも、こ、この問題が発生する可能性があります。
編注:なんだこのヘルプは、これだけしか書いていない。なので英語から補う。
Symptoms
After you turn on User Account Control in Windows Vista or newer operating systems, programs may be unable to access some network locations. This problem may also occur when you use the command prompt to access a network location.
Note To turn on User Account Control, you click Allow in a User Account Control dialog box.
Cause
This problem occurs because User Account Control treats members of the Administrators group as standard users.
When a member of the Administrators group logs on to a Windows Vista-based and newer computer that has User Account Control enabled, the user runs as a standard user. Standard users are members of the Users group. If you are a member of the Administrators group and if you want to perform a task that requires a full administrator access token, User Account Control prompts you for approval. For example, you are prompted if you try to edit security policies on the computer. If you click Allow in the User Account Control dialog box, you can then complete the administrative task by using the full administrator access token.
When an administrator logs on to Windows Vista or newer, the Local Security Authority (LSA) creates two access tokens. If LSA is notified that the user is a member of the Administrators group, LSA creates the second logon that has the administrator rights removed (filtered). This filtered access token is used to start the user’s desktop. Applications can use the full administrator access token if the administrator user clicks Allow in a User Account Control dialog box.
If a user is logged on to Windows Vista or newer, and if User Account Control is enabled, a program that uses the user’s filtered access token and a program that uses the user’s full administrator access token can run at the same time. Because LSA created the access tokens during two separate logon sessions, the access tokens contain separate logon IDs.
When network shares are mapped, they are linked to the current logon session for the current process access token. This means that, if a user uses the command prompt (Cmd.exe) together with the filtered access token to map a network share, the network share is not mapped for processes that run with the full administrator access token.
Workaround
To work around this issue, use the net use command together with a UNC name to access the network location. For example, at a command prompt, type the following command, and then press Enter:net use \\< computername >\< sharename > /user:< username >
この問題は、ユーザーアカウント制御がAdministratorsグループのメンバーを標準ユーザーとして扱うために発生します。
Administratorsグループのメンバーが、ユーザーアカウント制御が有効になっているWindows Vistaベースの新しいコンピューターにログオンすると、ユーザーは標準ユーザーとして実行されます。標準ユーザーは、Usersグループのメンバーです。 Administratorsグループのメンバーであり、完全な管理者アクセストークンを必要とするタスクを実行する場合は、ユーザーアカウント制御によって承認を求められます。たとえば、コンピュータのセキュリティポリシーを編集しようとすると、プロンプトが表示されます。 [ユーザーアカウント制御]ダイアログボックスで[許可]をクリックすると、完全な管理者アクセストークンを使用して管理タスクを完了することができます。
管理者がWindowsVista以降にログオンすると、ローカルセキュリティ機関(LSA)は2つのアクセストークンを作成します。ユーザーがAdministratorsグループのメンバーであることがLSAに通知されると、LSAは、管理者権限が削除(フィルタリング)された2番目のログオンを作成します。このフィルタリングされたアクセストークンは、ユーザーのデスクトップを起動するために使用されます。管理者ユーザーが[ユーザーアカウント制御]ダイアログボックスで[許可]をクリックすると、アプリケーションは完全な管理者アクセストークンを使用できます。
ユーザーがWindowsVista以降にログオンしていて、ユーザーアカウント制御が有効になっている場合、ユーザーのフィルター処理されたアクセストークンを使用するプログラムと、ユーザーの完全な管理者アクセストークンを使用するプログラムを同時に実行できます。 LSAは2つの別々のログオンセッション中にアクセストークンを作成したため、アクセストークンには別々のログオンIDが含まれています。
ネットワーク共有がマップされると、それらは現在のプロセスアクセストークンの現在のログオンセッションにリンクされます。つまり、ユーザーがコマンドプロンプト(Cmd.exe)をフィルター処理されたアクセストークンと一緒に使用してネットワーク共有をマップする場合、完全な管理者アクセストークンで実行されるプロセスにはネットワーク共有がマップされません。
回避策
この問題を回避するには、netuseコマンドをUNC名と一緒に使用してネットワークの場所にアクセスします。たとえば、コマンドプロンプトで次のコマンドを入力し、Enterキーを押します。net use \\< computername >\< sharename > /user:< username >
Windows Server 2012 で Robocopy/MIR を使用する場合、FSRM およびデータ重複除外機能しなくなる
Windows Server 2012 Datacenter Windows Server 2012 Datacenter Windows Server 2012 Standard Windows Server 2012 Standard
概要
/MIRオプションと共に Robocopy ユーティリティを使用して、Windows Server 2012 で、Robocopy はコピー先のディレクトリにソース ディレクトリを反映します。最初に、ソース ディレクトリに存在しない宛先ディレクトリ内のすべての内容は削除されます。ユーザーがアクセスできるすべてのファイルは、インストール先ディレクトリにソース ディレクトリからコピーされます。ユーザーがアクセスできないファイルとフォルダーをコピーするには、Robocopy の/Bまたは/ZBオプションを使用する必要があります。
< N > の: ボリュームが全体をコピーするのには < q: > ターゲット ・ ボリュームに/MIRオプションを使用すると、ミラーリング ・ プロセスは、システム ボリューム情報フォルダーに適用されます。これは、いくつかのファイル サーバーの機能が重要なメタデータを格納する場所です。ミラーリング ・ プロセスの削除段階は、ターゲット ・ ボリューム上のシステム ボリューム情報フォルダーに格納されているメタデータが失われる可能性があります。さらに、コピー ・ ミラーリング ・ プロセスのフェーズがターゲット ・ ボリュームにコピーされるソース ・ ボリュームに固有のメタデータがあります。この現象は、ファイル サーバー上の各種サービスが妨害されます。たとえば、次のサービスが影響を受けます。
ファイル サーバー リソース マネージャー (FSRM)
FSRM のクォータ、ファイル スクリーン、およびその他の構成情報をシステム ボリューム情報フォルダーに格納します。フォルダーが削除された場合、クォータ、ファイル スクリーン、およびその他の構成情報は適用されません、ターゲット ・ ボリュームにします。
データ重複除外
データ重複除外機能は、システム ボリューム情報フォルダーに共通のチャンクのストアを維持します。フォルダーが削除された場合、最適化されたファイル (再解析ポイント)、ソース ・ ボリュームからコピーされるため、破損ターゲット ・ ボリュームへのデータ ・ チャンクがコピーされません。
ソース ・ ボリュームはターゲット ・ ボリュームでは、有効なデータ重複除外を持っていない場合に問題が発生するさらに、またはその逆。例を次に示します。
サンプル コマンドでは、P: は、有効にすると、データ重複除外がないボリュームで M: は、データ重複除外が有効になっているボリュームです。
次のコマンドを実行します。
robocopy P: M: /MIR M:\System /L
ボリュームの情報が削除されたことになります。したがって、M: 上の重複ファイルが壊れています。
(編注:なぜ実行させるんだ。このヘルプは実行してはだめなものばかり)
次のコマンドを実行します。
robocopy P: M: /MIR /ZB M:\System Volume InfoMation
ボリューム Information\Dedup を削除することになります。したがって、M: 上の重複ファイルが壊れています。
次のコマンドを実行します。
robocopy M: P: /MIR /ZB
重複除外機能のすべてのメタデータが P:\System ボリュームの Information\Dedup フォルダーにコピーされることになります。チャンクの Id を格納するため両方のボリュームは、同じ、問題が発生する将来的に移行します。
これらの例の問題を回避するのにには、システム ボリューム情報フォルダーをコマンドのスコープから除外するのには、 /XD オプションを使用します。たとえば、次のコマンドでは、システム ボリューム情報フォルダーが除外されます。robocopy P: M: /MIR [/ZB] /XD "System Volume Information"
「Robocopy/B」は Windows 7 および Windows Server 2008 R2 に ACL などのセキュリティ情報をコピーできません
現象
次のような状況を考えます。
- ドメインのバックアップ オペレーター グループまたはローカルの Backup Operators グループにユーザー アカウントを追加するとします。
- Windows 7 または Windows Server 2008 R2 を実行しているコンピューターにログオンするには、このアカウントを使用します。
- 必要はありませんアクセス許可または所有権のいくつかのファイルをコピーするのには、 /Bオプションと共にRobocopyコマンドを使用します。
- エラー 5 (0x00000005) < ディレクトリ名 >のアクセスをインストール先ディレクトリに NTFS のセキュリティのコピーが拒否されました
- エラー 5 (0x00000005) リンク先のファイルの< ディレクトリ名 >のアクセスに NTFS のセキュリティのコピーが拒否されました
Backup Operators グループのメンバーがファイルをコピーするのには、 /Bオプションと共にRobocopy.exeユーティリティを実行するときに注意してください、すべてのものをコピーする必要があります。メンバーは、メンバーは、ファイルまたはファイルの所有権へのアクセス許可を持っていない場合でも、ファイルのセキュリティの構成情報へのアクセスにすることが必要です。
原因
この問題は、 Robocopy.exeユーティリティは、 /Bオプションを使用する場合、「バックアップ ・ インテント」フラグを使用してこれらのファイルを開くしないためにに発生します。この動作により、「バックアップ ファイルとディレクトリ」を持っているユーザーのセキュリティ構成情報にアクセス (SE_BACKUP_PRIVILEGE) の特権。
関連
Windows XPから7にして以降、ネットワークドライブに設置したROBOCOPYを呼び出すバッチファイルが動作しなくなった
/XCTの解説がある記事(削除されたTechnet)
/dcopy:T コピー ディレクトリのタイムスタンプ。
/xct変更されたファイルを除外します。/xn新しいファイルを除外します。/xo古いファイルを除外します。/xxその他のファイルやディレクトリを除外します。/xl「寂しい」のファイルやディレクトリを除外します。/is同じファイルが含まれています。/it「微調整」のファイルが含まれています。
/Dcopy:Tとしかしていない。/XCが/XCTとなっている。
もう一つ重要なのが、以下の解説。
解説
- mirオプションと、/e および /purgeオプションでは、1 つの小さな違いを除き同じ動作をします。
- コピー先ディレクトリが存在する場合、/e および /purgeのオプションでは、コピー先ディレクトリのセキュリティ設定は上書きされません。
- コピー先のディレクトリが存在する場合は、 /mirオプションでは、移動先ディレクトリのセキュリティ設定が上書きされます。
CopyとXcopyの違い
コマンドラインでxcopyよりもcopyを使用する利点は何ですか
- Copyはファイルを連結させることができる。
- `copy con file` ファイルに直接キーボードから書き込める
- `copy file prn` 共有プリンター `copy file \\computer\printer` ファイルの印刷
- `copy con prn`プリンタに直接書き込み
- xcopyがフォルダ階層をコピーできることと、copyがファイルのみを処理することを意図していたことです(またはそうでした)
- 倍密度フロッピーディスクPCのDOSを覚えていますか? Xcopyは、1回の読み取りで複数のファイルをメモリにロードしてコピーを高速化することにより、読み取りシークの数を最小限に抑えます。おそらくまだHDDで些細な速度の改善を行います
- Powershellを「コマンドライン」と考える場合はシェルレベルで深く埋め込まれたワイルドカードを展開する`copy G:\git\one\source\*\morePath\SomePattern*.dll destDir`
- [クリップボード リダイレクト (コピーと貼り付け) を使用してリモート デスクトップ サービスまたはターミナル サービス セッションを使用して 2 GB を超えるファイルをコピーすると、サイレント モードで失敗する](https://docs.microsoft.com/ja-jp/troubleshoot/windows-server/remote/copying-2-gb-file-by-clipboard-redirection-fails)
ドキュメント トラブルシューティング Windows Windows Server リモート デスクトップ サービス リダイレクト (プリンターではない)
2020/09/08
この記事では、クリップボードリダイレクトを使用してリモート デスクトップ サービスまたはターミナル サービス セッションを使用して 2 GB を超えるファイルをコピーできない問題を回避するためのヘルプを提供します。
つまりコピー&ペーストでは2GB以上のファイルはエラーを起こして失敗する可能性があり、Xcopyの仕様が推奨されている。
XcopyとRobocopyの違い
- リダイレクトさせなくてもLOGオプションでログが作成できる。ログの内容も指定できる。
- 更新日時で比較して、ソースのほうが新しい更新されたファイルだけをコピーするので、2回目以降のバックアップが速い。それをオプションで変更できる。
- ミラーリング機能があるので、バックアップ元でファイルを削除すると、バックアップ先でも同じように削除してくれる。
- /R:100000 /W:30がデフォルトのため、ファイルコピーに失敗した時でも再試行できる。というか、制限しないと終わらない。
- /CopyALLや/DCopy:DATを指定することで、ファイルやフォルダのアクセス権限もコピーできる。
- デフォルトは、ファイルのパスが256文字を超えてもエラーにならない(逆にジャンクションを除外しないと、無限に長いフォルダを作成する)
Windowsが長いファイル名から8.3ファイル名を生成する方法
記事ID:142982
2007年1月19
Microsoft Windows Millennium Edition
Microsoft Windows 98 Standard Edition
Microsoft Windows 95
Microsoft Windows NT Server 4.0 Standard Edition
Microsoft Windows NT Workstation 4.0 Developer Edition
この記事は以前にQ142982で公開されました
概要
Windowsは、最大255文字の長いファイル名をサポートします。Windowsは、MS-DOS互換(短い)ファイル名を8.3形式で生成し、MS-DOSベースまたは16ビットのWindowsベースのプログラムがファイルにアクセスできるようにします。
詳細
Windowsは、次の方法で長いファイル名から短いファイル名を生成します。
Windowsは、ファイル名から無効な文字とスペースを削除します。無効な文字は次のとおりです。。"/ \ [] :; =、短いファイル名にはピリオド(。)を1つしか含めることができないため、有効な場合、Windowsはファイル名から追加のピリオドを削除し、スペース以外の文字がファイル名の最後のピリオドの後に続きます。たとえば、Windowsは短いファイル名を生成しますThisis〜1.txt長いファイル名からこれは本当に長いファイル名です。123.456.789.txtそれ以外の場合、Windowsは最後の期間を無視し、最後の期間の次を使用します。たとえば、Windowsは短いファイル名を生成しますこれは〜1.789長いファイル名からこれは本当に長いfilename.123.456.789です。Windowsは、必要に応じてファイル名を6文字に切り捨て、チルダ(〜)と数字を追加します。たとえば、作成された一意のファイル名はそれぞれ「〜1」で終わります。重複するファイル名は「〜2」、「〜3」などで終わります。Windowsは、ファイル名拡張子を3文字以下に切り捨てます。Windowsは、ファイル名と拡張子のすべての文字を大文字に変換します。フォルダまたはファイル名にスペースが含まれているが8文字未満の場合でも、Windowsは短いファイル名を作成することに注意してください。このようなファイルやフォルダにネットワーク経由でアクセスしようとすると、この動作によって問題が発生する可能性があります。この状況を回避するには、スペースをアンダースコア(_)などの有効な文字に置き換えます。これを行うと、Windowsは別の短いファイル名を作成しません
たとえば、長いファイル名にはスペースが含まれているため、「Afile〜1.doc」は「Afile.doc」から生成されます。
ファイル名に含まれる文字が8文字未満であり、スペースが含まれていないため、「A_file.doc」から短いファイル名は生成されません。
短いファイル名「Alongf〜1.txt」は、長いファイル名「Alongfilename.txt」から生成されます。長いファイル名に8文字以上含まれているためです。
追加のクエリワード:4.0 lfn
キーワード:kbinfo kbui KB142982
ショート ファイル名とロング ファイル名の両方が使用されているコピー元からファイルをコピーするとファイルが失われることがある
Files may be lost when you copy files from a source that uses both short file names and long file names
https://support.microsoft.com/*195144
Microsoft KB Archive/195144
Contents
1 Files may be lost when you copy files from a source that uses both short file names and long file names
1.1 SYMPTOMS
1.2 CAUSE
1.3 RESOLUTION
1.3.1 Windows NT 4.0
1.3.2 Windows 2000 with Internet Explorer
1.3.2.1 Service pack information
1.3.2.2 Hotfix information
1.3.3 Windows 95 with Internet Explorer 4.0
1.4 WORKAROUND
1.4.1 Windows NT Backup
1.5 STATUS
Article ID: 195144
https://support.microsoft.com/ja-jp/help/195144
Article Last Modified on 11/1/2006
APPLIES TO
- Microsoft Windows 2000 Server
- Microsoft Windows NT Workstation 4.0 Developer Edition
- Microsoft Windows NT Server 4.0 Standard Edition
- Microsoft Windows NT Server 4.0 Enterprise Edition
- Microsoft Windows 95
This article was previously published under Q195144
1.1SYMPTOMS
When you copy files from a source that uses both short file names and long file names, files may be lost.
This problem can occur when you perform the copy operation by using any of the following programs:
- COPY
- XCOPY
- Windows NT Explorer
- Windows NT Backup
1.2CAUSE
This problem happens when a file that has a long file name is copied and a new short file name is generated for the file in the destination folder. If a file exists in the source folder and it has a name matching the newly generated short file name, this file will replace the first file and the content of the first file is lost. For example:
Source Directory : C:\source> dir /x 08/21/98 02:03p <DIR> . 08/21/98 02:03p <DIR> .. 08/20/98 02:32p 17 YXXXXX~1.XXX 08/20/98 02:32p 7 YXXXXX~2.XXX yxxxxxxxxx.xxx 4 File(s) 14 bytes C:\source> copy *.* c:\dest yxxxxxxxxx.xxx YXXXXX~1.XXX 2 file(s) copied. C:\source> dir c:\dest 09/15/98 09:27a <DIR> . 09/15/98 09:27a <DIR> .. 08/20/98 02:32p 17 YXXXXX~1.XXX yxxxxxxxxx.xxx 3 File(s) 17 bytesNote The yxxxxxxxxx.xxx file is copied first, and the short file name generated for that is YXXXXX~1.XXX. When the copy program copies YXXXXX~1.XXX to the destination, it finds a match in file name and replaces the existing file with its contents.
In NTBackup, if the short named file and the NTFS converted long file names are the same, you are prompted whether to replace the existing file or not. Overwriting the file may result in data loss as the file names will be the same but the contents will not be.
1.3RESOLUTION
1.3.1 Windows NT 4.0
To resolve this problem, obtain the latest service pack for Windows NT 4.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
152734 How to obtain the latest Windows NT 4.0 service pack
1.3.1.1 Windows 2000 with Internet Explorer
Service pack information
To resolve this problem, obtain the latest service pack for Windows 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
260910 How to obtain the latest Windows 2000 service pack
1.3.2.2 Hotfix information
The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.
Date Time Version Size File name------------------------------------------------------------- 5/11/2001 10:51a 5.0.3315.1000 2,337,552 Shell32.dll1.3.3 Windows 95 with Internet Explorer 4.0
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that this article describes. Apply it only to systems that are experiencing this specific problem.
To resolve this problem, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:
Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The P1 version of this P2 has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time item in Control Panel.
Date Time Size File name Platform ------------------------------------------------------------- 03/02/99 06:40p 1,431,264 Shell32.dll (Windows 95)Note These hotfixes only fix copy operations that are performed by using Windows NT Explorer. By design, the behavior of COPY and XCOPY is unchanged.
1.4WORKAROUND
To work around this problem, turn off automatic short file name generation. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
210638 How to disable automatic short file name generation
1.4.1 Windows NT Backup
If the files that have short file names were created by legacy applications, and you cannot upgrade these applications, use the FAT formatted partitions on Windows NT servers for compatibility with these applications. Use share-level security. You can also use different folders for files that have long file names and files that have short file names.
1.5STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in Windows NT 4.0 Service Pack 5 and in Windows 2000 Service Pack 3.
Additional query words: kbShell 4.00
Keywords: kbhotfixserver kbqfe kbbug kbfix kbshell kbwin2000sp3fix KB195144
Robocopy GUI版2006
https://web.archive.org/web/20090206192617/https://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx
2006年11月に発表された。UtilitySpotlights2006_11.exeの中に含まれている。
しかし、その後の情報がほとんどない。
前述のとおり、n-archives.netでGUI版が開発され、Windows20にも対応しているため、これを試験する意味は内容だ。
私が思う最大の利点は、不要なファイルをコピーすることなく、2つのファイル構造(選択した場合はすべてのサブディレクトリとファイルを含む)の完全なミラー複製を作成できることです。ソースの場所で新しいファイルまたは更新されたファイルのみがコピーされます。 Robocopyを使用すると、日付とタイムスタンプ、セキュリティアクセス制御リスト(ACL)など、関連するすべてのファイル情報を保持することもできます。
もちろん、私たちは皆、さまざまな方法で仕事をするのが好きです。コマンドラインを好む人もいますが、その人にとっては、出荷時のRobocopyツールが最適です。ただし、他の人はよりポイントアンドクリック指向であり、その群衆のために、RobocopyGUIがあります。 Robocopyへのこの歓迎すべきアドオンは、MicrosoftのMSNSearchグループのシステムエンジニアであるDerkBenischから提供されたものです。 Derkのユーティリティを使用すると、ユーザーは、シンプルで非常に見慣れたグラフィカルインターフェイスを使用してRobocopyスクリプトをカスタマイズできます(図1を参照)。
これらはすべて、従来のRobocopyコマンドライン機能で確実に実行できる機能ですが、多くの場合、オプションをグラフィカルインターフェイスに統合すると、プロセスが大幅に簡素化される可能性があります。
Robocopy GUIは、既存のRobocopyツールの機能をいくつかの非常に興味深い方法で拡張します。たとえば、このツールはマルチスレッド化されているため、Robocopyスクリプトを作成して実行し、最初のスクリプトの実行中に別のスクリプトの作成を開始できます。また、スクリプトを保存して(実際に実行しなくても)、一般的なスクリプトのライブラリを作成したり、同僚と共有したりすることもできます。そして最も重要なことは、Robocopy GUIを使用するとデフォルト設定を保存できるため、毎回最初からやり直す必要がありません。
Robocopy GUIには、独自のヘルプファイルと、完全なRobocopyリファレンスガイドの埋め込みコピーが含まれています。このリファレンスには、すべてのRobocopyコマンドと構文の完全なインデックスが含まれており、利用する設定を決定するのに役立ちます。
これらの便利な機能をすべて備えたRobocopyGUIは、ITプロフェッショナルのツールボックスに最適です。
Windows7 および Windows server 2008
Windows7 及び Windows Server 2008のRobocopyhaディレクトリツリーの複製をすると動作が遅延する
http://support.microsoft.com/kb/2646535
Significantly slower directory tree replication performance when you use the Robocopy command in Windows 7 or in Windows Server 2008 R2
SYMPTOMS
On a computer that is running Windows 7 or Windows Server 2008 R2, the performance of directory tree replication is significantly slower when you use the Robocopy command compared to earlier versions of Windows.
Windows7またはWindowsServer 2008 R2を実行しているコンピューターでは、Robocopyコマンドを使用すると、以前のバージョンのWindowsと比較してディレクトリツリーレプリケーションのパフォーマンスが大幅に低下します。
CAUSE
This issue occurs because additional code was added to copy extended attributes and alternative data streams for directories.
この問題は、ディレクトリの代替データストリームをコピーの属性複写オプションが拡充され、コードが追加されたために発生します。
Resolution
This hotfix adds the following copy options to the Robocopy command:
| Copy options | Descriptions |
|---|---|
| /nodcopy | copies no directory information |
| /dcopy: copy flags | The following copy flags are added: D copies directory data A copies directory attributes |
Note /dcopy:T was included in the Robocopy command.
Notes
The default behavior of earlier versions of Robocopy (the versions that are included in Resource Kits, in Windows Vista, and in Windows Server 2008) is the same behavior as using the /DCOPY:A option.
The default Robocopy behavior in Windows 7 and in Windows Server 2008 R2 (in the released versions and the hotfixed versions) is the same as using the /DCOPY:DA option.
To return Robocopy performance to an amount that is closer to earlier versions of Robocopy, you have to add the /DCOPY:A option to all Robocopy commands.
To improve Robocopy performance even more, use the /NODCOPY optioninstead of the /DCOPY:A option. This provides the best performance, but at the expense of not copying the DOS-style attributes, the extended attributes, and the alternae data streams of directories. Few applications depend on DOS-style attributes for directories. Therefore, if the source directories have no associated extended attributes or alternate data streams, the attempts to copy these attributes and data streams can be safely omitted.
Copying the NTFS file system access control list security information is requested by specifying the /SEC or /COPY:S option.
以前のバージョンのRobocopy(リソースキット、Windows Vista、およびWindows Server 2008に含まれているバージョン)のデフォルトの動作は、 DCOPY:Aオプションを使用した場合と同じ動作です。
Windows7およびWindowsServer 2008 R2(リリースバージョンおよびホットフィックスバージョン)でのデフォルトのRobocopy動作は、/ DCOPY:DAオプションを使用した場合と同じです。
Robocopyのパフォーマンスを以前のバージョンのRobocopyに近いレベルに戻すには、すべてのRobocopyコマンドに/DCOPY:Aオプションを追加する必要があります。
Robocopyのパフォーマンスをさらに向上させるには、/DCOPY:Aオプションの代わりに/NODCOPYオプションを使用します。これにより最高のパフォーマンスが得られますが、DOSスタイルの属性、拡張属性、およびディレクトリの代替データストリームをコピーしないという犠牲が伴います。ディレクトリのDOSスタイルの属性に依存するアプリケーションはほとんどありません。したがって、ソースディレクトリに関連する拡張属性または代替データストリームがない場合、これらの属性およびデータストリームをコピーする試みは安全に省略できます。
/SECまたは/COPY:Sオプションを指定して、NTFSファイルシステムのアクセス制御リストのセキュリティ情報をコピーするように要求されます。
When you request to copy the security information of files, security information of directories is also copied. This is the same behavior from earlier versions of Robocopy.
In Windows 7 and in Windows Server 2008 R2, copying security information of directories is only performed the first time that a target directory is copied or created. Earlier versions of Robocopy copied the NTFS access control list security information for all existing directories. However, this created too much NTFRS replication churn if the Robocopy target was also involved in NTFRS replication.
In Windows 7 and in Windows Server 2008 R2, you can force replication of NTFS access control lists for all directories by adding the /MIR option to Robocopy commands that copy security.
ファイルのセキュリティ情報のコピーを要求すると、ディレクトリのセキュリティ情報もコピーされます。 これは、以前のバージョンのRobocopyと同じ動作です。
Windows7およびWindowsServer 2008 R2では、ディレクトリのセキュリティ情報のコピーは、ターゲットディレクトリが初めてコピーまたは作成されたときにのみ実行されます。 以前のバージョンのRobocopyは、既存のすべてのディレクトリのNTFSアクセス制御リストのセキュリティ情報をコピーしました。 ただし、RobocopyターゲットがNTFRSレプリケーションにも関与している場合、これによりNTFRSレプリケーションチャーンが多すぎます。
Windows7およびWindowsServer 2008 R2では、セキュリティをコピーするRobocopyコマンドに/MIRオプションを追加することにより、すべてのディレクトリのNTFSアクセス制御リストのレプリケーションを強制できます。
/MIRimplies/PURGE. Therefore, adding the /MIR option to existing Robocopy commands can cause files and whole directory trees to be deleted if they exist at the destination, but not at the source. Use the/MIRoption with caution, because items that are deleted by using/MIRcannot be undeleted.In Windows 7 and in Windows Server 2008 R2, you cannot force NTFS access control lists for all directories to replicate unless you specify
/MIRand delete additional items from the destination./MIRは/PURGEを意味します。 したがって、既存のRobocopyコマンドに/MIRオプションを追加すると、ファイルとディレクトリツリー全体が宛先に存在するがソースには存在しない場合に削除される可能性があります。 /MIRを使用して削除されたアイテムは元に戻せないため、/MIRオプションの使用には注意が必要です。Windows7およびWindowsServer 2008 R2では、
/MIRを指定して宛先から追加のアイテムを削除しない限り、すべてのディレクトリのNTFSアクセス制御リストを強制的に複製することはできません。
Hotfix information
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing the problem described in this article. This hotfix might receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next software update that contains this hotfix.
If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, contact Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft website:
http://support.microsoft.com/contactus/?ws=support
Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language.
Prerequisites
To apply this hotfix, you must be running one of the following operating systems:
- Windows 7
- Windows 7 Service Pack 1 (SP1)
- Windows Server 2008 R2
- Windows Server 2008 R2 Service Pack 1 (SP1)
For more information about how to obtain a Windows 7 or Windows Server 2008 R2 service pack, click the following article number to view the article in the Microsoft Knowledge Base:
976932 Information about Service Pack 1 for Windows 7 and for Windows Server 2008 R2
Registry information
To apply the hotfix in this package, you do not have to make any changes to the registry.
Restart requirement
You must restart the computer after you apply this hotfix.
Hotfix replacement information
This hotfix does not replace a previously released hotfix.
File information
The global version of this hotfix installs files that have the attributes that are listed in the following tables. The dates and the times for these files are listed in Coordinated Universal Time (UTC). The dates and the times for these files on your local computer are displayed in your local time together with your current daylight saving time (DST) bias. Additionally, the dates and the times may change when you perform certain operations on the files.(中略)
WORKAROUND
To work around this issue, use the Robocopy command that was included in an earlier version of Microsoft Resource Kit.
この問題を回避するには、以前のバージョンのMicrosoft ResourceKitに含まれていたRobocopyコマンドを使用します。
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
編注
これまた今まで知られていなかったWindows7の情報である。ときにはなんと以前のバージョンを使えと言っていたのだった。
Windows8.1時代のROBOCOPY"## Windows 8.1 または Windows 8 で、Robocopy コマンドを使用して [SharePoint パス] 下のファイルを別のコンピューターにコピーできません。
Windows 8.1 Enterprise Windows 8.1 Pro Windows 8.1 Windows RT 8.1 Windows Server 2012 R2 Datacenter Windows Server 2012 R2 Essentials Windows Server 2012 R2 Foundation Windows Server 2012 R2 Standard Windows 8 Enterprise Windows 8 Pro Windows 8 Windows RT Windows Server 2012 Datacenter Windows Server 2012 Datacenter Windows Server 2012 Essentials Windows Server 2012 Foundation Windows Server 2012 Foundation Windows Server 2012 Standard Windows Server 2012 Standard 減らす
現象
次のような状況を考えます。
- Windows RT 8.1、8.1 の Windows、Windows Server 2012 R2、Windows RT、Windows 8 では、または Windows Server 2012 にコンピューターを配置するとします。
- 展開されているコンピューターに次のコマンドを使用してディレクトリ ツリーをコピーしようとするとします。
Robocopy「ソース」の「宛先」/E/R:2/S/MIR- ディレクトリ ツリーには、SharePoint のパスが含まれています。
このシナリオでは、SharePoint で関連するファイルのパスをコピーすることはできません。
解決策
この問題を解決するには、2962409、更新プログラムのロールアップをインストールまたは更新プログラムのロールアップ 2962407 をインストールします。これらの更新プログラムのロールアップ パッケージを入手する方法の詳細については、以下の資料、マイクロソフト サポート技術情報番号のいずれかをクリックします。
Windows RT 8.1、Windows 8.1 では、Windows Server 2012 R2 更新プログラムのロールアップ: 6 月の 2014年
Windows RT、Windows 8 では、Windows Server 2012 の更新プログラムのロールアップ: 6 月の 2014年
状況
マイクロソフトは、この問題を「対象製品」セクションに記載されているマイクロソフト製品の問題として認識しています。
Windows8 の robocopy の DCOPY オプションについて 2013/08/02
お世話になります。
Windows 7 ですと、robocopy のヘルプでは、/DCOPY には T オプションしかありません。
Windows 8 ですと、/DCOPY には D、A、T の3つのオプションが指定可能になっています。
ということは、Win 7 時代に作ったバッチファイルで、/DCOPY:T と書いてあるものがあるとすると、これを Win8 で実行した場合、D と A はコピーされないと解釈できます。
が、実際には、Win 8 で /DCOPY:T でディレクトリをコピーした場合にも、属性はコピーされていました。
あと、D オプションが意味する「ディレクトリのデータ」というのが何のことなのか、よくわかりませんが…。
属性がコピーされるのは、(Win8 から新設された /NODCOPY をつけない限り)robocopy の既定の挙動であるように思えます。
だとしたら /DCOPY:A って何なのでしょうか。
/# あと、ついでに /DCOPY:D も…
まだ調査中なのですが、時間がかかりそうなので、いったん〆ます。
このようなKBがありました。
http://support.microsoft.com/kb/2646535
robocopy のオプションはバージョンアップによって増えてきており、
- Windows Server 2003 Resource Kit Tools に含まれるものでは /DCOPY オプションは無し。
- Windows Vista / 7 世代では /DCOPY:T のみ。
Windows 8 世代からは /DCOPY:DAT が使用可能。
となっています。
で、/DCOPY を指定しない場合の既定のコピー動作はどうかと言えば、
- Windows Vista 世代以前では /DCOPY:A 相当
- Windows 7 世代以降では /DCOPY:DA 相当
となっています。つまり、Windows 8 世代において、
- Resource Kit Tools の動作を再現したい場合は /DCOPY:A
- Windows Vista 世代の動作を再現したい場合は /DCOPY:A ないしは /DCOPY:AT
を使用するということになります。
では /DCOPY:D とは何かという話ですが、どうやらこれは、ディレクトリの副次ストリームをコピーするかどうかを決めるフラグのようです。
副次ストリームには、Internet Explorer で使用される ZoneId をはじめとした情報が格納される代替データストリームや、ファイルのセキュリティ情報、リパース ポイント(シンボリック リンク等)の情報、POSIX 互換機能のための拡張属性などが入っているようです。
XP010~WindowsSever 2008 And Vistaのバグrobocopy 全角長音、半角長音、全角ダッシュが区別されない
robocopy 全角長音、半角長音、全角ダッシュが区別されない
Windows Server> Windows Server 2008
robocopyコマンドでデータ移行の検証を行っているのですが、ファイル名に全角長音”ー”、半角長音”ー”、全角ダッシュ”―”を含み、それ以外の文字列が同じファイルがある場合、コピーをすると、ファイルは区別されずにファイルが上書きされてしまいます。
具体的には、同じフォルダ内にrobocopyーtest.txt(全角長音)、robocopyーtest.txt(半角長音)、robocopy―test.txt(全角ダッシュ)というファイルを作成し、robocopyコマンドで他のドライブにコピーすると、コピー先にはrobocopy―test.txt(全角ダッシュ)だけが作成されます。
また、xcopyコマンドで同じことを試すと、3ファイルともコピー先に作成されました。
検証は以下の環境で実施いたしました。
OS:Windows Server 2008 SP2
robocopy.exe:ファイルバージョン 5.1.10.1027、製品バージョン 5.1.0.0、サイズ 85.5KB、言語 日本語(日本)
2011年8月30日 6:20
バッチファイルだと G:\Backup2というフォルダに新たにtestdir1とtestdir2というフォルダを作成
このバグはMicrosoft Windows 10.0.19042.804のような最新のバージョンはもちろん、これ以降のバージョンでは発生していない。
cd/dG:\BackUp2mkdirtestdir1mkdirtestdir2cdG:\BackUp2\testdir1cd/dG:\BackUp2mkdirtestdir1mkdirtestdir2cdG:\BackUp2\testdir1REM ファイルを作成しますか はい。作成して閉じるnotepad"robocopy―test.txt"pausenotepad"robocopyーtest.txt"pausenotepad"robocopyーtest.txt"pausec:\windows\system32\Robocopy.exeG:\BackUp2\testdir1g:\BackUp2\testdir2/copyallREM %PROGRAMFILES(X86)%\Windows Resource Kits\Tools\Robocopy.exe G:\BackUp2\testdir1 g:\BackUp2\testdir2 /copyallHot Fixed 2011
Robocopy.exe utility incorrectly skips some files during the file copy or backup process in Windows Vista or in Windows Server 2008 web.archive
http://support.microsoft.com/kb/2646454
Symptoms
Consider t\Windows Resource Kits\Tools>he following scenario:
You use the Robocopy.exe utility to copy or backup files on a computer that is running Windows Vista or Windows Server 2008.
The names of the files contain East Asian characters, for example Japanese characters.
In this scenario, some files may not be copied and the Robocopy.exe utility does not report an error.
Here is a sample scenario:
You have the following two files on a computer that is running Windows Vista or Windows Server 2008.
ー.txt ("chouon" character)
―.txt ("em dash" character)
-.txt ("en dash" character)
You try to copy these files to a destination folder by using the Robocopy.exe utility.
In this scenario, the Robocopy.exe utility incorrectly believes that their file names are identical and only one of the files is copied. Additionally, no error is reported.
Cause
This issue occurs because the Robocopy.exe utility uses an incorrect string comparison function when it copies files.
XP010ではこのエラーは発生する
実はこのエラーはXP010から存在していた。しかしHOTFIXの対象外のため、Windosws 2003 Resouce kit toolsのROBOCPY XP010ではこのエラーは発生する.
Prerequisites
To apply this hotfix, you must be running one of the following operating systems:
- Windows Vista Service Pack 1 (SP1)
- Windows Vista Service Pack 2 (SP2)
- Windows Server 2008
- Windows Server 2008 Service Pack 2 (SP2)
詳細なところは分かりませんが、検証された結果が全てではないかなと思います。
Windows Server 2008 R2 でも試してみましたが、同じような結果となりました。
(全角長音と全角ダッシュの組み合わせがダメみたいです)
意図的に試すとすぐに分かったのですが、実環境だとあまり遭遇する事がない、もしくは気づいていない、日本語環境特有の現象、等で情報が少ないのではと推測します。
つまりたまたま見つかっただけで、以前から存在していたということである。
Histroy 2009 RichCopy
フォルダを同期させるMS純正の高機能コマンド“robocopy”をGUIで「RichCopy
ROBOCOPY XP010
これが必要である趣旨
Windows Sever 2003 Resouce Kitに含まれているRobocopyのバージョンはXP010で古く/J,/DCopyといった重要なオプションがない`が、Windows10でも動く。
この解説は2003年のものだが、これ以降Microsoftにここまで詳細な解説はない。
XP010は後方互換や、UNIXを考慮している項目があり、マイクロソフトがRobocopyを出すとき、なにを意識していたのかがわかる。
Robocopy.exe |
Robocopy is a 32-bitcommand-line tool used for file replication. This tool helps maintain identicalcopies of a directory structure on a single computer or in separate networklocations. Robocopy is included in theMicrosoft® Windows® Resource Kit.
Important |
Robocopy version XP010 requires Microsoft® Windows® Server 2003,Microsoft® Windows® XP, Microsoft®Windows® 2000, or Microsoft® Windows NT® version 4.0.
Using Robocopy, you cancopy a single directory, or you can recursively copy a directory and itssubdirectories. The tool classifies files by whether they exist in the sourcedirectory, in the destination directory, or in both. In the latter case, thetool further classifies files by comparing time stamps and file sizes betweenthe source file and the corresponding destination file. You control whichclasses of files are copied.
If a file exists in boththe source and destination locations, by default Robocopy copies the file onlyif the two versions have different time stamps or different sizes. This savestime if the source and destination are connected by a slow network link. Youcan also specify that copies are restarted in the event of a failure, whichsaves even more time when your network links are unreliable.
Robocopy allows you to dothe following:
· Usefile names, wildcard characters, paths, or file attributes to include orexclude source files as candidates for copying.
· Excludedirectories by name or by path.
· Deletesource files and directories after copying (that is, move rather than copythem).
· Deletedestination files and directories that no longer exist in the source.
· Controlthe number of times the program retries an operation after encountering arecoverable network error.
· Schedulecopy jobs to run automatically.
· Specifywhen copying is to be performed.
· Monitora directory tree for changes.
· Selectivelycopy file data.
New Features in Robocopy Version XP010Command-line ReferenceUsage NotesBackwards CompatibilityUsing Robocopy Within a UNIX ShellProcessing a Directory Tree Retrying After a Failed Copy 12Specifying File and Directory Names 13Using Robocopy File Classes 14Using Precise File Times and Long File Names 15Working with File Attributes 16Maintaining True Replication 17Selectively Copying File Data 18Copying NTFS Security Information 18Moving Files 19Minimizing Directory Fragmentation 20Robocopy Job Files 20Scheduling Robocopy Jobs 23Monitoring a Directory Tree 24Controlling Bandwidth Usage 25Output Log 26Text Tags 27Run Summary 30Return CodeNew Features in Robocopy VersionXP010
Robocopy version XP010 includes a number ofenhancements. For example, you can now do the following:
· CopyJunctions – Volume Mount Points and Directory Links. By default these arecopied as normal directories, as it may not be possible to create an equivalentJunction in the destination, especially if the source and destination reside ondifferent machines. Copying a tree that contains a Volume Mount Point canresult in unexpectedly large volumes of data being copied.
Use/XJ if you would prefer Robocopy toskip Junctions.
· Acton and modify more file attributes.
In addition to supportfor the R, A, S, and H attributes:
/XA and/IA now also accept and select on the following addition fileattributes:
C – Compressed files
N – files Not contentindexed
E – Encrypted files
T – Temporary files
O – Offline files
/A+ and/A- now also accept and modify the following additional attributetype:
N – files Not contentindexed
T – Temporary files
· Selectfiles based on their Last Accessed Dates.
/MAXLAD:n excludes files with a LastAccess Date older than n.
/MINLAD:n excludes files with a LastAccess Date newer than n.
If n < 1900, n istaken to be a time span in days.
If n >= 1900, nmust be a date in the form YYYYMMDD
· Copya new class of file : “Tweaked” files.
Use/IT to include and process Tweakedfiles.
A Tweaked file isdefined to be one that exists in both the source and destination,
with identical sizeand timestamp, but different attribute settings.
Form more informationsee “Robocopy File Classes” later in this document.
· Copyvery long path names (longer that 256 characters).
Previousversions of Robocopy would fail to copy any pathname longer than 256characters. The program has now been enhanced to handle pathnames of anylength, up to the internal Windows limit of nearlt 32,000 characters.
· Getbetter information on data volumes for large copies.
Previousversions of Robocopy used 32-bit counters which would overflow when more than 2gigabytes of data was processed, resulting in incorrect output in the runsummary. This version now uses 64-bit counters to avoid this problem.
· Moreeasily correlate Robocopy errors to network errors.
Robocopynow displays the date and time that errors occur to assist in tracking downcommunication problems.
· Recovermore quickly and robustly from file copy failures.
Thisversion of Robocopy now timestamps destination files with a January 1980 dateduring copies. Thus, if a copy of a newer file is interrupted and re-run, thedestination file will seem to be older than the source file and be copiedcorrectly.
· Copyfiles in Backup Mode.
Use the/Bswitch to copy all files in Backup Mode. Use the/ZB switch to try to copy files in Restartable Mode (for greaterresiliency), and automatically switch to Backup Mode if the Restartable copyfails with an “Access Denied” error.
Note |
You must have the Backup Files and Restore Filesprivileges to copy files in Backup Mode using/B or/ZB.
Note |
Backup mode copies are not restartable, but theyenable you to copy some files as a Backup Operator that you would not be ableto copy as a normal user.
· Create,Edit, View, and take parameters from Robocopy Job (.RCJ) Files.
Use the/SAVE:jobswitch to save parameters to a Job file.
Use the/JOB:job switch to take parameters fromone or more Job files.
Use the /JOB:joband/SAVE:job switches together to edit a Job file.
Use the/QUIT switch to end execution afterprocessing command line arguments.
Use the/JOB:job and/QUIT switches together to view the contents of a job file.
Use the/NOSD to create a Job template with noSource Directory.
Use the/NODD to create a Job template with noDestination Directory.
Robocopy Job (.RCJ)files are simple text files that can also be edited manually.
For more information,see “Job Files” later in this document.
· Monitorthe source directory tree for changes, and copy changes when they occur.
Usethe/MON:n switch to specify the minimum number of changes that mustoccur before running again.
Usethe/MOT:m switch to specify the minimumtime, in minutes, that must elapse before running again.
If youonly specify one of these switches, the other is assumed to have a value of 1.
WhenMonitoring is specified, Robocopy never terminates. Instead, it enters a loopthat performs a normal Robocopy pass and then monitors the source directorytree for changes, until bothn changes have been detected andmminutes have elapsed.
Thiswhole process of copying and monitoring is repeated, ad infinitum, until theuser manually terminates the Robocopy process.
For more information,see “Monitoring a Directory Tree” laterin this document.
· Controlbandwidth usage.
Use/RH:hhmm-hhmm to specify Robocopy runhours.
When Run Hours have been specified, Robocopy willonly start new copies when the local system time is between the two specifiedtimes.
Use the/PFswitch to tell Robocopy to check its run hours on a Per File basis.
By default Robocopy will check its run hours on aper pass basis.
Use the/IPG:nswitch to specify an Inter-Packet Gap of n milliseconds.
Robocopy will then sleep for the given time intervalbetween each 64k chunk of file data transferred. This can be used to free upsome bandwidth on slow links.
For more information,see “Controlling Bandwidth Usage” later in this document.
· Exercisemore granular control over what is copied,
· CopyNTFS File Ownership Information, and
· CopyNTFS File Auditing Information.
Use the/COPY:[D][A][T][S][O][U] switch to specifyexactly what to copy.
The flags listed copy fileData,Attributes,Timestamps, NTFSSecurity (ACLs), NTFSOwnership information, and NTFSaUditing information,respectively.
Some previous versions of Robocopy were able tocopy NTFS ACLs. This version adds the ability to copy NTFS Ownership andAuditing information as well.
Use the/COPYALLswitch to copy everything (equivalent to/COPY:DATSOU).
Use the/NOCOPYswitch to copy nothing (this can be useful with/PURGE).
The default is/COPY:DAT, or/COPY:DATSif/SECis specified.
Note |
If file Data is copied, then file Timestamps arealso copied.
Note |
The/TIMFIXor/SECFIX switches are no longersupported. If you have scripts that use these switches you must edit them touse/COPY:instead./COPY:Treplaces the old/TIMFIX, and/COPY:Sreplaces the old/SECFIX.
Note |
You must have the Manage Audit Logs privilege tocopy file auditing information using/COPYALLor/COPY:U.
· Controlwhat is written to the output log.
Usethe/TS (Time Stamps) switch toinclude source file timestamps in the output.
Usethe/FP (Full Paths) switch toinclude full file pathnames in the output.
Usethe/NC (No Classes) switch toremove Robocopy file classes from the output.
Usethe/NS (No Sizes) switch to removefile and directory sizes from the output.
Use the/NFL(No File List) switch to suppress logging of file names.
Use the/NDL(No Directory List) switch to suppress logging of directory names.
Use the /NJH(No Job Header) switch to suppress output of the job header.
Use the /NJS(No Job Summary) switch to suppress output of the job summary.
Note |
File copy failures will still be logged even if/NFL is used.
Note |
If/NDLis used on its own, log files will contain fewer lines, but may use more diskspace, as full pathnames of files will be logged instead of simple names.
· Logoutput to both the console window and a log file on disk, simultaneously.
Use/TEE to request simultaneous output to boththe screen and also a log file specified by/LOG or/LOG+. Thisenables you visually monitor progress in a small console window on screen,while the full log is also written to disk.
Command-line Reference
To run Robocopy, use the following syntaxat the command prompt:
ROBOCOPYsource destination [file [file]...] [options]
The following table defines these syntaxelements.
Variable | Meaning | Comments |
| ||
source | Source directory | You can usedrive:\path or \\server\share\path |
destination | Destination directory | You can use drive:\path or \\server\share\path |
file | Names of files to act upon | You can use wildcard characters (? and*). If no files are listed, Robocopy defaults to all files (*.*). |
options | Command-line options you wish to use | Available options are described later in this document. |
Tip |
To view brief usage instructions at the commandprompt, runROBOCOPY withoutspecifying any command-line options.
The following table defines the command-lineoptions that you can use with Robocopy.
Switch | Function Performed |
| |
/S | Copies subdirectories (excluding empty ones). |
/E | Copies all subdirectories (including empty ones). |
/LEV:n | Copies only the topn levels of the source directory tree. |
/Z | Copies files in restartable mode (that is, restarts the copy process from the point of failure). |
/B | Copies files in Backup mode (Backup copies are not restartable, but can copy some files that restartable mode cannot). |
/ZB | Tries to copy files in restartable mode, but if that fails with an “Access Denied” error, switches automatically to Backup mode. |
/COPY:copyflags | Copies the file information specified bycopyflags, which can be any combination of the following : D – file Data. S – file Security (NTFS ACLs). A – file Attributes. O – file Ownership information. T – file Timestamps. U – file aUditing infomation. Source and destination volumes must both be NTFS to copy Security, Ownership or Auditing information. If no this switch is omitted the default is/COPY:DAT,or /COPY:DATS if/SEC is specified.. |
/COPYALL | Copies Everything. Equivalent to /COPY:DATSOU. |
/NOCOPY | Copies Nothing. Can be useful with /PURGE. |
/SEC | Copies NTFS security information. (Source and destination volumes must both be NTFS). Equivalent to /COPY:DATS. |
/MOV | Moves files (that is, deletes source files after copying). |
/MOVE | Moves files and directories (that is, deletes source files and directories after copying). |
/PURGE | Deletes destination files and directories that no longer exist in the source. |
/MIR | Mirrors a directory tree (equivalent to running both/E and/PURGE). |
/A+:{R|A|S|H|N|T} | Sets the specified attributes in copied files. The following attributes can be set: R – Read only S – System N – Not content indexed A – Archive H – Hidden T – Temporary |
/A-:{R|A|S|H|N|T} | Turns off the specified attributes in copied files. The following attributes can be turned off: R – Read only S – System N – Not content indexed A – Archive H – Hidden T – Temporary |
/CREATE | Creates a directory tree structure containing zero-length files only (that is, no file data is copied). |
/FAT | Creates destination files using only 8.3 FAT file names. |
/FFT | Assume FAT File Times (2-second granularity). Useful for copying to third-party systems that declare a volume to be NTFS but only implement file times with a 2-second granularity. |
/MON:n | Monitors the source directory for changes, and runs again whenn changes have been detected, and the minimum time interval specified by/MOT has elapsed. |
/MOT:n | Monitors the source directory for changes, and runs again when a furthern minutes have elapsed, and the minimum number of changes specified by/MON have been detected. |
/RH:hhmm-hhmm | Defines the time slot during which starting new copies is allowed. Useful for restricting copies to certain times of the day. Both values must be 24-hour times in the range 0000 to 2359. |
/PF | Makes more frequent checks to see if starting new copies is allowed (per file rather than per pass). Useful in stopping copy activity more promptly at the end of the run hours time slot. |
/IPG:n | Inserts a delay ofn milliseconds after each 64k chunk of file data is copied. Useful for freeing up bandwidth on slow lines. |
/IA:{R|A|S|H|C|N|E|T|O} | Includes files with the specified attributes. The following file attributes can be acted upon: R – Read only A – Archive S – System H – Hidden C – Compressed N – Not content indexed E – Encrypted T – Temporary O - Offline |
/XA:{R|A|S|H|C|N|E|T|O} | Excludes files with the specified attributes. The following file attributes can be acted upon: R – Read only A – Archive S – System H – Hidden C – Compressed N – Not content indexed E – Encrypted T – Temporary O - Offline |
/A | Copies only files with the archive attribute set. |
/M | Copies only files with the archive attribute set and then resets (turns off) the archive attribute in the source files. |
/XJ | Excludes Junction points. |
/XFfile [file] | Excludes files with the specified names, paths, or wildcard characters. |
/XDdir [dir] | Excludes directories with the specified names, paths, or wildcard characters. |
/XC | Excludes files tagged as “Changed”. |
/XN | Excludes files tagged as “Newer”. |
/XO | Excludes files tagged as “Older”.. |
/XX | Excludes files and directories tagged as “Extra”. |
/XL | Excludes files and directories tagged as “Lonely”. |
/IS | Includes files tagged as “Same”. |
/IT | Includes files tagged as “Tweaked”. |
/MAX:n | Excludes files larger thann bytes. |
/MIN:n | Excludes files smaller thann bytes. |
/MAXAGE:n | Excludes files with a Last Modified Date older thann days or specified date. Ifn is less than 1900, thenn is expressed in days. Otherwise,n is a date expressed as YYYYMMDD. |
/MINAGE:n | Excludes files with a Last Modified Date newer thann days or specified date. Ifn is less than 1900, thenn is expressed in days. Otherwise,n is a date expressed as YYYYMMDD. |
/MAXLAD:n | Excludes files with a Last Access Date older thann days or specified date. Ifn is less than 1900, thenn is expressed in days. Otherwise,n is a date expressed as YYYYMMDD. |
/MINLAD:n | Excludes files with a Last Access Date newer thann days or specified date. Ifn is less than 1900, thenn is expressed in days. Otherwise,n is a date expressed as YYYYMMDD. |
/R:n | Specifies the number of retries on failed copies. (The default is 1 million.) |
/W:n | Specifies the wait time between retries. (The default is 30 seconds.) |
/REG | Saves/R:n and/W:n in the registry as default settings. |
/TBD | Waits for share names to be defined on a “Network Name Not Found” error. |
/L | Lists files without copying, deleting, or applying a time stamp to any files. |
/X | Reports all files tagged as “Extra”(including files not selected). |
/V | Produces verbose output (including skipped files). |
/TS | Displays source file timestamps in the output log. |
/FP | Displays full pathnames of files in the output log. |
/NC | Suppresses output of Robocopy file classes. |
/NS | Suppresses output of file and directory sizes. |
/NDL | Turns off logging of directory names. Full file pathnames (as opposed to simple file names) will be shown if /NDL is used. |
/NFL | Turns off logging of file names. File names are still shown, however, if file copy errors occur. |
/NJH | Turns of logging of the job header. |
/NJS | Turns off logging of the job summary. |
/NP | Turns off copy progress indicator (% copied). |
/ETA | Shows estimated time of completion for copied files. |
/LOG:file | Redirects output to the specified file, overwriting the file if it already exists. |
/LOG+:file | Redirects output to the specified file, appending it to the file if it already exists. |
/TEE | Displays output in the console window, in addition to directing it to the log file specified by /LOG or /LOG+. |
/JOB:job | Reads parameters from the named Job file. |
/SAVE:job | Writes the current parameter settings to the named Job file. |
/QUIT | Quits after processing the command line. No files will be copied. Use /QUIT with /JOB to view job file contents. |
/NOSD | Declares that no source directory is specified. Useful in template Jobs for which the source is provided at run time. |
/NODD | Declares that no destination directory is specified. Useful in template Jobs for which the destination is provided at run time. |
/IF | Includes files with the specified names, paths, or wildcard characters. Intended for use in Job files only. |
/SD:path | Explicity specifies the source directory for the copy. Intended for use in Job files only. |
/DD:path | Explicitly specifies the destination directory for the copy. Intended for use in Job files only. |
Usage Notes
Thefollowing sections provide more details about using the command-line options totailor Robocopy to match your needs.
BackwardsCompatibility
This version of Robocopy was developed and tested under MicrosoftWindows XP.
The recommended minimum operating system platform for this versionof Robocopy is therefore Microsoft Windows XP, or Microsoft Windows Server2003.
Robocopy uses only standard, publicly documented Win32 APIsthroughout. For example, the program uses CopyFileEx() to copy files, andFindFirstFile() and FindNextFile() to read directories. In theory, Robocopyshould run on any operating system that supports these APIs, such as Windows NTversion 4.0 and Windows 2000.
However if you choose to run this version of Robocopy on Windows NTversion 4.0 or Windows 2000, please be aware that only limited testing wasperformed on these platforms, and Robocopy’s theoretical performance may differfrom practical results.
Note |
AsRobocopy uses the CopyFileEx() Win32 API,it can not run on Windows NT 3.1, Windows NT 3.5x, nor Windows 95, Windows 98 or Windows ME.
Using Robocopy Within a UNIXShell
You can specify all Robocopy switches inUNIX style (for example,-ETA instead of/ETA). You canalso specify source and destination directory paths using the UNIX delimiter(/), rather than the native Windows delimiter (\).
The only restriction is that any argumentthat begins with a UNIX slash mark (/) is treated as a switch if the argumentcontains only a single slash mark (/). In other words, /dir is treated as a switch; but //server/share/dir and /download/test aretreated as paths.
This avoids any possible confusion betweenswitches and single-level paths subordinate to the root of a drive. To specifya directory as an argument, you must use an alternate expression for its path,such asX:/dir or//server/C$/dir.
Processing a Directory Tree
Bydefault, Robocopy processes only the single source directory specified on thecommand line. To process the entire directory tree, including subdirectories,use/S or/E. To limit the copy to only the topn levels of the source directory tree, use/LEV:n.
Forexample /LEV:2 will cause Robocopy to process the top two directory levelsonly, i.e. just the root directory of the source and any directory directlyunder the root. Subdirectories of directories under the root will not beskipped.
Bydefault Robocopy will handle file and directory path names up to almost 32,000characters in length. If for any reason you wish to disable this support forvery long path names, use the/256switch. This causes Robocopy to revert to normal path name semantics, and amaximum path name length of 256 characters.
Ifthe/256 switch is used and Robocopyencounters a path name longer than 256 characters, one of the following errorsmay be reported, depending on the operation being performed on the very longpath name at the time :
The filename, directory name, or volume label syntax is incorrect.
The system cannot find the file specified.
The file name or extension is too long.
While walking a directorytree, Robocopy may encounter Junctions in the file system. These may be VolumeMount Points created using the MOUNTVOL command, or Directory Links createdusing the LINKD command. Robocopy handles Junctions in the source by creating anormal Directory of the same name in the destination, because it may not bepossible to replicate the Junction in the destination. This is often the caseif the source and destination are on different machines, as the target volumeor directory of the Junction may not exist on the destination machine. Notethat copying Junctions in this way can result in unexpectedly large volumes ofdata being copied if, for example, the source directory tree contains a VolumeMount Point. You can disable processing of Junctions by specifying the/XJswitch, which causes Robocopy toexclude Junctions from further processing. If/XJ is specified, Junctions are skipped.
RetryingAfter a Failed Copy
When a copy operation fails and returns anerror, Robocopy waits and then retries the operation until it succeeds or untilthe retry limit is reached. The defaults are a 30-second wait and up to 1million retries.
Changing Default Retry Parameters
Use the/W:n switch to change thewait time (in seconds) between retries, wheren is a positive decimalinteger, or zero (0) if you do not want any wait time between retries.Similarly, use the/R:n switch to change the retry limit.If an invalid value is given for/Wor/R, Robocopy uses the defaultvalue.
To change the default retry parameters, usethe/REGswitch on a valid Robocopy command that specifies non-default values for/W and/R. When/REG is used, the values you specify for/W and/R are stored in the registry and used as default values for/W and/R in future Robocopy runs where/W and/R arenot specified on the command line. Youcan always specify/W or/Rto override the stored settings.
Handling “Network Name Not Found” Errors
Robocopy does not automatically retry all failedoperations. Certain errors in some operations are not retried, where practicalexperience indicates that this would be futile. For example, the “Network NameNot Found” error usually indicates that a remote computer exists but does nothave a share with the given name. Because manual intervention is required tocreate a suitable share name on the remote computer, this error usually causesthe attempted operation to fail without a retry.
In some situations, however, this might notbe the desired action. For example, in a software publishing environment it iscommon to delete a share name, update the contents of the share, and thenrecreate the share name. In this scenario, you can use the/TBD switch to retry a copy operation when Robocopy encounters a “NetworkName Not Found” error.
Restarting from the Point of Failure
NormallyRobocopy will restart failed copies from the beginning of the file. You canoverride this default behaviour by specifying the/Z switch (or the/ZBswitch) which requests restartable copies - with/Z, failed copies will usually restart from close to the point offailure rather than the beginning of the file. See “Copying NTFS SecurityInformation” later in this document for more information on/ZB.
Note |
If you use/Z,/B, or/ZB, this can decrease Robocopy performance and throughputsignificantly, as these options involve extra overhead. These options aretherefore only recommended when experience indicates you really need them.
Specifying File and Directory Names
To specify a directory or file name or pathname that includes one or more spaces, you must enclose the entire file or pathname in quotation marks. For example:
ROBOCOPY “\\sales\reports\Fiscal 97” “C:\finance\Year End\sales” /XF “Budget96*.*”
Note |
Any file names that appear in the command linemust be specified as individual arguments separated from other arguments bywhite space, and not appended to the source or destination directory pathnames. If no such arguments appear in the command line, Robocopy defaults to allfiles.
By default, Robocopy treats all non-switchcommand-line arguments as file names, paths, or wildcard characters. Thesenames can be alternated with switch arguments, but the command line is easierto read when they are grouped together.
The command line is parsed from left toright. The meaning of any non-switch argument depends on where it appears withrespect to an/XF or/XD switch. Normally there must be twonon-switch arguments before any/XFor/XD switch, and these are treatedas the path names of the source and destination directories, respectively. Theonly exception is when/NOSD or/NODD is used as a directoryplaceholder to define a Template Job File. See “Robocopy Job Files” later inthis document for more details.
After the source and destination pathnames, and until Robocopy encounters an/XFor/XD switch, any non-switchargument is treated as either a file name or a wildcard character (but not apath) indicating one or more files to include as candidates for copying.
The/XFswitch specifies that all subsequent file names, paths, and wildcard charactersare files to exclude from copying until an/XDor /IF switch is found.
The/XDswitch specifies that all subsequent file names, paths, and wildcard charactersare directories to exclude from copying until an/XF or/IF switch isfound.
The/IF switch specifies that allsubsequent file names and wildcard characters are candidates for copying untilan/XD or/XF switch is found./IFis intended for use within Robocopy Job Files, but it can also be used on thecommand line.
The following table compares these subtledifferences in allowed values:
Argument | Names | Paths | Wildcard Characters |
Source directory | Yes | Yes | No |
Destination directory | Yes | Yes | No |
Files to include | Yes | No | Yes |
Files to exclude | Yes | Yes | Yes |
Directories to exclude | Yes | Yes | Yes |
The following example shows the correct useof these switches:
ROBOCOPY c:\source d:\dest *.c* /XF *.cpp /S /XD binc:\source\unwanted
In this example, Robocopy recursivelycopies the directory tree (including subdirectories) with the root c:\source,excluding the subdirectories bin and c:\source\unwanted. All files whoseextensions begin with c are copied, except files with the extension .cpp.
Using Robocopy File Classes
For each directory processed, Robocopyconstructs a list of files in both the source and destination directories. Thislist matches the files specified on the command line for copying.
Robocopy then cross-references the lists,determining where files exist and comparing file times and sizes. The programplaces each selected file in one of the following classes.
|
|
| Source/dest | Source/dest | Source/dest |
Lonely | Yes | No | n/a | n/a | n/a |
Tweaked | Yes | Yes | Equal | Equal | Different |
Same | Yes | Yes | Equal | Equal | Equal |
Changed | Yes | Yes | Equal | Different | n/a |
Newer | Yes | Yes | Source > destination | n/a | n/a |
Older | Yes | Yes | Source < destination | n/a | n/a |
Extra | No | Yes | n/a | n/a | n/a |
Mismatched | Yes (file) | Yes (directory) | n/a | n/a | n/a |
By default, Changed, Newer, and Older filesare candidates for copying (subject to further filtering, as described later).Same files are not copied. Extra and Mismatched files and directories are onlyreported in the output log.
Normally, Tweaked files are neither identifiednor copied – they are usually identified as Same files by default. Only when/IT is used will the distinction between Same and Tweaked files be made, andonly then will Tweaked files be copied.
Usethe following switches to override this default behavior.
Switch | Function Performed |
| |
/XL | Excludes Lonely files and directories. |
/IT | Includes Tweaked files. |
/IS | Includes Same files. |
/XC | Excludes Changed files. |
/XN | Excludes Newer files. |
/XO | Excludes Older files. |
/XX | Suppresses reporting and processing of Extra files. |
Note |
You do not need to specify any of these argumentsto include the current version of source files in the destination tree. In mostsituations, Robocopy includes these files by default.
The/XLswitch limits Robocopy to copying a file from the source directory treeonly when a corresponding file of the same name already exists in thedestination. This provides a convenient mechanism for maintaining a copy of aselected subset of the source tree. Using the/IS switch alone, with no other switches, forces a total refresh ofthe destination tree. Using the /IT switch provides a way to copy some Samefiles but not others by changing the attributes of those you wish to be copiedin either the source or the destination.
During a copy operation Robocopy places aJanuary 1980 time stamp on the destination file, and updates this to the sourcefile’s time stamp only when the copy is complete. If you quit Robocopy during acopy operation, any incompletely copied destination file will therefore have anearlier time stamp than its corresponding source file. If you restart the samecopy operation, Robocopy treats this file as an Newerfile and will therefore complete the interrupted copy, unless youhave specified /XN.
The most appropriate use for/XOis to synchronize two directorytrees so that they can be updated simultaneously in separate areas. To ensurethat the latest files are present in both directory trees, copy with/XO first in one direction and then inthe other.
You can use switches to exclude files basedon their size or time stamp./MAX:nexcludes files larger thann bytes,and/MIN:n excludes files smaller thann bytes. Similarly,/MAXAGE:n excludes files with a lastmodified date older thann and/MINAGE:n excludes fileswith a last modified date newer thann, wheren is either a time spanin days (ifn < 1900), or a date in the form YYYYMMDD (ifn>= 1900).
Similarly,/MAXLAD:n excludes fileswith a Last Accessed Date older thann and/MINLAD:n excludes fileswith a Last Accessed Date newer thann, wheren is either a time spanin days (ifn < 1900), or a date in the form YYYYMMDD (ifn>= 1900).
Using Precise File Times and Long FileNames
Although it is preferable to have both thesource and destination directories reside on NTFS partitions, you can useRobocopy to copy to other file systems, such as HPFS or FAT. If you do so,however, file times might be inaccurate due to rounding errors, and long filenames might not be preserved.
Handling FAT File Times on NTFS Drives
File-time granularity is 100 nanoseconds onNTFS, and two seconds on FAT, so copying a file from NTFS to FAT causes filetimes to be rounded to a value that the FAT file system can manage. When boththe source and destination volumes rea NTFS, file times are compared exactly.When either the source or destination volume is not an NTFS volume, Robocopyconsiders file times to be identical if they are within two seconds of eachother. Without this two-second margin, the program might classify manyotherwise unmodified files as Older or Newer files, which would result inunnecessary copying of unchanged files. Sometimes you need to override thishandling of file times. Suppose you copy an NTFS tree to a FAT volume, and thencopy the FAT tree (with its rounded file times) to a local NTFS drive. Later,when you want to recreate the original tree exactly, you do not want to refreshthe entire tree.
In this scenario, you can use the/IS and/COPY:T switchestogether to copy just file times independently of file data for Same files,rather than copying the files themselves again. See “Selectively Copying FileData” later in this document for more information on/COPY.
Some third-party operating systems declarethat their volumes are NTFS, but only implement FAT-style file times with a2-second granularity. When copying to such a destination from a true NTFSvolume, file time rounding may occur, along with unnecessary copying of filedata in subsequent jobs. If you encounter this situation, you can use the /FFT (FAT File Times) switch to tellRobocopy to consider file times to be identical if they are within 2 seconds ofeach other, even though both source and destination appear to be NTFS. Thiseliminates unnecessary copying in this scenario.
Handling Long File Names on FAT or HPFS Volumes
When the destination is on a FAT or HPFSvolume, you might experience problems copying files and directories with longnames or with names that include extended Unicode characters. To overcome theseproblems, use the/FAT switch. Thisswitch prompts Robocopy to create destination files with system-generated namesin the standard 8.3 FAT file system format.
Working with File Attributes
By default, Robocopy ignores most sourcefile attributes (read-only, archive, system, and hidden) when selecting filesto copy. Any file matching other specified conditions is copied regardless ofits attribute settings. You can use command-line switches to modify thisdefault behavior, as described in the following sections.
Including or Excluding Files Based on Specified Attributes
The/IA:{R|A|S|H|C|N|E|T|O}switch includes only files with one or more of the specified attributes set.Files that do not have any of the specified attributes set are excluded fromfurther processing and are not copied.
/IA can be useful in data staging applications. For example, you canspecify/IA:R to copy only read-onlyfiles from a test Web server to a live Web server. Developers can remove theread-only attribute from files on the test server while they edit and test thefiles. Until the read-only attribute is turned on again, these files are notreplicated on the live server.
Another switch,/XA:{R|A|S|H|C|N|E|T|O}, can be used to exclude files if one ormore of the specified attributes is set. For example, you can specify/XA:R to prevent read-only files frombeing copied. Similarly,/XA:SHexcludes files with either the system or hidden attribute set.
Any combination of the following fileattribute types can be used with/IAand/XA:
R – Read only files
A – Archive files
S – System files
H – Hidden files
C – Compressed files
N – files Not contentindexed
E – Encrypted files
T – Temporary files
O – Offline files
Note |
Robocopy processes/IA before/XA when bothswitches are specified in the same Robocopy command.
The/Aand/M switches allow only thosesource files with the archive attribute set to be selected for copying. Aftercopying, the archive attribute of the source file is either left set (if/A was used) or turned off (if/M was used).
Note |
Temporary files are normally deleted by theowning application when it is no longer needed. When present on the system theyare usually in use, and therefore copy delays or failures will often occur ifyou try to copy them.
Note |
Offline files have been physically removed tooffline storage, and severe delays may be encountered in copying them, whilethe system retrieves them.
Changing File Attributes After Copying
After a file has been successfully copiedto the destination, the attributes of the destination file are set by default tomatch those of the source file. To modify this default behavior, you can usetwo other switches:
/A+:{R|A|S|H|N|T} sets attributes, and
/A-:{R|A|S|H|N|T} resets or turns off attributes.
For example,/A+:A turns on the archive attribute in destination files (to makeit easier to back them up)./A-:RSH removes the read-only, system, and hiddenattributes from destination files (to make it possible to see and edit them).
The order of attribute operations on newlycopied destination files is as follows:
1. Attributes are copied to the destination filefrom the source file.
2. Attributes specified by/A+ are set (turned on).
3. Attributes specified by/A- are reset (turned off).
Any combination of the following fileattribute types can be used with/A+and/A-:
R – Read only files
A – Archive files
S – System files
H – Hidden files
N – files Not contentindexed
T – Temporary files
Maintaining True Replication
Ifyou require the destination directory tree to be maintained as anexact mirror of the source directorytree, you must delete files and directories from the destination whenever theydisappear from the source. To accomplish this, use the/E and/PURGE switchesin combination, or use the/MIRswitch
The /PURGE switch causes Robocopy todelete all Extra and Mismatched destination files and directories. After aMismatched destination entry has been deleted, the corresponding source entryis then treated as a Lonely file or directory and processed accordingly. When /PURGE results in the deletion of an Extraor Mismatched destination directory, the entire directory tree, including allsubordinate files and subdirectories, is deleted (even if/S or/E is notspecified).
Caution |
Use /PURGE and/MIR very carefully. If you inadvertently specify/PURGE or/MIR with an existing destination directory, Robocopy can quicklydelete a large amount of data from the destination.
Toprevent specific directory trees or files from being deleted when you use/PURGE, you must exclude them by name,using the/XD or/XF options./XD and/XF excludefiles and directories before all other processing.
Note |
Becausethe/XX switch excludes Extra filesfrom further processing, the/PURGEswitch has no effect when/XX isalso used.
SelectivelyCopyingFileData
Once a file has been selected for copying,you can choose precisely which data associated with the file is copied usingthe/COPY:copyflagscommand line argument,wherecopyflags can be any combination of the following :
· D to copy file Data
· A to copy file Attributes
· T to copy file Timestamps
· S tocopy NTFS Security information (ACLs)
· O tocopy NTFS Ownership information
· U tocopy NTFS aUditing information
For ease of use the following alternativeswitches are also provided :
· /COPYALL copies everything (equivalent to/COPY:DATSOU).
· /NOCOPYcopiesnothing (which can be useful if/PURGEis also used).
· /SEC copiesdata, attributes, and NTFS ACLs (like/COPY:DATS).
Any combination of these flags can be used,if you have the appropriate access rights. However, if file data is copied,file timestamps are also copied. By default Robocopy assumes/COPY:DAT,and will copy file data, attributes, and timestamps.
Note |
You musthave the Manage Audit Logs privilege to copy file auditing information using/COPYALL or/COPY:U.
Torefresh security information for existing destination files and directorieswithout copying file data, use the/ISswitch together with the/COPY switch without theD flag. For example/IS/COPY:SOUwould refresh all security information for all selected files, withoutcopying any file data.
Torefresh time stamps on existing destination files and directories withoutcopying file data, use the/ISswitch together with the/COPY switch without theD flag. For example/IS/COPY:Twould refresh all security information for all selected files, withoutcopying any file data.
Copying NTFSSecurity Information
Ifboth the source and destination directories reside on NTFS volumes, you can useRobocopy to copy NTFS security information. The most common requirement is topreserve NTFS ACLs during a copy. To do this, use the/SEC switch tocopy NTFS file permissions when you copy files to a destination for the firsttime. If you also need to preserve NTFS ownership and auditing information youshould use/COPYALL.
Note |
If eitherthe source or the destination volume is not NTFS, requests to copy securityinformation are ignored. Only one attempt is made to copy NTFS securityinformation for each file or directory copied.
Torefresh security information for existing destination files and directorieswithout copying file data, use the/ISswitch together with the/COPY switch without theD flag. For example/IS/COPY:SOUwould refresh all security information for all selected files, withoutcopying any file data. See “Selectively Copying File Data” earlier in thisdocument for more information on/COPY.
Whenyou copy security information, you might notice a short delay after Robocopyprints its banner and before it displays arguments on the screen. This delayoccurs because the program is checking for the NTFS file system at both ends.Copying NTFS file security information fails if you have insufficient accessprivileges at either the source or the destination.
Formore information about access privileges, see “Scheduling Robocopy Jobs” laterin this document.
Youcan copy security information between computers in separate domains even ifthey do not have trust relationships. However, this applies securityinformation that is unknown to the destination computer to the destination directorytree. When you view this information on the destination, user accounts areshown as “Account Unknown.” If you copy these permissions back to a computer inthe originating domain, they are interpreted correctly again.
Ifyou copy NTFS security information (ACLs) along with file data, it is possibleto copy files to which you have read access, but not write access. After such afile is copied once, and the ACLs are applied, you may find that to get an“Access Denied” error when you try to copy the file again.
Inthis situation you should use the/Bor/ZB switch to copy the files inBackup Mode.
/B copies all files with backup semantics (Backup Mode)./ZB first attempts to copy files inrestartable mode (for greater resiliency) but if that fails with an “AccessDenied” error it automatically retries the copy using Backup Mode.
Note |
You musthave the Backup Files and Restore Files privileges to copy files in Backup Modeusing/B or/ZB.
Note |
Backupmode copies are not restartable, but they enable you to copy some files as aBackup Operator that you would not be able to copy as a normal user.
Note |
If youuse/Z,/B, or/ZB, this candecrease Robocopy performance and throughput significantly, as these optionsinvolve extra overhead. These options are therefore only recommended whenexperience indicates you really need them.
MovingFiles
In some situations, you may want to movefiles instead of copying them, especially if disk space is at a premium on yournetwork. You can use the/MOVE switch to delete source files from thesource directory tree after they have been successfully copied to thedestination./MOVEalso deletes empty directories from the source directory tree.
Even with/MOVE specified,however, Robocopy deletes only those source files that it successfully copiesto the destination. There is no guarantee that a skipped source file isidentical to its corresponding destination file (even if the file times andsizes are identical) until immediately following a successful copy. For that reason,some files and directories (such as skipped Same files) might remain in thesource tree even when/MOVE is specified. You must determine whetherto delete the remaining entries, and do so manually.
Note |
To move files but still preserve the source directorytree structure, use/MOV instead of/MOVE.
Minimizing Directory Fragmentation
When you copy a directory tree for thefirst time, the files contained in each directory are copied into it as it iscreated. The directory entry for each file is created first, and then the filedata is copied.
If the tree contains large directories,however, this sequence can cause fragmentation of the directory structure. Whendisk allocation for the directory itself is expanded, the new directory extentcan be separated from the rest of the directory by large amounts of file data,which can reduce later file system performance significantly.
Use the/CREATE switch to minimize directory fragmentation when you copy alarge tree for the first time. When/CREATEis specified, Robocopy creates only the directory tree and zero-length files asplaceholders for the actual files. No file data is copied. Immediatelyfollowing a Robocopy command containing/CREATE,run the same command again without/CREATEto copy the file data to the destination.
Robocopy does not use/CREATE by default, because pre-creating a directory tree and thencopying file data takes more time than just copying the files. For directory trees
Note |
When using this technique, do not use/XO, because the zero-length filescreated by the initial/CREATEcommand are tagged as “Older” files on the second run.
Robocopy Job Files
Given the largenumber of command-line options available, it is easy to create Robocopycommands that are extremely long, and unwieldy to manipulate. Using RobocopyJob Files can greatly simplify matters.
Robocopy JobFiles are simple text files containing one Robocopy parameter per line, thatyou can create, view, and edit manually using a text editor, or, more simply,you can use Robocopy itself for all of these tasks.
There are threebasic switches that are used in Robocopy Job File processing. The/SAVE:jobswitch tells Robocopy to save its current set of parameters to the named file,the/JOB:job switch tells Robocopy to readparameters from the named file, and the/QUITswitch tells Robocopy to terminate after processing the command line.
Note |
Both /SAVEand /JOBexpect the file to have a .RCJ suffix, and append a .RCJ suffix to the providedfilename if it does not have one.
For example,you may use a Robocopy command to back up source files as follows :
ROBOCOPY C:\SRC D:\SRC/E *.C* *.H*
To encapsulatethis command in a Robocopy Job File, you could do the following :
ROBOCOPY C:\SRC D:\SRC/E *.C* *.H* /SAVE:SBACKUP
This creates aRobocopy Job File named SBACKUP.RCJin the current directory that encapsulates all the Robocopy parameters youspecified prior to the /SAVE switch.
Note |
/SAVEis actioned as soon as it is encountered on the command line. Any arguments onthe command line after /SAVE willnot be saved.
Note |
/SAVEwrites to the specified file immediately, with no warning if the target filealready exists. Care should be taken that you do not overwrite existing fileswhen using /SAVE to create a newRobocopy Job File.
To run theresulting Robocopy Job File at a later date, assuming the same workingdirectory, the following command would suffice :
ROBOCOPY /JOB:SBACKUP
Actually, thecommand given above to create a Robocopy Job File might not be ideal, as afterprocessing the /SAVE switch andcreating the Robocopy Job File, Robocopy would continue on and run with thegiven parameters.
To just createthe Robocopy Job File without running the job, you can use the/QUIT switch as follows :
ROBOCOPY C:\SRC D:\SRC/E *.C* *.H* /SAVE:SBACKUP /QUIT
To view theverbatim contents of the generated .RCJ file you can either load it into a texteditor (e.g. by running NOTEPAD SBACKUP.RCJ)or display its contents in the console window (e.g. by running TYPE SBACKUP.RCJ).
Alternatively,you can get a more succinct idea of its contents by running :
ROBOCOPY /JOB:SBACKUP /QUIT
This causesRobocopy to load the file, display its parameters, and then quit.
To edit a jobfile, you can use /JOB/SAVE and /QUIT together asfollows :
ROBOCOPY /JOB:SBACKUP /XF *.HLP /SAVE:SBACKUP /QUIT
This loads thenamed job, adds parameters to exclude .HLP files from the job, and updates iton disk.
Alternatively,you can edit job files using a text editor. The format of Robocopy Job Files isstraightforward. They contain one Robocopy parameter per line (parameterscontaining colons, e.g. /LOG:logfileor /MAX:n,count as one parameter and must be specified on a single line, with no spacesaround the colon). Leading white space is ignored, as is any text after twoconsecutive colons, which is considered to be a comment. View aRobocopy-generated .RCJ file to examine the format in more detail.
MultipleRobocopy Job Files can be specified on the Robocopy command line. For example,you might have a large list of files to be excluded from copying. You could usean editor to create a text file containing this exclusion list as follows :
/XF
file1
file2
file3
...
Once this issaved with a .RCJ suffix, e.g. EXCLUDE.RCJ,it can be used in conjunction with other Robocopy Job Files, for example asfollows :
ROBOCOPY /JOB:SBACKUP/JOB:EXCLUDE
Note |
When multiple job files are used, their contentsare cumulative. For example if a job specifies /XA:R and is used in conjunction with another that specifies /XA:SH then the result will be /XA:RSH.This also means that you must make sure that only one source directory and onlyone destination directory is specified in any set of job files that are usedtogether.
It is sometimesuseful to create Robocopy Job Files that can be used as templates for similartypes of copies, and for this purpose it is perfectly valid to save a job filewithout specifying a source directory or destination directory or both. Such ajob file cannot be run on its own, of course, unless the source and destinationdirectories are specified at run time.
For example:
ROBOCOPY *.c* *.h* /SAVE:SBACKUP /QUIT
Could be usedcreate a template job SBACKUP.RCJfor backing up source files.
To use thistemplate to back up different projects you might later run:
ROBOCOPY /JOB:SBACKUPC:\PROJECTS\PROG1 D:\PROJECTS\PROG1
ROBOCOPY /JOB:SBACKUPC:\PROJECTS\PROG2 D:\PROJECTS\PROG2
However, if thelist of files you wish to include contains a specific file name (as opposed towild cards like *.c*), such asMAKEFILE, then this approach will fail. You mightattempt to create such a template job as follows:
ROBOCOPY *.c* *.h* MAKEFILE /SAVE:SBACKUP/QUIT
The problemhere is that Robocopy assumes that the first three non-switch, non-wild cardarguments are the source pathname, the destination pathname, and the first of alist of files to include, repectively, and therefore will assume that MAKEFILE is the source directory, rather than afilename to include.
To handle thissituation you can use the/NOSD and/NODD switches in place of the sourceand destination directories respectively. In the example above you should usethe/NOSD switch to declare that noSource Directory is being specified, and the/NODD switch to declare that no Destination Directory is beingspecified, as follows:
ROBOCOPY /NOSD /NODD *.c* *.h* MAKEFILE/SAVE:SBACKUP /QUIT
Obviously, botha source directory and a destination directory must be specified, so/NOSD and/NODD are only useful in the creation of template job files.However, template job files can be a powerful tool, as multiple job files canbe specified on a single Robocopy command line.
Extending theexample of backing up source files further, you could create a template jobapecifying file section options, then further jobs for specific source codeprojects:
ROBOCOPY /NOSD /NODD *.c* *.h*MAKEFILE /SAVE:SB /QUIT
ROBOCOPY C:\PROJECTS\PROG1 D:\PROJECTS\PROG1/SAVE:P1 /QUIT
ROBOCOPY C:\PROJECTS\PROG2 D:\PROJECTS\PROG2/SAVE:P2 /QUIT
Etc…
Such a jobstructure would enable you to back up your projects simply and consistentlyusing brief commands like the following:
ROBOCOPY /JOB:SB/JOB:P1
ROBOCOPY /JOB:SB/JOB:P2
Etc…
This is just anintroduction to Robocopy Job Files with simple and straightforward examples,but their flexibility an open-endedness enables large and complicated jobs tobe created and managed with ease.
Scheduling Robocopy Jobs
You can create Robocopy jobs that runregularly and automatically in the background to maintain local mirrors ofremote directory trees. In Windows 2000, use theAT command, or use theSOONcommand with the Windows 2000 Schedule service. (TheSOON command runs Soon.exe, aWindows® 2000 Resource Kit tool named Near-Future Command Scheduler.)
By default, the Schedule service logs on asthe system account for the local system, which has no network access. Scheduledjobs run in the same context as the Schedule service. To run a scheduledRobocopy job, however, Robocopy must connect to network drives, which requiressome additional configuration. The following sections describe two ways toaccomplish this.
Using the Local System Account
You can leave the Schedule service runningin the context of the local system account. You can then schedule batch filesby using the following commands:
NET USE \\remoteserver\IPC$ /USER:userid password
ROBOCOPY\\remoteserver\sourcepath \\localserver\destpath ...
NET USE \\remoteserver\IPC$ /DEL
Within each job, credentials with remoteservers are validated by connecting to the IPC$ (Interprocess Communication)share on remote computers using an appropriate user account, rather than thelocal system account. The disadvantage of this approach is that user passwordsare stored in the batch files; however, passwords can be protected by storingthe batch files on an NTFS volume, and setting appropriate NTFS permissions onthe batch files.
Using a User Account
You can configure the Schedule service tolog on as a user account. Once the user account has been granted appropriateaccess to source and destination servers, you can schedule Robocopy jobs tocopy files between them.
To configure theSchedule service to log on as a user account
1. In Services in Control Panel, clickSchedule, and then clickStartup.
2. In theStartupType box, clickAutomatic orManual.
3. In theLogOn As box, select the account in which to run the service, and specify thecorrect logon password.
Tip |
Because drive mappings can be changed by users,it is more reliable to use UNC names for source and destination directories inscheduled Robocopy jobs. For example:
ROBOCOPY \\server1\share1\source\\server2\share2\dest …
Note |
The ATcommand and the Schedule service are documented in Windows 2000 onlineHelp. TheSOON command is documentedin theMicrosoft® Windows® 2000 Resource Kit.
Monitoringa Directory Tree
Usingthe/MON:n and/MOT:mswitches you can Monitor the source directory tree for changes, and copychanges as and when they occur. The/MON:n switch specifies the minimumnumber of changes that must occur before running again. The/MOT:m switch specifies the minimum time,in minutes, that must elapse before running again.
Ifyou only specify one of these switches, the other is assumed to have a value of1.
WhenMonitoring is specified, Robocopy never terminates. Instead, it enters a loopthat performs a normal Robocopy pass and then monitors the source directorytree for changes, until bothn changes have been detected andmminutes have elapsed. When both conditions are met, another Robocopy pass isstarted. This whole process of copying and monitoring is repeated, adinfinitum, until the user manually terminates the Robocopy process.
Asa minimum, Robocopy monitors the source directory tree for changes to file anddirectory names, sizes, and last write times. If attributes are to be copiedRobocopy will also monitor the tree for attribute changes. Similarly, ifsecurity information is to be copied, Robocopy will also monitor the tree forsecurity changes.
Consequently,a user performing an edit and saving a single new file, for example, may causemultiple changes of various types to be reported back to Robocopy. Thereforesome experimentation may be required to determine appropriate threshold valuesfor/MON and/MOT for eachRobocopy job, especially those monitoring busy trees.
Controlling Bandwidth Usage
Usingthe/RH:hhmm-hhmmswitch to specify Robocopy’s Run Hours you can definea time slot in which starting new copies is allowed; outside of this time slotnew copies will not be started, and Robocopy will sleep, waiting for the starttime to come around.
Bothtimes must be in 24-hour format, must be exactly 4 digits long in the range 0000 to 2359, and must bedifferent so as to specify a minimum two-minute window in which new copies maybe started.
Forexample/RH:2200-0600 would specifythat copies can be started when the local system time is between 10 p.m. and 6a.m. (or, to be exact, between 10:00:00 p.m. and 06:00:59 a.m., as Robocopyonly looks at the hours and minutes components of the local system time whendeciding if starting new copies is allowed).
Bydefault Robocopy will check to see if it is within the defined Run Hours timeslot at the start of each Robocopy pass (i.e. before starting the initial copypass; and, if/MON or/MOTwere used, at the start of each subsequent copy pass).
Youshould use the/PFswitch if youwould like the Run Hours check to be performed before each individual file copyis started.
Oncea copy is actually started it alwaysruns to completion, and therefore it is probable that a copy pass or file copythat starts close to the end of the Run Hours time slot will not complete untilsome time after the end time specified. Experimentation may therefore berequired to determine an appropriate end time for your needs.
Themost obvious use of/RH is to limitRobocopy’s copy activity to a time slot that is outside of normal businesshours (e.g./RH:2200-0600), to limitRobocopy’s use of network bandwidth andimprove network performance for interactive users during the day. This isparticularly useful for Robocopy jobs that run for extended periods of time,for example those that process very large trees, or Monitoring jobs.
However,you can also use/RHto schedule ajob to start at a later time. For example, you could start Robocopy in acommand window with/RH:1900-1901just before you leave work to go home, and the job would start copying at 7pm, and run overnight.
Onvery slow links heavy Robocopy activity can easily consume large percentages tothe available network bandwidth, and seriously impact network performance. Insuch a case you can use the /IPG:n switch to specify an Inter-PacketGap ofn milliseconds.
Robocopyusually copies files in 64 kilobyte packets with no delay between receiving apacket and requesting the next. When/IPG is used Robocopy will wait for the giventime interval before requesting the next packet, thereby freeing up networkbandwidth. Again, experimentation may be required to determine an appropiatevalue for/IPG.
OutputLog
During a run, Robocopy creates an OutputLog that comprises a Job Header detailing the command line arguments used forthe job, a list of files and directories processed during the job, and a JobSummary that shows totals copied, etc. By default, Output Log is written to thecommand prompt. This output can be redirected to a file, either by using thestandard command-line operators (> or >>), or by using one of thecommand-line options:
· /LOG:fileredirects output to the specified file, overwriting the file if it alreadyexists.
· /LOG+:fileredirects output to the specified file, appending it to the file if it alreadyexists.
You can also use/TEE inconjunction with one of the above options. This causes Robocopy to log itsoutput to both the command prompt (for visual progress monitoring) and thespecified file (for a permanent record of the Robocopy run).
Aside from error reporting and retries,Robocopy produces one line of output per source file or directory. Lines fordirectories show the number of files in that directory specified for copying(where known) and the full path of the directory. Lines for files indicate thename of the file, the size of the file, and what was done with the file.
One line is also generated for eachMismatched file and directory and each Extra file and directory in thedestination. Lines for Extra files include the full path and name of the file.
By default, the only Extra files reportedare those that match files specified for copying on the command line. In mostcases, this is more efficient. For example, if you are refreshing CPP files,you probably do not need information about TXTfiles in the destination. If you want a list of all Extra files in thedestination, regardless of their type, use the/X switch.
No output is produced for skipped files. Toobtain a verbose listing that shows all source files specified for copying onthe command line, including skipped files, use the/V switch.
Robocopy provides copy progress information(% copied) by default. You can use the/NPswitch to suppress the display of progress information. This can be useful whenoutput is redirected to a file.
To see the start time of each file copy andthe estimated time of completion based on the observed throughput of previouscopies, use the/ETA switch. Times are displayed after thefile name in the format HH:MM – >HH:MM (start – >finish).
Finally, to obtain only a list of the filesthat would be copied (without actually copying them), use the/L switch.
This defaultcontents of the output log can be modified using the following command lineswitches :
· /TS displays the file timestamps forevery file processed.
· /FP replaces simple file names with fullfile pathnames in the output.
· /NS (No Sizes) suppresses output of filesizes.
· /NC (No Classes) suppresses output offile class “Text Tags” (see below).
· /NDL(No Directory List) suppressesoutput of the directory list. When/NDLis used, full pathnames of processed files are logged instead of the simplefile name, so that problems can be pinpointed. Because of this, note that logfiles can actually increase in size if/NDLis used. Directories deleted by/PURGE(or whichwould be deleted if/L was omitted, if/PURGE and/L were bothused) are always logged even if /NDLis used.
· /NFL(No File List) suppresses output offiles processed. File copy failures are still logged even if/NFL is used, so that problems can beisolated. Files deleted by/PURGE(or which would be deleted if /L wasomitted, if/PURGE and/L were both used) are always loggedeven if/NFL is used.
· /NJH(No Job Header) suppresses outputof the job header.
· /NJS(No Job Summary) suppresses outputof the job summary.
Combinations ofthese switches allow quite a bit of flexibility in terms of what is logged. Forexample, you could use/NDL /NC /NSto produce a list of just the full pathnames of files that were processedduring the run, or you could use/NDL/NFL to produce just the summary report for the run (see “Run Summary”below).
Text Tags
Each line in the output log begins with abrief text tag, which is formatted according to the following rules:
· Allcapital letters indicate an anomaly that should be investigated.
· Initialcapital letters indicate a file that was selected for copying.
· Alllowercase letters indicate a file that was skipped (displayed only if the/V switch is used).
The text tags that indicate copying areleft-aligned. Tags that indicate skipping are right-aligned. Tags that indicateanomalies are placed farther to the left than other tags. Error messages alwaysstart in the first column. This arrangement simplifies the task of scanningthrough even a verbose listing, and makes it easier to identify new downloads,anomalies, and network errors.
If few files are copied, the left margin ofthe output log is mostly blank. Copied files and anomalies are easily spottednon-blank entries in the left margin of the output log.
Tags for Files
The following table lists the tags thatapply to files.
File Tag | Meaning |
*MISMATCH | The source file corresponds to a destination directory of the same name. The source file is skipped, and housekeeping of the destination tree is recommended. |
*EXTRA File | The file exists in the destination but not the source (an Extra file). Some housekeeping of the destination tree may be required. |
New File | The file exists in the source but not in the destination (a Lonely file). The file is copied; to skip this file, use/XL. |
lonely | The file exists in the source but not in the destination (a Lonely file).The file is skipped; to copy this file, omit/XL. |
Newer | The source file has a later time stamp than the destination file. The file is copied; to skip this file, use/XN. |
newer | The source file has a later time stamp than the destination file. The file is skipped; to copy this file, omit/XN. |
Older | The source file has an earlier time stamp than the destination file. The file is copied; to skip this file, use/XO. |
older | The source file has an earlier time stamp than the destination file. The file is skipped; to copy this file, omit/XO. |
Changed | The source and destination files have identical time stamps but different file sizes. The file is copied; to skip this file, use/XC. |
changed | The source and destination files have identical time stamps but different file sizes. The file is skipped; to copy this file, omit/XC. |
Tweaked | The source and destination files have identical time stamps and file sizes but different attributes. The file is copied because/IThas been specified; to skip this file, omit/IT. |
Same | The source and destination files have identical time stamps and file sizes. The file is copied; to skip this file, omit/IS. |
same | The source and destination files have identical time stamps and file sizes. The file is skipped; to copy this file, use/IS. |
attrib | At least one source file attribute matches the attributes specified by/XA. The file is skipped; to copy this file, modify or omit/XA. |
named | The file is skipped because it was named following an/XF switch. To process this file, amend the argument following/XF. |
large | The file is skipped because it is larger than/MAX:n bytes. To process this file, increase the value ofn. |
small | The file is skipped because it is smaller than/MIN:n bytes. To process this file, reduce the value of/MIN:n. |
too old | The file is skipped because it is older than the date defined by/MAXAGE:n or/MAXLAD:n. To process this file, amendn to specify an earlier date. |
too new | The file is skipped because it is newer than the date defined by/MINAGE:n or/MINLAD:n. To process this file, amendn to specify a more recent date. |
Tags for Directories
The following table lists the tags thatapply to directories.
Directory Tag | Meaning |
(blank) | A normal directory. |
*MISMATCH | This source directory corresponds to a destination file of the same name and cannot be processed. Housekeeping of the destination is recommended. |
*EXTRA Dir | The directory exists in the destination but not the source (an Extra directory). Some housekeeping of the destination tree may be required. |
lonely | The directory exists in the source but not the destination (a Lonely directory). The directory is skipped; to process this directory, omit/XL. |
named | The directory is skipped because it was named following an/XD switch. To process this directory, amend the argument following/XD. |
junction | The entry is actually a junction, and is skipped because/XJ was specified. To process this junction and copy it as a directory, omit/XJ. |
Run Summary
If you have not specified the /NJS (No Job Summary) switch, thenbefore Robocopy stops, it displays a summary of its activities at the commandprompt (or redirects the information to a file). This output summarizes thevolume of data processed in the following format:
| ||||||||
| Total | Copied | Skipped | Mismatch | FAILED | Extras | ||
Dirs: | 13 | 0 | 13 | 0 | 0 | 1 | ||
Files: | 157 | 2 | 155 | 0 | 0 | 3 | ||
Bytes: | 33.73 m | 691.5 k | 33.05 m | 0 | 0 | 162 | ||
Times: | 0:01:33 | 0:01:04 |
|
| 0:00:00 | 0:00:29 | ||
Speed: |
| 10952 bps |
|
|
|
| ||
Speed: |
| 0.626 mb/min |
|
|
|
| ||
The first column of the run summaryindicates the total number of files and directories processed, the total sizeof source files matching the file names specified for copying, and the totaltime taken by the operation. The remaining columns provide a breakdown of thetotals, as described in the following table.
Column | Information Provided |
Copied | Number of directories created and files copied |
Skipped | Number of directories processed but not created, and number of files skipped |
Mismatch | Number of Mismatched files and directories |
FAILED | Number of items not successfully processed within the retry limit |
Extras | Number of items present in the destination but not the source |
The Times line of the summary providestiming information for the run, as described in the following table. Times aredisplayed in HH:MM:SS format.
Column | Information Provided |
Copied | Time spent copying files (excluding retry wait times) |
FAILED | Time spent waiting between retries for failed operations |
Extra | Time spent scanning directories and performing other functions |
Note |
Large times in the FAILED column usually indicatenetwork problems.
Finally, if files were copied, the Speed linesshow throughput information, calculated by dividing the volume of data copiedby the time spent copying. The same data is displayed twice: first in bytes persecond (bps), and then in megabytes per minute (mb/min).
Return Code
The return code fromRobocopy is a bit map, defined as follows:
Hex Bit Value | Decimal Value | Meaning If Set |
0x10 | 16 | Serious error. Robocopy did not copy any files. This is either a usage error or an error due to insufficient access privileges on the source or destination directories. |
0x08 | 8 | Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further. |
0x04 | 4 | Some Mismatched files or directories were detected. Examine the output log. Housekeeping is probably necessary. |
0x02 | 2 | Some Extra files or directories were detected. Examine the output log. Some housekeeping may be needed. |
0x01 | 1 | One or more files were copied successfully (that is, new files have arrived). |
0x00 | 0 | No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized. |
You can use thisinformation in a batch file to report the most serious anomalies, as follows:
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 8 echo**FAILED COPIES** & goto end
if errorlevel 4 echo*MISMATCHES* & goto end
if errorlevel 2 echoEXTRA FILES & goto end
if errorlevel 1 echoCopy successful & goto end
if errorlevel 0 echo--no change-- & goto end
:end
Alternatively, full detailsof the return code could be reported as follows:
if errorlevel 16 echo ***FATAL ERROR*** & goto end
if errorlevel 15 echoFAIL MISM XTRA COPY & gotoend
if errorlevel 14 echoFAIL MISM XTRA & goto end
if errorlevel 13 echoFAIL MISM COPY& goto end
if errorlevel 12 echoFAIL MISM & goto end
if errorlevel 11 echoFAIL XTRA COPY& goto end
if errorlevel 10 echoFAIL XTRA & goto end
if errorlevel 9 echo FAIL COPY& goto end
if errorlevel 8 echo FAIL & goto end
if errorlevel 7 echo MISM XTRA COPY &goto end
if errorlevel 6 echo MISM XTRA & goto end
if errorlevel 5 echo MISM COPY & goto end
if errorlevel 4 echo MISM & goto end
if errorlevel 3 echo XTRA COPY & gotoend
if errorlevel 2 echo XTRA & goto end
if errorlevel 1 echo COPY& goto end
if errorlevel 0 echo --no change-- & goto end
:end
Feedback
For questions or feedback concerning thistool, please contact rkinput_microsoft.com.
If you want to report a problem encounteredwhen using Robocopy, please supply the following information.
· Versionnumber
· Operatingsystem and Service Pack for all computers
· Filesystem
· CompleteRobocopy command line or batch file
· Outputlog
· Directorylistings
· Dr.Watson log (for application errors)
· Methodof running Robocopy (from the command prompt, using Schedule service, and soon)
· Useraccount information.
© 1985 – 2003 Microsoft Corporation. All rightsreserved.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
