.net Powershell压缩。Zipfile错误
在Powershell中运行脚本时收到错误。该脚本在一个目录中查找两个特定文件夹(一个约13GB,另一个1.5GB),并在zip文件名后附加日期/时间字符串对其进行压缩。它已经无误运行了一年多。直到平安夜。通常仅在一个文件夹上接收错误,而另一个文件夹则正常处理。尽管脚本按特定顺序处理文件夹,但在哪个文件夹上发生错误似乎是随机的。该代码自一年前投入生产以来一直没有改变 我的错误 使用“4”参数调用“CreateFromDirectory”时出现异常:“数据错误(循环冗余检查)。” 我的代码.net Powershell压缩。Zipfile错误,.net,powershell,powershell-3.0,zipfile,.net,Powershell,Powershell 3.0,Zipfile,在Powershell中运行脚本时收到错误。该脚本在一个目录中查找两个特定文件夹(一个约13GB,另一个1.5GB),并在zip文件名后附加日期/时间字符串对其进行压缩。它已经无误运行了一年多。直到平安夜。通常仅在一个文件夹上接收错误,而另一个文件夹则正常处理。尽管脚本按特定顺序处理文件夹,但在哪个文件夹上发生错误似乎是随机的。该代码自一年前投入生产以来一直没有改变 我的错误 使用“4”参数调用“CreateFromDirectory”时出现异常:“数据错误(循环冗余检查)。” 我的代码 {
{
$fileNameAppend = (get-date -Format "_MM-dd-yyyy-hhmmss")+".zip"
$sourceFolder = $sourcePath+$folder+"\"
$zipFileName = $sourcePath+$folder+$fileNameAppend
$destinationFileName = $destinationPath+$folder+$fileNameAppend
If ( (Test-Path $sourceFolder) -eq $false )
{
Write-Error "Error reading Source. Folder location not found: $sourcefolder"
}
if ($error.Count -eq 0)
{
#Does not run on empty folder
if( (Get-ChildItem $sourceFolder) -eq $null)
{
Write-Error "Error compressing folder. Source folder is empty: $sourceFolder"
}
}
if ($error.Count -eq 0)
{
#Use .NET 4.5 to zip the folder to a file
$startC = get-date -Format ("hh:mm:ss")
Write-Output ((Get-Date -Format ("MM/dd/yyyy HH:mm:ss"))+" Compressing Folder: $sourceFolder ...")
$compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
$includebasedir = $true
[System.IO.Compression.ZipFile]::CreateFromDirectory($sourceFolder,$zipFileName,$compressionLevel,$includebasedir)
#Verify file was created
if (![System.IO.File]::Exists($zipFileName))
{
Write-Error "Error compressing folder. File not found: $zipFileName"
}
$end = Get-Date -Format ("hh:mm:ss")
$diff = ($end|ts) - ($startC|ts)
Write-Output ("Finished compressing in "+[string]$diff.Minutes+" minutes and "+[string]$diff.Seconds+" seconds.`r`n")
}
if ($error.Count -eq 0)
{
if (![System.IO.Directory]::Exists($destinationPath))
{
[System.IO.Directory]::CreateDirectory($destinationPath)
}
$startC = get-date -Format ("hh:mm:ss")
Write-Output ((Get-Date -Format ("MM/dd/yyyy HH:mm:ss"))+" Copying File: $zipFileName ...")
[System.IO.File]::Copy($zipFileName, $destinationFileName, $True)
$end = Get-Date -Format ("hh:mm:ss")
$diff = ($end|ts) - ($startC|ts)
Write-Output ("Finished copying in "+[string]$diff.Minutes+" minutes and "+[string]$diff.Seconds+" seconds.")
Write-Output ((Get-Date -Format ("MM/dd/yyyy HH:mm:ss"))+" Getting Hash ...")
$sHash = GetHash $zipFileName
$dHash = GetHash $destinationFileName
if ($sHash -ne $dHash)
{
Write-Error ("Error copying file: $zipFileName Hash does not match. `r`n Source Hash: "+[string]$sHash+" `r`n Destination Hash: "+[string]$sHash+" `r`n")
}
else
{
Write-Output ("Source Hash: "+([string]$sHash))
Write-Output ("Destination Hash: "+([string]$dHash)+"`r`n")
}
}
if ($error.Count -eq 0)
{
Get-ChildItem $sourceFolder | `
ForEach-Object {Write-Output ("Deleting: "+($_.FullName)) (Remove-Item $_.FullName)}
Get-ChildItem $destinationPath | `
Where-Object { $_.name -Like ($folder+"*") } | `
Where-Object { $_.LastWriteTime -lt $(get-date).('AddHours').Invoke(-2) } | `
ForEach-Object {Write-Output ("Deleting: "+($_.FullName)) (Remove-Item $_.FullName)}
}
}
您似乎正在正在压缩的文件夹中创建zipfile。尝试将其移到
$sourceFolder
tree@Eris正在压缩的文件夹是G:\MSSQL\u Backups\Alpha,文件Alpha\u 201301113123022(基于日期时间)正在压缩到G:\MSSQL\u Backups。是否尝试了其他压缩方法?