Exemple #1
0
        private BackupResultInfo BackupWithCompression(PSTRegistryEntry pstFileToSave, BackupResultInfo backupResult)
        {
            FileInfo sourceFile             = new FileInfo(pstFileToSave.SourcePath);
            string   finalDestinationFolder = FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath);

            DirectoryInfo compressionFolder = new DirectoryInfo(FileSystem.GetTemporaryFolder());

            if (HasEnoughDiskspace(compressionFolder, sourceFile.Length / 2))
            {
                string destinationFilePath = Path.Combine(compressionFolder.FullName, sourceFile.Name + ".gz.temp");
                CompressFile(sourceFile.FullName, destinationFilePath);
                CopyFile(destinationFilePath, Path.Combine(finalDestinationFolder, sourceFile.Name + ".gz.temp"), true);
                FileInfo compressedFile = new FileInfo(Path.Combine(finalDestinationFolder, sourceFile.Name + ".gz"));
                FileSystem.RenameFile(Path.Combine(finalDestinationFolder, sourceFile.Name + ".gz.temp"), compressedFile.FullName);
                backupResult.RemotePath     = compressedFile.FullName;
                backupResult.CompressedSize = compressedFile.Length;

                try
                {
                    compressionFolder.Delete(true);
                }
                catch (Exception) { }
            }
            else
            {
                throw new NotEnoughEstimatedDiskSpace(compressionFolder.FullName);
            }

            return(backupResult);
        }
Exemple #2
0
        private void LaunchBackup(PSTRegistryEntry pstFileToSave)
        {
            try
            {
                Logger.Write(23, "Starting to save " + pstFileToSave.SourcePath, Logger.MessageSeverity.Information);
                Action SetCurrentFileFinished = () =>
                { chkLstBxPstFiles.SetItemCheckState(_currentFileIndex, CheckState.Indeterminate); };
                if (this.InvokeRequired)
                {
                    this.Invoke(SetCurrentFileFinished);
                }
                else
                {
                    SetCurrentFileFinished();
                }

                _backupThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(_bckEngine.Backup));
                _backupThread.IsBackground = true;
                _backupThread.Start(pstFilesToSave[0]);
            }
            catch (Exception ex)
            {
                Logger.Write(20021, "An error occurs while starting to backup a PST file.\r\n" + ex.Message, Logger.MessageSeverity.Error, System.Diagnostics.EventLogEntryType.Error);
            }
        }
Exemple #3
0
        /// <summary>
        /// Add into Registry, new PST files that or not already registred in the registry
        /// </summary>
        /// <param name="registryEntries">List of all registry entries.</param>
        /// <param name="pstFileList">List of all PST files mounted in Outlook.</param>
        public static void RegisterNewPstFilesInRegistry(List <PSTRegistryEntry> registryEntries, List <string> pstFileList)
        {
            try
            {
                foreach (string pstFile in pstFileList)
                {
                    bool found = false;

                    foreach (PSTRegistryEntry regEntry in registryEntries)
                    {
                        if (regEntry.SourcePath.ToLower() == pstFile.ToLower())
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        PSTRegistryEntry regEntry = new PSTRegistryEntry(pstFile.ToLower());
                        registryEntries.Add(regEntry);
                    }
                }
            }
            catch (Exception ex) { Logger.Write(20019, "An error occurs while registering new PST files.\r\n" + ex.Message, Logger.MessageSeverity.Error, System.Diagnostics.EventLogEntryType.Error); }

            DeletePstFileRegistryEntries();
            for (int i = 0; i < registryEntries.Count; i++)
            {
                var regEntry = registryEntries[i];
                regEntry.RegistryPath = @"HKEY_CURRENT_USER\Software\PST Backup\PST Files\" + i.ToString();
                regEntry.Save();
            }
        }
            public void CreateNewEntryInRegistry_WhenThereIsNewPstFiles()
            {
                // Arrange
                List <PSTRegistryEntry> backupEntries = ApplicationSettings.GetPstRegistryEntries();

                DeletePstFilesEntries();
                int index = 0;
                List <PSTRegistryEntry> registryEntries = new List <PSTRegistryEntry>();
                PSTRegistryEntry        regEntry;

                regEntry = new PSTRegistryEntry(@"E:\Pst Backup\Pst Files\Archive2009.pst");
                regEntry.RegistryPath = @"HKEY_CURRENT_USER\Software\PST Backup\PST Files\" + index;
                registryEntries.Add(regEntry);
                index++;
                regEntry = new PSTRegistryEntry(@"E:\Pst Backup\Pst Files\Archive2010.pst");
                regEntry.RegistryPath = @"HKEY_CURRENT_USER\Software\PST Backup\PST Files\" + index;
                registryEntries.Add(regEntry);
                index++;
                regEntry = new PSTRegistryEntry(@"E:\Pst Backup\Pst Files\Archive2011.pst");
                regEntry.RegistryPath = @"HKEY_CURRENT_USER\Software\PST Backup\PST Files\" + index;
                registryEntries.Add(regEntry);
                index++;
                foreach (var registryEntry in registryEntries)
                {
                    registryEntry.Save();
                }
                List <string> pstFiles = new List <string>();

                pstFiles.Add(@"E:\Pst Backup\Pst Files\Archive2005.pst".ToLower());
                pstFiles.Add(@"E:\Pst Backup\Pst Files\Archive2006.pst".ToLower());
                pstFiles.Add(@"E:\Pst Backup\Pst Files\Archive2007.pst".ToLower());

                // Act
                SUT.RegisterNewPstFilesInRegistry(registryEntries, pstFiles);
                registryEntries = ApplicationSettings.GetPstRegistryEntries();
                // Restore registry entries
                DeletePstFilesEntries();
                foreach (var registryEntry in backupEntries)
                {
                    registryEntry.Save();
                }

                // Assert
                Assert.AreEqual(6, registryEntries.Count);
                foreach (var pstFile in pstFiles)
                {
                    bool found = false;
                    foreach (var pstRegistryEntry in registryEntries)
                    {
                        if (pstRegistryEntry.SourcePath == pstFile)
                        {
                            found = true;
                            break;
                        }
                    }
                    Assert.IsTrue(found);
                }
            }
