当我设置zip。MaxOutputSegmentSize足够高,所以它只会有一个zip文件。一旦我限制了MaxOutputSegmentSize,我就会在其中一个分割文件达到其最大大小后得到此错误-当我有一个像20MB这样的值时,它总是发生在文件的末尾。
如果我使用zip。ZipErrorAction = ZipErrorAction。跳过或重试,我得到一个系统。ObjectDisposedException。
什么可能是问题在这里或这是一个错误在DotNetZip库?
ZipFile zip = new ZipFile(backupPath + "Backup.zip");
zip.MaxOutputSegmentSize = maxSize;
//zip.TempFileFolder = @"D:BackupTemp"; //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:projectsMyProject.ConfigurationBackupBackupLogic.cs:Zeile 100.
bei MyProject.Configuration.Backup.BackupLogic.ScheduledBackup() in D:projectsMyProject.ConfigurationBackupBackupLogic.cs:Zeile 42.
bei MyProject.Configuration.BackupTimer.CreateThread(Object parameters) in D:projectsMyProject.ConfigurationBackupTimer.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)
异常和StackTrace使用ZipErrorAction。跳过:
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ÄTIUSR, 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ÄTIUSR, 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ÄTIUSR, OpenResult: Opened
12:35:32.9941529 PM w3wp.exe 5380 CloseFile D:Backup SUCCESS
问题是在一个文件夹中有gzip文件(.gz带密码)-似乎DotNetZip不能拆分那些(7zip可以)。因此,一旦它到达一个.zip文件的末尾,就会出现异常。
我现在使用了一个解决方案,所以我循环我所有的文件,计算总大小,并创建单个(不分割)zip文件,每次我达到我的最大大小。
DotNetZip的问题(Bug?)仍然存在。