Beispiel #1
0
        /// <summary>
        /// tests the basic Tar and GZip functionality.
        /// </summary>
        static void testTarGZip()
        {
            Console.WriteLine("starting testTarBzip2");
            byte[]        b         = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            Guid          guid      = new Guid(b);
            string        tempPath  = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch";
            string        tempPath2 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\temp\\scratch 2";
            StorageThread st        = new StorageThread(tempPath, guid);
            BackupTask    task      = new BackupTask(tempPath, tempPath2, 123, 0);

            st.EnqueueStorageTask(task);
            Console.WriteLine("queued task");
            int x = 0;

            while (st.IsWorking())
            {
                x++;
                Console.WriteLine("waiting for thread to finish." + x);
                Thread.Sleep(1000);
            }
            Console.WriteLine("thread finished.");
            st.RequestStop();
            Console.WriteLine("requested thread terminate.");
            while (st.IsAlive())
            {
                x++;
                Console.WriteLine("waiting for thread to die. " + x);
                Thread.Sleep(1000);
            }
            Console.WriteLine("thread is dead.");
            Console.WriteLine("number of chunks: " + st.NumChunks());
            while (st.NumChunks() > 0)
            {
                Chunk c = st.DequeueChunk();
                Console.WriteLine(c);
            }

            Console.WriteLine("press a key to continue");
            Console.ReadKey();
        }
Beispiel #2
0
 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);
         }
     }
 }