/*internal static IIncrementalProvider GetProviderByName(string name){ * return selectablePlugins[name].Value; * }*/ internal static IIncrementalProvider GetProviderByPriority(BackupRootDrive rd, Dictionary <string, byte[]> initMetadata) { if (initMetadata == null || initMetadata.Count == 0) { return(null); } IIncrementalProvider iip = null; //new FileCompareProvider(referenceBackupStart, referenceBackupEnd, refTaskId); //iip = from plugins where plugins.ContainsKey(rd.systemDrive.MountPoint) and p int maxPrio = 0; foreach (KeyValuePair <string, IIncrementalProvider> prov in selectablePlugins) { if (prov.Key == rd.SystemDrive.OriginalMountPoint && prov.Value.Priority > maxPrio) { Logger.Append(Severity.DEBUG, "Testing incr provider '" + prov.Value.Name + "' for drive '" + rd.SystemDrive.OriginalMountPoint + "'"); foreach (KeyValuePair <string, byte[]> kp in initMetadata) { Logger.Append(Severity.TRIVIA, "Got reference metadata for provider " + kp.Key); } if (initMetadata.ContainsKey(prov.Value.Name)) { prov.Value.SetReferenceMetadata(initMetadata[prov.Value.Name]); } if (prov.Value.CheckCapability()) { iip = prov.Value; maxPrio = prov.Value.Priority; Logger.Append(Severity.INFO, "Incremental provider " + prov.Value.Name + " with priority " + prov.Value.Priority + " is selectable for this task."); } else { Logger.Append(Severity.INFO, "Incremental provider " + prov.Value.Name + " with priority " + prov.Value.Priority + " is NOT selectable for this task."); } } } /*if(Utilities.PlatForm.IsUnixClient()){ * FileCompareProvider fcp = new FileCompareProvider(referenceBackupStart, referenceBackupEnd, refTaskId, rd); * if(fcp.CheckCapability()) iip = fcp; * } * else{ * if(usnp == null) throw new Eception("Provider USNJournalProvider has not been initialized, call PrepareProvidersForBackup first"); * else { * //UsnJournalProvider usn = new UsnJournalProvider(bType, rd, referenceBackupStart, referenceBackupEnd); * //UsnJournalProvider usn = new UsnJournalProvider(rd, referenceBackupStart, referenceBackupEnd); * if(usnp.CheckCapability()) iip = usn; * * } * }*/ if (iip != null) { Logger.Append(Severity.INFO, "Incremental/Differential provider " + iip.GetType().ToString() + ", priority " + iip.Priority + " choosen."); } return(iip); }
/*private IEnumerable<IFile> GetFull_old(){ * foreach(string f in Directory.EnumerateFileSystemEntries(snapshottedPath, "*", SearchOption.TopDirectoryOnly)){ * IFile entry = null; * //Console.WriteLine("GetFull() : "+f); * try{ * entry = FileProvider.GetFile(f); * } * catch(Exception e){// permission errors, deleted file... * Logger.Append(Severity.WARNING, "Could not add element '"+f+"' to backup : "+e.Message); * Logger.Append(Severity.INFO, "TODO : report exception to hub for task logentry"); * } * if(entry.Kind == FileType.Directory){ * depth++; * snapshottedPath = f; * foreach(IFile e in GetFull()) //GetFilesToBackup()) * yield return e; * * if(depth == 1){ * if(SubCompletionEvent != null) SubCompletionEvent(entry.FileName.Replace(snapshottedPath, currentPath)); * //entry.FileName.Replace(snapshottedPath, currentPath * } * depth--; * //else * // Console.WriteLine ("##### depth="+depth); * //subCompletionNb++; * * } * * //Console.WriteLine("GetFilesToBackup() : "+f); * yield return entry; * } * }*/ private IEnumerable <Node.IFSEntry> GetIncremental() { // open reference index //IndexManager im = new IndexManager(); Index refIdx = new Index(referenceTaskid, false); refIdx.Open(); // set previous chunk max id in order to not overlap ids chunkOrder = refIdx.GetMaxChunkId(); Dictionary <string, byte[]> dict = refIdx.GetProviderMetadata(this.backupRootDrive.SystemDrive.OriginalMountPoint); IIncrementalProvider incrProv = null; /*if(isFullRefresh){ * incrProv = new FileCompareProvider(this.TaskId, this.backupRootDrive); * } * else{*/ // get the most efficient (higher priority) incrementalprovider for the current drive, passing it the reference backup's metadata incrProv = IncrementalPluginProvider.GetProviderByPriority(this.backupRootDrive, dict); //} this.backupRootDrive.IncrementalPlugin = incrProv; if (incrProv != null) { Logger.Append(Severity.INFO, "Chose Incremental/Differential provider : " + incrProv.GetType().ToString() + ", priority: " + incrProv.Priority); } else // no reference data for any provider, unable to perform incr, default to full { Logger.Append(Severity.ERROR, "Unable to select any of the Incremental providers for FS " + this.backupRootDrive.SystemDrive.MountPoint); //yield return GetFull(); throw new Exception("Unable to select any of the Incr providers for FS " + this.backupRootDrive.SystemDrive.MountPoint); } refIdx.Terminate(); bool exclude = false; foreach (IFSEntry entry in incrProv.GetNextEntry(currentPath, snapshottedPath)) { // don't try to match include/exclude rules if file was deleted if (entry.ChangeStatus == DataLayoutInfos.Deleted) { yield return(entry); continue; } //Console.WriteLine (DateTime.Now.TimeOfDay+" @@@ GetIncremental() : got entry "+entry.Name); //if(entry.Kind == FileType.Directory){ if (entry.SnapFullPath == null) { Logger.Append(Severity.NOTICE, "Got null entry for '" + entry.Name + "' from provider '" + entry.GetType() + "' while collecting in incremental mode, this is unexpected"); continue; } // TODO : report completionpercent if possible exclude = false; //if(depth <2) Console.WriteLine ("GetFull() : entering "+entry.SnapshottedFullPath); for (int i = currentPath.ExcludedPaths.Count - 1; i >= 0; i--) { if (entry.SnapFullPath.IndexOf(currentPath.ExcludedPaths[i]) == 0) { Logger.Append(Severity.DEBUG, "Exclusion rule '" + currentPath.ExcludedPaths[i] + "' : ignoring entry " + entry.SnapFullPath); //currentPath.ExcludedPaths.RemoveAt(i); exclude = true; //yield return entry; break; } } //} if (!exclude && entry != null) { Console.WriteLine(" /////// return incr entry : " + entry.ToString()); yield return(entry); } } }