Esempio n. 1
0
            public void FinishBackup_WhenDbContainsPartialHashes()
            {
                // Pst File is registered in Db but the hash table does not contains all hashes for the backup file
                // Arrange
                DeleteDb();
                CopyPartialFile();
                SUT      _backupEngine = new SUT(_appSettings, _dbFilename);
                ClientDb _clientDb     = new ClientDb(_dbFilename);

                _clientDb.RegisterNewPstFile(1, _pstFileToSave.SourcePath, Path.Combine(_destinationPath, _partialFilename));
                Assert.IsTrue(_clientDb.IsPstFileRegistered(_pstFileToSave.SourcePath));
                Assert.AreEqual(_clientDb.GetBackupFilePath(_pstFileToSave.SourcePath), Path.Combine(_destinationPath, _partialFilename), true);

                // Act
                _backupEngine.Backup((object)_pstFileToSave);
                DeleteFile(Path.Combine(_destinationPath, _pstFilename));
                CopyInterruptedFile();
                _clientDb.RenameBackupFile(_pstFileToSave.SourcePath, Path.Combine(_destinationPath, _partialFilename));
                int remainsHashes = (int)(_clientDb.GetHashes(1).Count * 75 / 100);

                _clientDb.DeleteHashes(1, remainsHashes);
                _backupEngine.Backup((object)_pstFileToSave);

                // Assert
                Assert.IsTrue(_clientDb.IsPstFileRegistered(_pstFileToSave.SourcePath));
                Assert.IsTrue(AreFilesEquals(_pstFileToSave.SourcePath, Path.Combine(_destinationPath, _pstFilename)));
                Assert.AreEqual(Path.Combine(_destinationPath, _pstFilename), _clientDb.GetBackupFilePath(_pstFileToSave.SourcePath), true);

                DeleteFile(Path.Combine(_destinationPath, _pstFilename));
            }
        public override void Backup(object objPstFileToSave)
        {
            try
            {
                PSTRegistryEntry pstFileToSave = (PSTRegistryEntry)objPstFileToSave;
                BackupResultInfo backupResult  = new BackupResultInfo(pstFileToSave);
                backupResult.IsCompressed = false;

                Logger.Write(30011, "Starting to backup " + pstFileToSave.SourcePath + " to file system with differential method", Logger.MessageSeverity.Debug);

                int           fileId       = CheckPrerequisitesForSmbBackup(pstFileToSave.SourcePath);
                string        backupFile   = _clientDb.GetBackupFilePath(pstFileToSave.SourcePath);
                List <string> remoteChunks = _clientDb.GetHashes(fileId);
                backupResult.ChunkCount = SynchonizeLocalAndRemoteFile(fileId, pstFileToSave.SourcePath, backupFile, remoteChunks);

                string backupFileNewName = FileSystem.GetNewName(backupFile);
                FileSystem.RenameFile(backupFile, backupFileNewName);
                _clientDb.RenameBackupFile(pstFileToSave.SourcePath, backupFileNewName);
                pstFileToSave.LastSuccessfulBackup = DateTime.Now;
                pstFileToSave.Save();
                backupResult.RemotePath     = backupFileNewName;
                backupResult.CompressedSize = 0;
                backupResult.ErrorCode      = BackupResultInfo.BackupResult.Success;
                backupResult.ErrorMessage   = String.Empty;
                backupResult.EndTime        = DateTime.UtcNow;
                Logger.Write(30012, pstFileToSave + " have been successfuly saved", Logger.MessageSeverity.Debug);

                if (!base.IsCancelRequired)
                {
                    BackupFinished(new BackupFinishedEventArgs(pstFileToSave, backupResult));
                }
            }
            catch (Exception ex)
            {
                Logger.Write(20024, "An error occurs while backuping a PST file with differential method\r\n" + ex.Message, Logger.MessageSeverity.Error, System.Diagnostics.EventLogEntryType.Error);
            }
        }