internal BackupIndex GetFullIndex(long refTaskId) { BackupIndex bi = null; try{ bi.OpenByName("s" + refTaskId + ".idx"); } catch (System.IO.FileNotFoundException) { // synthetic not found, ref backup might be a full, let's try try{ bi.OpenByTaskId(refTaskId); if (bi.Header.BackupType == P2PBackup.Common.BackupType.Full) { return(bi); } else // ref task was not a full and no synthetic full, re-generate a synthetic { Logger.Append(Severity.WARNING, "Could not find reference task synthetic index, will try to re-create..."); } } catch (System.IO.FileNotFoundException) { //INDEX not found. ask to hub and retrieve from storage node Logger.Append(Severity.WARNING, "Could not find synthetic nor partial indexes, will try to retrieve them"); } } return(null); }
//Placeholder for Jame's code to restore files private void btnRestore_Click(object sender, EventArgs e) { //Retrieves data about selected recovery file, stores in object {source path, original size, backup time/date} string guid = Backend.Properties.Settings.Default.guid.ToString(); string dateAndTime = (string)dataGridViewBackupInfo.Rows[0].Cells["backupTime"].Value; BackupIndex index = indexDB.GetBackupIndex(guid, dateAndTime); string recoveryDestinationDirectory = txtRecoveryDestination.Text; }
private void dataGridViewRecoveryDateTimeInfo_CellContentClick(object sender, DataGridViewCellEventArgs e) { string guid = Backend.Properties.Settings.Default.guid.ToString(); string dateAndTime = (string)dataGridViewRecoveryDateTimeInfo.SelectedRows[0].Cells["colDateTime"].Value; BackupIndex index = indexDB.GetBackupIndex(guid, dateAndTime); //Updates data grid based on values of backup index dataGridViewBackupInfo.Rows[0].Cells["sourcePath"].Value = index.sourcePath; dataGridViewBackupInfo.Rows[0].Cells["size"].Value = index.size; dataGridViewBackupInfo.Rows[0].Cells["backupTime"].Value = index.dateAndTime; //column is not visible }
internal void CreateSyntheticFullIndex(long referenceTask, long task) { BackupIndex refIndex = null; BackupIndex mergeIndex = null; try{ //Console.WriteLine ("CreateSyntheticFullIndex(): 1"); refIndex = new BackupIndex(); //Console.WriteLine ("CreateSyntheticFullIndex(): 2"); mergeIndex = new BackupIndex(task); //Console.WriteLine ("CreateSyntheticFullIndex(): 3"); refIndex.OpenByTaskId(referenceTask); Logger.Append(Severity.DEBUG, "Opened reference index " + referenceTask + "..."); //Console.WriteLine ("CreateSyntheticFullIndex(): 4"); taskIndex.OpenByTaskId(task); Console.WriteLine("CreateSyntheticFullIndex() : opened indexes"); if (refIndex.Header.TaskId != referenceTask) { Logger.Append(Severity.ERROR, "Reference index doesn't handle expected task (wanted " + referenceTask + ", got " + refIndex.Header.TaskId); return; } // synthetic index will have the header of the just-ended task mergeIndex.Header = taskIndex.Header; mergeIndex.WriteHeaders(); BChunk refChunk; //taskChunk = taskIndex.ReadChunk(); // walk the reference (synthetic) index and merge changes from the new backup index. while ((refChunk = refIndex.ReadChunk()) != null) { Console.WriteLine("CreateSFI() : reading chunk " + refChunk.Name + ", " + refChunk.Files.Count + " items"); for (int i = refChunk.Files.Count - 1; i >= 0; i--) { //foreach(IFile item in refChunk.Files){ //Console.WriteLine("CreateSFI() : chunk "+refChunk.Name+", item "+item.OriginalFullPath+", type="+item.Kind); IFSEntry newEntry = SearchItemInActualIndex(refChunk.Files[i]); if (newEntry != null) { Console.WriteLine("CreateSFI() : found updated entry " + newEntry.OriginalFullPath); refChunk.Files.RemoveAt(i); } } if (refChunk.Files.Count > 0) { mergeIndex.AddChunk(refChunk); } } foreach (BChunk newChunk in actualTaskChunks) { mergeIndex.AddChunk(newChunk); } } catch (Exception e) { Logger.Append(Severity.ERROR, "Error creating synthetic full index : " + e.Message + " ---- " + e.StackTrace); } finally{ try{ refIndex.Terminate(); taskIndex.Terminate(); mergeIndex.Terminate(); } catch (Exception e) { // harmless for backup and indexes consistency, but will leave open files descriptors. // However this case should not happen in real-life Logger.Append(Severity.ERROR, "Error closing indexes : " + e.Message); } } }
protected void checkStorageThread() { if (storageThread.NumChunks() > 0) { Chunk chunk = storageThread.DequeueChunk(); Logger.Debug("EchoBackupService:checkStorageThread Finished archiving chunk."); //identify host(s) to send to. List <GuidAndIP> gai = NetworkFunctions.GetOnlineNodesIPAddresses(); if (gai.Count < 2) { Logger.Warn("EchoBackupService:checkStorageThread not enough online hosts. hosts online: " + gai.Count); } //send chunk to hosts. List <Block> blocks = new List <Block>(); long filesize = new FileInfo(chunk.Path()).Length; for (int i = 0; i < 2 && i < gai.Count; i++) { TcpClient tc = new TcpClient(gai[i].ipAddress.ToString(), CommandServer.SERVER_PORT); ClientThread ct = new ClientThread(tc, false, this.guid); PushRequest pr = new PushRequest(Node.GetIPAddress(), this.guid, MiscFunctions.Next()); pr.Path = chunk.Path(); pr.FileSize = filesize; pr.BackupNumber = chunk.BackupID(); pr.ChunkNumber = chunk.ChunkID(); ct.EnqueueWork(pr); lock (clientThreads) { clientThreads.Add(ct); } blocks.Add(new Block(this.guid.ToString(), gai[i].guid.ToString(), "bad storage path", filesize, MiscFunctions.DBDateAndTime())); } //do something with the index so we know about this backup //store files in BackupIndex IndexDatabase idb = new IndexDatabase(); foreach (FileInChunk fic in chunk.Files()) { BackupIndex bi = new BackupIndex(); string fullpath = Path.Combine(chunk.BasePath(), fic.path); if (Directory.Exists(fullpath)) { continue; } bi.backupLevel = 0; bi.dateAndTime = MiscFunctions.DBDateAndTime(); bi.firstBlockOffset = 0; bi.size = new FileInfo(fullpath).Length; bi.sourceGUID = this.guid.ToString(); bi.sourcePath = fullpath; //todo: we cannot insert multiple blocks for every file. that is what the index-to-block table is for //idb.InsertIndex(bi, blocks); } //store indexes in DB } if (storageThread.NumRecoverStructs() > 0) { RecoverResult rs = storageThread.DequeueRecoverResult(); lock (recoverResults) { recoverResults.Enqueue(rs); } } }