0

哦,我有一台服务器将数据备份到 NAS,然后我从源 NAS 复制到目标 NAS。

我正在寻找一种方法来验证已发送到目标 NAS 的大小数量是否与源 NAS 上的大小相匹配。

因为移动的数据量很大,无法一一看到。

有人对我的问题有任何建议和解决方案吗?

谢谢你

4

1 回答 1

1

如果您需要验证在 2 个目录之间复制的数据,我认为您的最佳选择是比较文件哈希而不是文件大小。

您可以使用以下脚本来识别不一致的文件

$Dir1 = "D:\SRC"
$Dir2 = "D:\DST"
$Dir1Hash = Get-ChildItem $Dir1 -recurse -file | Get-FileHash | select hash,Path,@{n='RemotePath';e={$_.path.replace($Dir1,$Dir2)}}
$Dir2Hash = Get-ChildItem $Dir2 -recurse -File | Get-FileHash | select hash,Path,@{n='RemotePath';e={$_.path.replace($Dir2,$Dir1)}}
foreach ($item in $Dir1Hash){
$ReplicaFile = $Dir2Hash | where {$_.RemotePath -eq $item.path}
if ($ReplicaFile) {
    if ($item.Hash -ne $ReplicaFile.Hash){
        Write-host "Incorrect hash of file: $($item.Path) on Replica folder" -ForegroundColor Cyan
    }
}
else {
    Write-Output "File: $($item.Path) doesn't exist on Replica Folder"
}
}
于 2021-12-24T22:02:33.237 回答