【问题标题】:Best way to do a remote directory compare with Powershell与 Powershell 进行远程目录比较的最佳方法
【发布时间】:2012-08-29 19:41:01
【问题描述】:

我有 2 个文件夹:

$srcPath = \\stagingserver
$destPath = \\productionserver

我想比较这两者,以确定 $src 文件夹中的哪些更改尚未推送到生产环境。该项目是超过 100 个目录的约 4000 个文件,总计约 80mb。我目前正在像这样进行哈希比较:

$src = Get-ChildItem $srcPath -Recurse
$dest = Get-ChildItem $destPath -Recurse 
$same = Compare-Object $src $dest -Property Name, Length, LastWriteTime -passthru -includeequal -excludeDifferent

$srcTree = Get-ChildItem $src -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash
$destTree = Get-ChildItem $dest -Recurse -exclude $same | Where-Object {!$_.psiscontainer } | get-hash  

$diff = Compare-Object -ReferenceObject $srcTree -differenceObject $destTree | ? {$_.SideIndicator -eq "<=" } | % {$_.InputObject.Path}

大约需要 5 分钟。我接受它是因为它需要在本地复制所有内容以执行散列。我怎样才能更快地做到这一点?有没有办法为服务器上的每个文件维护一个哈希值?我应该远程执行脚本吗?

【问题讨论】:

    标签: powershell deployment scripting


    【解决方案1】:

    您可以使用robocopy 将暂存共享内容同步到生产共享,而不是比较文件。 /MIR 标志可用于镜像,即从目标中删除不存在的文件。 Robocopy 使用时间戳来确定是否需要复制文件,因此有一些注意事项。

    如果需要哈希,您可以在远程服务器上创建一个脚本,将文件哈希存储在 CSV 文件中。之后,导入 CSV 文件并将本地哈希与文件内容进行比较应该很容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-03-13
      • 2020-12-27
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      相关资源
      最近更新 更多