Exemple #5
0
 public BackupResultInfo(PSTRegistryEntry pstFile)
 {
     System.IO.FileInfo fileToSave = new System.IO.FileInfo(pstFile.SourcePath);
     LocalPath    = fileToSave.FullName;
     FileSize     = fileToSave.Length;
     ChunkCount   = 0;
     StartTime    = DateTime.UtcNow;
     ErrorCode    = BackupResult.NotStarted;
     ErrorMessage = "An unknown error occurs.";
 }
Exemple #6
0
 private ReportService.PstFile GetPstFile(PSTRegistryEntry regEntry)
 {
     ReportService.PstFile pstFile = new ReportService.PstFile()
     {
         LocalPath            = regEntry.SourcePath,
         LastSuccessfulBackup = regEntry.LastSuccessfulBackup,
         IsSetToBackup        = regEntry.ToBackup,
         Size = new System.IO.FileInfo(regEntry.SourcePath).Length
     };
     return(pstFile);
 }
Exemple #7
0
        private BackupResultInfo BackupWithoutCompression(PSTRegistryEntry pstFileToSave, BackupResultInfo backupResult)
        {
            FileInfo sourceFile             = new FileInfo(pstFileToSave.SourcePath);
            string   finalDestinationFolder = FileSystem.ExpandDestinationFolder(AppSettings.FilesAndFoldersDestinationPath);

            CopyFile(sourceFile.FullName, Path.Combine(finalDestinationFolder, sourceFile.Name + ".temp"), false);
            FileSystem.RenameFile(Path.Combine(finalDestinationFolder, sourceFile.Name + ".temp"), Path.Combine(finalDestinationFolder, sourceFile.Name));
            backupResult.RemotePath     = Path.Combine(finalDestinationFolder, sourceFile.Name);
            backupResult.CompressedSize = backupResult.FileSize;

            return(backupResult);
        }
