protected override GetBackupFolderFilesResult GetBackupFilesInFolder(string folder, DateTime startDateOfRetentionRange)
        {
            var    backupFiles     = new GetBackupFolderFilesResult();
            string blobsNextMarker = null;
            bool   firstFileSet    = false;

            do
            {
                var blobs = _client.ListBlobs(folder, delimiter: null, listFolders: false, marker: blobsNextMarker);

                foreach (var blob in blobs.List)
                {
                    if (firstFileSet == false)
                    {
                        backupFiles.FirstFile = blob.Name;
                        firstFileSet          = true;
                    }

                    if (RestorePointsBase.TryExtractDateFromFileName(blob.Name, out var lastModified) && lastModified > startDateOfRetentionRange)
                    {
                        backupFiles.LastFile = blob.Name;
                        return(backupFiles);
                    }
                }

                blobsNextMarker = blobs.NextMarker;
                CancellationToken.ThrowIfCancellationRequested();
            } while (blobsNextMarker != null);

            return(backupFiles);
        }
        protected override GetBackupFolderFilesResult GetBackupFilesInFolder(string folder, DateTime startDateOfRetentionRange)
        {
            var backupFiles = new GetBackupFolderFilesResult();
            // backups are ordered in lexicographical order
            var files = _client.ListObjects(folder, null, false, 1);

            backupFiles.FirstFile = files.FileInfoDetails?.Select(x => x.FullPath).FirstOrDefault();

            var startAfter = $"{folder}{startDateOfRetentionRange.ToString(BackupTask.DateTimeFormat, CultureInfo.InvariantCulture)}{Constants.Documents.PeriodicBackup.IncrementalBackupExtension}";

            files = _client.ListObjects(folder, null, false, take: 1, startAfter: startAfter);

            backupFiles.LastFile = files.FileInfoDetails?.Select(x => x.FullPath).LastOrDefault();

            return(backupFiles);
        }
Exemple #3
0
 private static Task <GetBackupFolderFilesResult> GetBackupFilesInFolderInternal(string folder)
 {
     try
     {
         var orderedBackups = Directory.GetFiles(folder).AsEnumerable().OrderBackups();
         var backupFiles    = new GetBackupFolderFilesResult
         {
             FirstFile = orderedBackups.FirstOrDefault(),
             LastFile  = orderedBackups.LastOrDefault()
         };
         return(Task.FromResult(backupFiles));
     }
     catch (DirectoryNotFoundException)
     {
         return(Task.FromResult((GetBackupFolderFilesResult)null));
     }
 }
        private bool GotFreshIncrementalBackup(GetBackupFolderFilesResult backupFiles, DateTime now)
        {
            if (backupFiles.LastFile == null)
            {
                return(false);
            }

            if (backupFiles.FirstFile.Equals(backupFiles.LastFile))
            {
                return(false);
            }

            if (RestorePointsBase.TryExtractDateFromFileName(backupFiles.LastFile, out var lastModified) == false)
            {
                lastModified = File.GetLastWriteTimeUtc(backupFiles.LastFile).ToLocalTime();
            }

            return(now - lastModified < _retentionPolicy.MinimumBackupAgeToKeep);
        }