Beispiel #1
0
        public RestorePoint CreateBackup(RestorePoint lastPoint, List <string> objectsForBackup, BackupStoringAlgorithm storingAlgorithm)
        {
            var lastFullBackupPoint = lastPoint;

            while (lastFullBackupPoint != null && !(lastFullBackupPoint is FullBackupPoint))
            {
                lastFullBackupPoint = lastFullBackupPoint.PreviousPoint;
            }

            if (lastFullBackupPoint == null)
            {
                throw new IncrementalBackupCannotBeFirstException();
            }

            var list = new Dictionary <string, FileRestoreCopyInfo>();

            foreach (var filePath in objectsForBackup)
            {
                // Упрощение: Если нет, или изменился размер файла
                if (!lastPoint.Info.ContainsKey(filePath) ||
                    lastPoint.Info[filePath].BackupSize != new FileInfo(filePath).Length)
                {
                    var point = lastPoint;
                    while (!point.Info.ContainsKey(filePath) && !(point is FullBackupPoint))
                    {
                        point = point.PreviousPoint;
                    }

                    var size = new FileInfo(filePath).Length;
                    if (!point.Info.ContainsKey(filePath))
                    {
                        size = Math.Abs(size - point.Info[filePath].BackupSize);
                    }

                    list.Add(filePath, new FileRestoreCopyInfo(filePath, size, DateTimeProvider.Now, storingAlgorithm.BackupPath));
                    // storingAlgorithm.CopyFile(filePath);
                }
            }

            if (list.Count == 0)
            {
                throw new NoChangesForIncrementalBackupException();
            }

            return(new IncrementalBackupPoint(lastPoint, list, DateTimeProvider.Now));
        }
Beispiel #2
0
        public RestorePoint CreateBackup(RestorePoint lastPoint, List <string> objectsForBackup, BackupStoringAlgorithm storingAlgorithm)
        {
            var list = new Dictionary <string, FileRestoreCopyInfo>();

            foreach (var filePath in objectsForBackup)
            {
                list.Add(filePath, new FileRestoreCopyInfo(filePath, new FileInfo(filePath).Length, DateTimeProvider.Now, storingAlgorithm.BackupPath));
                // storingAlgorithm.CopyFile(filePath);
            }

            return(new FullBackupPoint(lastPoint, list, DateTimeProvider.Now));
        }