/// <summary> /// Returns "" if there is no completed recovery or a recovery failed. /// Returns the path to the output directory if recovery succeeded. /// </summary> /// <returns></returns> public string CheckRecovery(/*long fileID, Guid sourceNode*/) { lock (recoverResults) { if (recoverResults.Count > 0) { RecoverResult rr = recoverResults.Dequeue(); if (rr.Successful) { return(Path.GetDirectoryName(rr.Path)); } else { Logger.Error("EchoBackupService:CheckRecovery Recovery failed"); } } } return(""); }
public virtual void RecoverResult(C context, RecoverResult mystruct) { }
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); } } }
private void processTask(RestoreTask task) { Logger.Debug("StorageThread:processTask:RestoreTask"); Stream inStream = File.OpenRead(task.ArchivePath); Stream gzipStream = new GZipInputStream(inStream); TarInputStream tarStream = new TarInputStream(gzipStream); TarEntry entry; List<string> list = task.RelativeFilenames(); RecoverResult recover = new RecoverResult(task.OutputDir, true); while ((entry = tarStream.GetNextEntry()) != null) { if (entry.IsDirectory) continue; if (list.IndexOf(entry.Name) != -1) { string name = entry.Name.Replace('/', Path.DirectorySeparatorChar); name = Path.Combine(task.OutputDir, name); Directory.CreateDirectory(Path.GetDirectoryName(name)); FileStream outStream = new FileStream(name, FileMode.CreateNew); tarStream.CopyEntryContents(outStream); outStream.Close(); DateTime myDt = DateTime.SpecifyKind(entry.ModTime, DateTimeKind.Utc); File.SetLastWriteTime(name, myDt); } } tarStream.Close(); lock (_lock) { recoverResults.Enqueue(recover); } }