tbl*_*tbl 14 windows powershell ntfs robocopy
通常,Robocopy会忽略lastwrittendate和filesize相同的文件.我们怎样才能摆脱这种设计?我想用Robocopy强制覆盖.
我希望dst\sample.txt应该写成test001.但是这些文件被Robocopy识别为相同的文件而不会被覆盖.在这种情况下,"/ IS"选项无效.
New-Item src -itemType Directory
New-Item dst -itemType Directory
New-Item src\sample.txt -itemType File -Value "test001"
New-Item dst\sample.txt -itemType File -Value "test002"
Set-ItemProperty src\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"
Set-ItemProperty dst\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"
ROBOCOPY.exe src dst /COPYALL /MIR
Get-Content src\sample.txt, dst\sample.txt
> test001
> test002
ROBOCOPY.exe src dst /COPYALL /MIR /IS
Get-Content src\sample.txt, dst\sample.txt
> test001
> test002
Ans*_*ers 22
从文档:
/is包含相同的文件.
/it包括"调整"文件.
"相同文件"表示相同的文件(名称,大小,时间,属性)."调整文件"是指具有相同名称,大小和时间但属性不同的文件.
robocopy src dst sample.txt /is      # copy if attributes are equal
robocopy src dst sample.txt /it      # copy if attributes differ
robocopy src dst sample.txt /is /it  # copy irrespective of attributes
SuperUser上的这个答案很好地解释了选择参数匹配的文件类型.
话虽如此,我可以重现你描述的行为,但根据我对文档的理解和robocopy我测试中生成的输出,我会认为这是一个错误.
PS C:\temp> New-Item src -Type Directory >$null
PS C:\temp> New-Item dst -Type Directory >$null
PS C:\temp> New-Item src\sample.txt -Type File -Value "test001" >$null
PS C:\temp> New-Item dst\sample.txt -Type File -Value "test002" >$null
PS C:\temp> Set-ItemProperty src\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"
PS C:\temp> Set-ItemProperty dst\sample.txt -Name LastWriteTime -Value "2016/1/1 15:00:00"
PS C:\temp> robocopy src dst sample.txt /is /it /copyall /mir
...
  Options : /S /E /COPYALL /PURGE /MIR /IS /IT /R:1000000 /W:30
------------------------------------------------------------------------------
                           1    C:\temp\src\
            Modified                   7        sample.txt
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         0         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :         7         7         0         0         0         0
...
PS C:\temp> robocopy src dst sample.txt /is /it /copyall /mir
...
  Options : /S /E /COPYALL /PURGE /MIR /IS /IT /R:1000000 /W:30
------------------------------------------------------------------------------
                           1    C:\temp\src\
            Same                       7        sample.txt
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         0         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :         7         7         0         0         0         0
...
PS C:\temp> Get-Content .\src\sample.txt
test001
PS C:\temp> Get-Content .\dst\sample.txt
test002
该文件被列为已复制,并且由于它在第一次robocopy运行后变为同一文件,因此至少同步时间.但是,即使已根据输出复制了7个字节,但在两种情况下都没有数据实际写入目标文件,尽管数据标志已设置(通过/copyall).如果明确设置数据标志(/copy:d),则行为也不会更改.
我不得不修改上次写入时间robocopy以实际同步数据.
PS C:\temp> Set-ItemProperty src\sample.txt -Name LastWriteTime -Value (Get-Date)
PS C:\temp> robocopy src dst sample.txt /is /it /copyall /mir
...
  Options : /S /E /COPYALL /PURGE /MIR /IS /IT /R:1000000 /W:30
------------------------------------------------------------------------------
                           1    C:\temp\src\
100%        Newer                      7        sample.txt
------------------------------------------------------------------------------
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         0         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :         7         7         0         0         0         0
...
PS C:\temp> Get-Content .\dst\sample.txt
test001
一个公认的丑陋的解决方法是更改相同/调整文件的最后写入时间以强制robocopy复制数据:
& robocopy src dst /is /it /l /ndl /njh /njs /ns /nc |
  Where-Object { $_.Trim() } |
  ForEach-Object {
    $f = Get-Item $_
    $f.LastWriteTime = $f.LastWriteTime.AddSeconds(1)
  }
& robocopy src dst /copyall /mir
切换到xcopy可能是您的最佳选择:
& xcopy src dst /k/r/e/i/s/c/h/f/o/x/y
小智 14
这真的很奇怪,为什么没有人提到 /IM 开关?!我已经在备份工作中使用它很长时间了。但是我刚刚尝试使用谷歌搜索,我无法登陆一个网页,即使在MS 网站上也没有任何说明!!!还发现很多用户帖子抱怨同样的问题!!
反正..使用的Robocopy覆盖一切什么都大小或时间源或distination您必须在您的命令这三个开关(/ IS / IT / IM)
/IS :: Include Same files. (Includes same size files)
/IT :: Include Tweaked files. (Includes same files with different Attributes)
/IM :: Include Modified files (Includes same files with different times).
这是我用来传输几乎 1GB+ 文件(ISO - 磁盘映像 - 4K 视频)的几个 TeraBytes 的确切命令:
robocopy B:\Source D:\Destination /E /J /COPYALL /MT:1 /DCOPY:DATE /IS /IT /IM /X /V /NP /LOG:A:\ROBOCOPY.LOG
我为你做了一个小测试……结果如下:
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :      1028      1028         0         0         0       169
   Files :      8053      8053         0         0         0         1
   Bytes : 649.666 g 649.666 g         0         0         0   1.707 g
   Times :   2:46:53   0:41:43                       0:00:00   0:41:44
   Speed :           278653398 Bytes/sec.
   Speed :           15944.675 MegaBytes/min.
   Ended : Friday, August 21, 2020 7:34:33 AM
目标、磁盘:WD Gold 6TB(写入速度与我的结果进行比较)
即使有那些“额外”,也只是因为“/X”开关而用于报告。如您所见,没有任何内容被跳过,所有文件的总数和大小都等于已复制。有时,当我滥用它并在操作期间多次取消它时,它会显示少量跳过的文件,但即使前两列中的值始终相等。我之前还通过运行 PowerShell 脚本来确认这一点,该脚本扫描目标中的所有文件并生成所有时间戳的报告。
我历史上的一些性能提示以及如此多的测试和麻烦!:
. 尽管大多数在线用户建议使用最大线程“/MT:128”,就像这是获得最佳性能的一般技巧……请不要将“/MT:128”用于非常大的文件……这是一个一个大错误,它会在多次运行后显着降低您的驱动器性能..它会产生非常高的碎片,甚至在某些情况下导致文件系统失败,您最终会花费宝贵的时间来尝试恢复 RAW 分区和所有这些废话。最重要的是,它的执行速度会慢 4-6 倍!!
| 归档时间: | 
 | 
| 查看次数: | 67550 次 | 
| 最近记录: |