/*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); } } }
internal void PrepareAll() { // lauch pre-backup commands/scripts string [] cmdOuts = ExecuteCommand(this.BackupSet.Preop); HubNotificationEvent(this.Id, 710, "STDOUT", cmdOuts[0]); HubNotificationEvent(this.Id, 710, "STDERR", cmdOuts[1]); // DEBUG print basepaths foreach (BasePath bsp in this.BackupSet.BasePaths) { Console.WriteLine("0##### bp path=" + bsp.Path + ", type=" + bsp.Type); } // Gather the FSs paths required by special objects (if there are any) //Dictionary<string, SPOMetadata> spoMetadatas = PrepareSpecialObjects(); List <Tuple <string, SPOMetadata, List <string> > > spoMetadatas = PrepareSpecialObjects(); // Telling Special objects to tell the app they manage to put themselves into backup mode (if possble) // and/or freeze their IOs Logger.Append(Severity.INFO, "Freezing " + this.specialObjects.Count + " special objects..."); foreach (ISpecialObject spo in this.specialObjects) { spo.Freeze(); } SanitizePaths(); // Now snapshot (if requested). PrepareDrivesAndSnapshots(); this.Index = new Index(this.Id, (this.Level != BackupLevel.Full)); Index.Header = new IndexHeader { TaskId = this.Id, BackupType = this.Level }; //Index.Header.RootDrives = backupRootDrives; Index.Create(backupRootDrives); //taskId, (this.Bs.ScheduleTimes[0].Level != BackupLevel.Full), this.RootDrives); Index.WriteHeaders(); // Collect incremental providers metadata (for subsequent backups) foreach (BackupRootDrive brd in backupRootDrives) { Dictionary <string, byte[]> provMetadata = IncrementalPluginProvider.SignalBackupBegin(this.Id, brd); if (provMetadata == null) { continue; } foreach (KeyValuePair <string, byte[]> kp in provMetadata) { Logger.Append(Severity.TRIVIA, "Signaled backup to Incremental providers, got metadata from " + kp.Key); Index.AddProviderMetadata(kp.Key, brd, kp.Value); } } if (spoMetadatas != null) { //foreach(KeyValuePair<string,SPOMetadata> spoMetadata in spoMetadatas){ foreach (Tuple <string, SPOMetadata, List <string> > tuple in spoMetadatas) { if (tuple.Item2 != null) { using (MemoryStream mStr = new MemoryStream()){ (new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()).Serialize(mStr, tuple.Item2); Index.AddProviderMetadata(tuple.Item1, backupRootDrives[0], mStr.GetBuffer()); Index.AddSpecialObject(tuple.Item1, tuple.Item3); } } else { Logger.Append(Severity.WARNING, "Could'nt save metadata from provider '" + tuple.Item1 + "' : metadata is null"); } } } }