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));
            }
Esempio n. 2
0
            public void BackupToNewDestination_WhenDestinationChangeAfterCompletBakupOccurs()
            {
                // PST File is registred in Db and PST file exists but the destination folder have changed
                // Arrange
                DeleteDb();
                CopyPstFile();
                SUT      _backupEngine = new SUT(_appSettings, _dbFilename);
                ClientDb _clientDb     = new ClientDb(_dbFilename);

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

                // Act
                _appSettings.FilesAndFoldersDestinationPath = @"\\192.168.0.250\share\Transit\PstFiles\courtel2";
                _backupEngine.Backup((object)_pstFileToSave);

                // Assert
                Assert.IsTrue(_clientDb.IsPstFileRegistered(_pstFileToSave.SourcePath));
                Assert.IsTrue(AreFilesEquals(_pstFileToSave.SourcePath, Path.Combine(@"\\192.168.0.250\share\Transit\PstFiles\courtel2", _pstFilename)));
                Assert.AreEqual(Path.Combine(@"\\192.168.0.250\share\Transit\PstFiles\courtel2", _pstFilename), _clientDb.GetBackupFilePath(_pstFileToSave.SourcePath), true);

                DeleteFile(Path.Combine(@"\\192.168.0.250\share\Transit\PstFiles\courtel2", _pstFilename));
                DeleteFile(Path.Combine(_destinationPath, _pstFilename));
            }
Esempio n. 3
0
            public void RegisterNewPstFileThenDeletePartialFileAndCreateNewOne_WhenPstFileIsNotRegisteredInDbButPartialFileExists()
            {
                // PST File is not registred in Db but partial file exists.
                // Arrange
                DeleteDb();
                CopyPartialFile();
                SUT      _backupEngine = new SUT(_appSettings, _dbFilename);
                ClientDb _clientDb     = new ClientDb(_dbFilename);

                Assert.IsFalse(_clientDb.IsPstFileRegistered(_pstFileToSave.SourcePath));

                // Act
                _backupEngine.Backup((object)_pstFileToSave);

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

                DeleteFile(Path.Combine(_destinationPath, _pstFilename));
            }
Esempio n. 4
0
            public void UseInformationsFromDbThenBackupFile_WhenPstFileIsRegisteredInDbAndPartialFileDoesNotExists()
            {
                // PST File is registred in Db but partial file does not exists.
                // Arrange
                DeleteDb();
                DeleteFile(Path.Combine(_destinationPath, _partialFilename));
                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);
                Assert.IsFalse(File.Exists(Path.Combine(_destinationPath, _partialFilename)));

                // Act
                _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));
            }
        private int CheckPrerequisitesForSmbBackup(string pstFileToSave)
        {
            FileInfo backupFile;
            FileInfo sourceFile = new FileInfo(pstFileToSave);
            int      fileId     = 0;

            if (_clientDb.IsPstFileRegistered(pstFileToSave))
            {
                // PST file is already known in the database
                fileId     = _clientDb.GetFileID(pstFileToSave);
                backupFile = new FileInfo(_clientDb.GetBackupFilePath(pstFileToSave).ToLower());
                if (String.Compare(backupFile.DirectoryName, FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath), true) != 0)
                {
                    // Destination have change
                    backupFile = new FileInfo(Path.Combine(FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath), backupFile.Name));
                    _clientDb.RenameBackupFile(pstFileToSave, backupFile.FullName);
                    _clientDb.DeleteHashes(fileId, 0);
                }
                if (backupFile.Name.EndsWith(".pst"))
                {
                    // Backup File is PST
                    _clientDb.RenameBackupFile(pstFileToSave, backupFile.FullName + ".partial");
                    if (backupFile.Exists)
                    {
                        // Backup.pst exists
                        File.Move(backupFile.FullName, backupFile.FullName + ".partial");
                    }
                    else
                    {
                        // Backup.pst does not exists
                        _clientDb.DeleteHashes(fileId, 0);
                    }
                }
                else
                {
                    // Backup File is Partial
                    if (!backupFile.Exists)
                    {
                        // BackupFile.pst.partial does not exists
                        _clientDb.DeleteHashes(fileId, 0);
                    }
                }
            }
            else
            {
                // PST file is not in the database
                fileId     = _clientDb.GetAvailableFileId();
                backupFile = new FileInfo(Path.Combine(FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath), sourceFile.Name + ".partial"));
                _clientDb.RegisterNewPstFile(fileId, pstFileToSave, backupFile.FullName);

                if (backupFile.Exists)
                {
                    // backup.pst.partial already exists
                    backupFile.Delete();
                }
            }

            // Create or Resize
            backupFile = new FileInfo(Path.Combine(FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath), sourceFile.Name + ".partial"));
            if (FileSystem.ResizeFile(backupFile.FullName, sourceFile.Length) == -1)
            {
                // backup file have been shrinked, shrink Hashes table
                _clientDb.ShrinkChunkList(fileId, sourceFile.Length, _chunkSize);
            }
            return(fileId);
        }