【问题标题】:Powershell PSCX Write-Zip is slowPowershell PSCX Write-Zip 很慢
【发布时间】:2016-02-19 02:06:29
【问题描述】:

谁能帮我解决为什么这个 PSCX cmdlet 'Write-Zip' 这么慢? DotNetZip 库可以在大约 20 分钟内压缩相同的文件夹需要 1.5 小时。 (DotNetZip 库的问题在于它被大文件阻塞,所以我切换到 PSCX,它是完美的、很酷的小进度条,它实际上也可以工作,只是速度很慢)。

这是一些示例代码,如果您需要查看其他内容,请告诉我。

    $ElapsedTime = [System.Diagnostics.Stopwatch]::StartNew()

    Write-Host "Script Started at $(get-date)"

    Import-Module Pscx
    Import-Module BitsTransfer

    Write-Host "Just imported the BitsTransfer and Pscx modules"

    Write-Host "*** Starting backup portion of script ***"

    foreach($i in $appServers) {

            if (!(Test-Path -path \\$i\c$\newDeploy)) {
                New-Item \\$i\c$\newDeploy -type directory
                Write-Host "Just created newDeploy folder on $i"
            }
            if (!(Test-Path -path \\$i\c$\newDeploy\backup)) {
                New-Item \\$i\c$\newDeploy\backup -type directory
                Write-Host "Just created newDeploy\backup folder on $i"
            }
            if(!(Test-Path \\$i\c$\newDeploy\zipper.ps1)) {
                Start-BitsTransfer -Source \\$appDeployServer\c$\newDeploy\zipper.ps1 -Destination \\$i\c$\newDeploy
                Write-host "Just added zipper.ps1 to $i"
            }

    }

    foreach($i in $appServers) {

        $sessionForI = New-PSSession -computername $i
        Invoke-Command -Session $sessionForI -ArgumentList  $aosFolder, $i, $ElapsedTime -ScriptBlock {
            param ($aosFolder, $i, $ElapsedTime)

            Import-Module Pscx
            Write-Host "Just imported Pscx module for $i"

            if ((Test-Path C:\\newDeploy\\backup\\$aosFolder.zip)) {
                Remove-Item C:\\newDeploy\\backup\\$aosFolder.zip
                Write-Host "Just removed newDeploy\backup\$aosFolder.zip on $i"
            }

            Write-Host "Just started creating new ZIP file backup created on $i"
            Write-Host "   Elapsed Time: $($ElapsedTime.Elapsed.ToString())"

            cd "C:\Program Files (x86)\Folder\$aosFolder"
            Get-ChildItem "C:\Program Files (x86)\Folder\$aosFolder" -Recurse -Exclude *.e2e | Write-Zip -OutputPath "C:\newDeploy\backup\$aosFolder.zip" -NoClobber -Level 1

            write-host "   Elapsed Time: $($ElapsedTime.Elapsed.ToString())"
            Write-Host "Just finished creating new ZIP file backup created on $i"
        }
        remove-PSSession -session $sessionForI

    }

    Write-Host "Just ran second foreach loop to ZIP all folders to backup on each server"

    foreach($i in $appServers) {
        if(!(Test-Path -path C:\newDeploy\backup\$i)) {
            New-Item C:\newDeploy\backup\$i -type directory
            Write-Host "Just created DEPLOY SERVER's newDeploy\backup\$i folder for backups"
        }
        Start-BitsTransfer -Source \\$i\c$\newDeploy\backup\$aosFolder.zip -Destination C:\newDeploy\backup\$i
        Write-Host "$i backup ZIP transferred to deploy server"
    }

    Write-Host "Just ran third foreach loop to move all ZIP files to the backup server for each remote server"

    foreach($i in $appServers) {
        Remove-Item \\$i\c$\newDeploy\backup\$aosFolder.zip
        Write-Host "Just removed newDeploy\backup\$aosFolder.zip on $i"
    }

    Write-Host "Just ran forth foreach loop to delete all backup ZIP files to cleanup"

    $date = get-date -format "M-d-yyyy"
    Write-Zip -Path "C:\newDeploy\backup" -OutputPath "C:\newDeploy\backup\$date APPbackup.zip" -NoClobber -Level 1
    Write-Host "Just ran final ZIP command to put all server's backups into one neat ZIP"

    foreach($i in $appServers) {
        if((Test-Path -path C:\newDeploy\backup\$i)) {
            Remove-Item -Force -Recurse C:\newDeploy\backup\$i
            Write-Host "Just removed DEPLOY SERVER's newDeploy\backup\$i folder"
        }
    }
    Write-Host "Just ran fifth foreach loop to delete each server's backup folder on the local server to cleanup"

    Write-Host "*** Finished with backup portion of script ***"

    Write-Host "*** Starting deploy preparation portion of script ***"



    Write-Host "*** Finished with deploy preparation portion of script ***"

    Write-Host "Script Ended at $(get-date)"

【问题讨论】:

  • 有完整源代码的最终解决方案吗?
  • 我最终按照唯一答案中的建议使用了 7zip。我会尽快发布代码。
  • cd "D:\inetpub\wwwroot" Get-ChildItem "D:\inetpub\wwwroot" -Recurse -Exclude *.e2e | D:\newDeploy\7za.exe a -mx1 "D:\newDeploy\backup\sites.zip" $_.FullName
  • 用最终脚本 ps1 修改您的问题会很棒

标签: powershell pscx


【解决方案1】:

我建议您使用 7zip 命令行存档工具。它们非常活泼,可以处理各种档案。

http://downloads.sourceforge.net/sevenzip/7za920.zip

【讨论】:

  • 谢谢,我试试看。
【解决方案2】:

这是我的做法:

set-alias sz "$env:C:\7za920\7za.exe"
sz a -mx9 -tzip -r $FileName $SourceFolder

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 2012-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    相关资源
    最近更新 更多