Example #1
0
 protected bool NeedMorePointsToSave(RestorePoint restorePoint)
 {
     if (restorePoint is FullRestorePoint)
     {
         return(false);
     }
     BackupLogger.GetInstance().Warning("To implement the algorithm for cleaning restore points, you must store one more point.");
     return(true);
 }
Example #2
0
        protected virtual void CheckArguments(int expected)
        {
            if (arguments.Count() == expected)
            {
                return;
            }
            var exception = new WrongArgumentAmountException(arguments.Count() + 1, expected + 1);

            BackupLogger.GetInstance().Error(exception.Message);
            throw exception;
        }
Example #3
0
 public void AddBackup(string filePath, string backupPath, StorageType storageType)
 {
     if (!File.Exists(filePath))
     {
         BackupLogger.GetInstance().Error($"Cannot add backup for the file {filePath}." +
                                          $" File {filePath} does not exist.");
         return;
     }
     Backups.Add(new Backup(filePath, backupPath, storageType));
     BackupLogger.GetInstance().Info($"Backup for the file {filePath} was added to the current backup system.");
 }
Example #4
0
 public BackupSystem(StorageType storageType, string commonFolder, List <string> fileList, Algorithm algorithm)
 {
     StorageType  = storageType;
     CommonFolder = commonFolder;
     Backups      = new List <Backup>();
     foreach (var file in fileList)
     {
         AddBackup(file, new StorageFolderFactory(storageType, file, commonFolder).GetFolder(), storageType);
     }
     Algorithm = algorithm;
     BackupLogger.GetInstance().Info($"New backup system with {Backups.Count} backup(s) created.");
 }
Example #5
0
 public Backup(string originalFilePath, string fullPath, StorageType storageType)
 {
     Id                 = Guid.NewGuid();
     CreationTime       = DateTime.Now;
     FullPath           = fullPath;
     OriginalFilePath   = originalFilePath;
     RestorePoints      = new List <RestorePoint>();
     StorageType        = storageType;
     RestorePointsCount = 0;
     BackupLogger.GetInstance().Info($"New backup for the file {OriginalFilePath} at path {FullPath} was created.\n" +
                                     $"Backup ID: {Id}.\nBackup storage type: {StorageType}.");
 }
Example #6
0
 public void DeleteRestore()
 {
     if (File.Exists(FullPath))
     {
         File.Delete(FullPath);
         BackupLogger.GetInstance().Info($"Restore point at path {FullPath} was deleted.");
     }
     else
     {
         BackupLogger.GetInstance().Error($"Restore point at path {FullPath} does not exist.");
     }
 }
Example #7
0
        public void RemoveBackup(string filePath)
        {
            var backup = Backups.FirstOrDefault(b => b.OriginalFilePath == filePath);

            if (backup is null)
            {
                BackupLogger.GetInstance().Error(
                    $"Backup for the file {filePath} does not exist in the current backup system.");
                return;
            }
            Backups.Remove(backup);
            BackupLogger.GetInstance().Info($"Backup for the file {filePath} was removed from the current backup system.");
        }
Example #8
0
        private void CreateBackup(ParsedData parsedData)
        {
            _dataFile = parsedData.DataFile;
            if (File.Exists(_dataFile + ".dat"))
            {
                var exception = new DataFileAlreadyExistsException(_dataFile + ".dat");
                BackupLogger.GetInstance().Error(exception.Message);
                throw exception;
            }
            File.Create(_dataFile + ".dat").Close();

            _backupSystem = parsedData.BackupSystem;
            _backupSystem.CreateRestore(new RestoreFactory(RestoreType.Full));
        }
Example #9
0
 public override void CreateRestore()
 {
     File.Create(FullPath).Close();
     File.WriteAllLines(FullPath, new[]
     {
         "Incremental restore point\n",
         CreationTime.ToString(CultureInfo.CurrentCulture),
         Size.ToString(),
         Name,
         DirectoryName,
         FullPath,
         OriginalFilePath
     });
     BackupLogger.GetInstance().Info($"Incremental restore point at path {FullPath} was created.");
 }