Exemple #8
0
            public static void ClassInitialize(TestContext context)
            {
                DateTime _today     = DateTime.Now;
                DateTime _lastMonth = _today.AddMonths(-1);
                DateTime _yesterday = _today.AddDays(-1);

                PSTRegistryEntry _toBackup_today = new PSTRegistryEntry();

                _toBackup_today.ToBackup             = true;
                _toBackup_today.LastSuccessfulBackup = _today;

                PSTRegistryEntry _toBackup_lastMonth = new PSTRegistryEntry();

                _toBackup_lastMonth.ToBackup             = true;
                _toBackup_lastMonth.LastSuccessfulBackup = _lastMonth;

                PSTRegistryEntry _toBackup_yesterday = new PSTRegistryEntry();

                _toBackup_yesterday.ToBackup             = true;
                _toBackup_yesterday.LastSuccessfulBackup = _yesterday;

                PSTRegistryEntry _toNotBackup_today = new PSTRegistryEntry();

                _toNotBackup_today.ToBackup             = false;
                _toNotBackup_today.LastSuccessfulBackup = _today;

                PSTRegistryEntry _toNotBackup_lastMonth = new PSTRegistryEntry();

                _toNotBackup_lastMonth.ToBackup             = false;
                _toNotBackup_lastMonth.LastSuccessfulBackup = _lastMonth;

                PSTRegistryEntry _toNotBackup_yesterday = new PSTRegistryEntry();

                _toNotBackup_yesterday.ToBackup             = false;
                _toNotBackup_yesterday.LastSuccessfulBackup = _yesterday;

                _allPstFiles.Add(_toBackup_yesterday);
                _allPstFiles.Add(_toBackup_today);
                _allPstFiles.Add(_toBackup_lastMonth);
                _allPstFiles.Add(_toNotBackup_lastMonth);
                _allPstFiles.Add(_toNotBackup_today);
                _allPstFiles.Add(_toNotBackup_yesterday);

                appSettings.SchedulePolicy   = ApplicationSettings.BackupPolicy.EveryX;
                appSettings.ScheduleInterval = 8;
                appSettings.ScheduleUnit     = ApplicationSettings.BackupUnit.Days;
            }
Exemple #9
0
        public override void Backup(object objPstFileToSave)
        {
            PSTRegistryEntry pstFileToSave = (PSTRegistryEntry)objPstFileToSave;
            BackupResultInfo backupResult  = new BackupResultInfo(pstFileToSave);

            backupResult.IsCompressed = AppSettings.FilesAndFoldersCompressFiles;
            try
            {
                Logger.Write(30015, "Starting to backup " + pstFileToSave.SourcePath + " to file system with full method\r\n", Logger.MessageSeverity.Debug);
                // Backup to SMB destination
                backupResult = backupResult.IsCompressed ? BackupWithCompression(pstFileToSave, backupResult) : BackupWithoutCompression(pstFileToSave, backupResult);

                backupResult.ErrorCode             = BackupResultInfo.BackupResult.Success;
                backupResult.ErrorMessage          = String.Empty;
                pstFileToSave.LastSuccessfulBackup = DateTime.UtcNow;
            }
            catch (BackupCanceledException ex)
            {
                Logger.Write(24, "Backup of " + ex.PstFilename + " have been canceled by the user", Logger.MessageSeverity.Warning);
            }
            catch (NotEnoughEstimatedDiskSpace ex)
            {
                Logger.Write(10002, "Not enough estimated disk space on " + ex.Destination, Logger.MessageSeverity.Warning, System.Diagnostics.EventLogEntryType.Warning);
                backupResult.ErrorCode    = BackupResultInfo.BackupResult.Failed;
                backupResult.ErrorMessage = "Not enough estimated disk space on " + ex.Destination;
            }
            catch (Exception ex)
            {
                Logger.Write(20025, "An error occurs while saving a PST file with full method\r\n" + ex.Message, Logger.MessageSeverity.Error, System.Diagnostics.EventLogEntryType.Error);
                backupResult.ErrorCode    = BackupResultInfo.BackupResult.Failed;
                backupResult.ErrorMessage = ex.Message;
            }
            if (!base.IsCancelRequired)
            {
                backupResult.EndTime = DateTime.UtcNow;
                pstFileToSave.Save();
                BackupFinished(new BackupFinishedEventArgs(pstFileToSave, backupResult));
            }
        }
        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);
            }
        }
Exemple #11
0
 public static void ClassInitialize(TestContext context)
 {
     _appSettings.FilesAndFoldersDestinationPath = _destinationPath;
     _appSettings.BackupAgentBackupMethod        = ApplicationSettings.BackupMethod.Differential;
     _pstFileToSave = new PSTRegistryEntry(Path.Combine(_sourcePath, _pstFilename));
 }
Exemple #12
0
 /// <summary>
 /// Create an instance of the event args
 /// </summary>
 /// <param name="pstRegistryEntry">A reference to the PstRegistryEntry</param>
 /// <param name="backupResult">A reference to the Result of the backup</param>
 public BackupFinishedEventArgs(PSTRegistryEntry pstRegistryEntry, BackupResultInfo backupResult)
 {
     PstRegistryEntry = pstRegistryEntry;
     Result           = backupResult;
 }