【问题标题】:compress-archive task failing in SSIS with 1.25GB file压缩归档任务在 SSIS 中失败,文件为 1.25GB
【发布时间】:2021-08-05 09:28:36
【问题描述】:

我正在使用“执行进程任务”来调用 powershell compress-archive 命令。

对于小文件,它工作正常。

对于 1.25GB 的文件,它失败了。它开始处理然后“完成”但没有创建文件。

鉴于 compress-archive 应该可以处理最大 2GB 的文件,为什么会发生这种情况以及我还有哪些其他选择?

由于无法控制服务器安装,因此不能选择 7zip。

【问题讨论】:

    标签: powershell ssis zip compress-archive


    【解决方案1】:

    Compress-ArchiveSystem.IO.Compression.ZipArchive .Net 库的简化包装器。不支持某些功能,例如存储相对路径。异常处理和报告很弱。对于任何需要强大异常处理的压缩任务,我通常选择直接使用 .Net 库。

    使用脚本(对于无人值守的工作来说总是一个好主意)和错误处理,代码并不复杂。这可能无法解决您的问题,但可能会为您提供更多信息:

    $ZipPath = 'C:\Temp\test.zip'
    $LogPath = "c:\Temp\Archiving-$(get-date -f yyyy-MM-dd).log"
    $FilesToZip = (Get-ChildItem 'C:\Temp\*.csv' -File) #trying to compress the zip or log file will result in error: 'process cannot access the file ... in use'
    @( 'System.IO.Compression','System.IO.Compression.FileSystem') | % { [void][Reflection.Assembly]::LoadWithPartialName($_) }
    Try{
        Start-Transcript $LogPath -Append
        $WriteArchive = [IO.Compression.ZipFile]::Open( $ZipPath, 'Update')#Update mode also creates a zip
        ForEach($file in $FilesToZip){
            $ArchivedFile = [IO.Compression.ZipFileExtensions]::CreateEntryFromFile($WriteArchive, 
                $File.FullName, $file.Name, 'Optimal')
            Write-Host "Archived: $($File.FullName) bytes: $($file.Length)"
        }
    }Catch [Exception]{
        Write-Error $_.Exception
    }Finally{
        $WriteArchive.Dispose() #close the zip file so it can be read later     
        Stop-Transcript 
    }
    

    使用 Compress-Archive 的大致等效代码:

    Compress-Archive -Path 'C:\Temp\*.csv' -DestinationPath 'C:\Temp\test.zip' -Update
    

    但是,Compress-Archive 在后续运行时会覆盖 .Zip 存档中的条目。 CreateEntryFromFile 在存档中创建重复条目。

    【讨论】:

    • 我尝试在 c# 脚本任务中执行此操作,但由于“内存不足”而失败。如果在同一台机器上我只是尝试手动压缩它或使用 powershell 手动压缩,它工作正常。
    猜你喜欢
    • 1970-01-01
    • 2010-09-20
    • 2018-09-11
    • 2023-03-22
    • 2017-08-28
    • 2018-06-26
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    相关资源
    最近更新 更多