Vom*_*yle 15
默认情况下,如果文件的特定元数据匹配,Robocopy 会跳过复制现有文件,那么这些文件将从“文件”复制操作 ( /COPY:DAT) 中跳过。
Robocopy 默认值
- 如果上次写入时间、文件名和文件大小匹配,则跳过文件复制
- 如果上次写入时间、文件名或文件大小不匹配,则复制文件
如@mklement0 所示,如果时间戳 [LastWriteTime] 和文件大小相同,则隐含的默认值/COPY:DAT不会复制具有不同数据的文件,因此这是默认跳过。
因此,如果由于某种原因您要同步的两个文件具有匹配的文件大小、文件名和上次修改属性,即使数据不同,它也不会复制源文件。
Robocopy 默认选项:
/COPY:DAT /R:1000000 /W:30
由运行的日志文件或命令窗口确认 robocopy c:\source c:\dest *
/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).
Run Code Online (Sandbox Code Playgroud)
Net*_*ion 10
robocopy SOURCE DESTINATION FILE(S) /IS
Run Code Online (Sandbox Code Playgroud)
当IS代表我nclude小号AME文件(S)。使用此开关会覆盖现有文件。见下文:
::
:: 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.
Run Code Online (Sandbox Code Playgroud)
不幸的是,官方文档并没有描述默认跳过哪些文件背后的逻辑。
然而,非官方ss64.com 文档提供了关键指针(强调):
默认情况下,如果源和目标具有不同的时间戳或不同的文件大小, Robocopy 只会复制文件。
注意:时间戳是指最后修改的时间戳(仅)。
换句话说:的Robocopy认为两个文件是相同的基础只有在他们的最后修改时间邮票和文件大小是否一致,因此跳过该事件而复制。
据我所知:
此行为不会影响通过修改一个文件/目录的哪些方面来复制(参数/copy/ /dcopy)
如果你想扩展默认的同一性检测(同上次修改时间戳和文件大小相同)的以下特性,使用/it(包括调整了)选项:
A用于/copy参数)S以/copy参数表示)O用于/copy参数)U以/copy参数表示)Robocopy 似乎没有提供基于文件内容检测文件相同性的选项(通常通过加密哈希函数实现)。
因此,在极少数情况下,可能存在具有相同上次修改时间戳和相同文件大小但内容不同的文件,您唯一的选择是使用/is(包含相同)选项:
这会导致无条件复制被认为相同的文件- 因此可能是不必要的。
警告:奇怪的是,这是相同的相对于上次修改文件时间戳和文件大小的文件,但不同相对于所述/it产权相关属性上述被不包括在由缺省与/is单独; 因此,要涵盖所有可能发生的情况,请使用/is和/it 组合.
以下Pester测试演示了这些行为;将代码另存为Tests.ps1并将其调用为Invoke-Pester ./Tests.ps1:
Describe RoboCopySkippedFilesTests {
BeforeAll {
Push-Location TestDrive:
}
AfterAll {
Pop-Location
}
BeforeEach {
# Set up a source and a destination folder and make their
# Content the same.
if (Test-Path dest) { Remove-Item -Force -Recurse dest }
$null = New-Item -Type Directory -Force src
'file1' > src\file1
'file2' > src\file2
Copy-Item -Recurse src dest
}
It "Does not copy anything with identical folders." {
robocopy.exe src dest
$LASTEXITCODE | Should Be 0
}
It "Does recognize a changed last-modified filestamp" {
(gi src\file1).LastWriteTime = [datetime]::now
robocopy.exe src dest # | Out-Host
$LASTEXITCODE | Should Be 1
}
It "Does recognize a change in file size" {
'!' | Add-Content dest\file1
robocopy.exe src dest # | Out-Host
$LASTEXITCODE | Should Be 1
}
It "Does not recognize a change in file content, with size and last-modified date identical" {
'file!' > dest\file1
(Get-Item dest\file1).LastWriteTime = (Get-Item src\file1).LastWriteTime
robocopy.exe src dest # | Out-Host
$LASTEXITCODE | Should Be 0
}
It "Does not recognize a change in file attributes, with size and last-modified date identical" {
(Get-Item dest\file1).Attributes = 'System'
robocopy.exe src dest # | Out-Host
$LASTEXITCODE | Should Be 0
}
It "Does recognize an attribute-modified-only file as tweaked (/IT)" {
(Get-Item dest\file1).Attributes = 'System'
robocopy.exe src dest /IT # | Out-Host
$LASTEXITCODE | Should Be 1
}
It "Does not include an attribute-modified-only file with /IS" {
Remove-Item src\file2, dest\file2
(Get-Item dest\file1).Attributes = 'System'
robocopy.exe src dest /IS # | Out-Host
$LASTEXITCODE | Should Be 0
}
}
Run Code Online (Sandbox Code Playgroud)
您应该会看到类似以下内容,表明所有测试都通过了(从Robocopy.exe文件版本开始10.0.16299.15 (WinBuild.160101.0800)):
Describing RoboCopySkippedFilesTests
[+] Does not copy anything with identical folders. 231ms
[+] Does recognize a changed last-modified filestamp 112ms
[+] Does recognize a change in file size 68ms
[+] Does not recognize a change in file content, with size and last-modified date identical 69ms
[+] Does not recognize a change in file attributes, with size and last-modified date identical 83ms
[+] Does recognize an attribute-modified-only file as tweaked (/IT) 65ms
[+] Does not include an attribute-modified-only file with /IS 70ms
Tests completed in 589ms
Passed: 7 Failed: 0 Skipped: 0 Pending: 0 Inconclusive: 0
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69983 次 |
| 最近记录: |