当我将 zip.MaxOutputSegmentSize 设置得足够高时,只有一个 zip 文件可以工作。一旦我限制 MaxOutputSegmentSize 在其中一个拆分文件达到其最大大小后出现此错误 - 当我有一个像 20MB 这样的值时,它总是出现在文件“.z02”的末尾,如果值更小它也可能稍后发生一些文件。
如果我使用 zip.ZipErrorAction = ZipErrorAction.Skip 或 .Retry 我会得到一个 System.ObjectDisposedException 。
这里可能是什么问题,或者这是 DotNetZip 库中的错误?
ZipFile zip = new ZipFile(backupPath + "Backup.zip");
zip.MaxOutputSegmentSize = maxSize;
//zip.TempFileFolder = @"D:\Backup\Temp"; //seems not to make any difference
zip.Comment = "Backup created at " + System.DateTime.Now.ToString("G");
zip.AddFile(dbBackup.FullName,"Database");
zip.AddDirectory(physicalAppPath,"Application");
zip.AddDirectory(mailArchivePath,"MailArchive");
zip.Save(); //Exception occurs here
堆栈跟踪:
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.File.Move(String sourceFileName, String destFileName)
bei Ionic.Zip.ZipSegmentedStream.TruncateBackward(UInt32 diskNumber, Int64 offset)
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
bei MyProject.Configuration.Backup.BackupLogic.Backup(Boolean monthly) in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 100.
bei MyProject.Configuration.Backup.BackupLogic.ScheduledBackup() in D:\projects\MyProject.Configuration\Backup\BackupLogic.cs:Zeile 42.
bei MyProject.Configuration.BackupTimer.CreateThread(Object parameters) in D:\projects\MyProject.Configuration\BackupTimer.cs:Zeile 60.
bei System.Threading.ExecutionContext.runTryCode(Object userData)
bei System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart(Object obj)
使用 ZipErrorAction.Skip 的异常和 StackTrace:
ObjectDisposed Exception was unhandled: Auf eine geschlossene Datei kann nicht zugegriffen werden. (Could not access an closed file)
bei System.IO.FileStream.get_Position()
bei Ionic.Zip.ZipEntry.Write(Stream s)
bei Ionic.Zip.ZipFile.Save()
...
在目标文件夹上带有过滤器的进程监视器显示没有任何可疑之处:(在这种情况下,创建了 3 个拆分文件,然后发生了异常)
12:35:25.6312905 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:25.6319249 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS
12:35:27.7507327 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:27.7511904 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS
12:35:32.9936509 PM w3wp.exe 5380 CreateFile D:\Backup SUCCESS Desired Access: Write Data/Add File, Synchronize, Disposition: Open, Options: , Attributes: n/a, ShareMode: Read, Write, AllocationSize: n/a, Impersonating: NT-AUTORITÄT\IUSR, OpenResult: Opened
12:35:32.9941529 PM w3wp.exe 5380 CloseFile D:\Backup SUCCESS