Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/AgDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,19 @@ public List<BackupMetadata> RecentBackups()
{
// find most recent full backup LSN across all replica servers
var fullBackupLsnBag = new ConcurrentBag<decimal>();
_listener.ForEachAgInstance(s => fullBackupLsnBag.Add(s.Database(Name).MostRecentFullBackupLsn()));
_listener.ForEachAgInstance(s =>
{
try
{
fullBackupLsnBag.Add(s.Database(Name).MostRecentFullBackupLsn());
}
catch { }
});

// find all backups in that chain
if (fullBackupLsnBag.IsEmpty)
throw new Exception($"Could not find any full backups for DB '{Name}'");

var databaseBackupLsn = fullBackupLsnBag.Max();
var bag = new ConcurrentBag<BackupMetadata>();
_listener.ForEachAgInstance(s => s.Database(Name).BackupChainFromLsn(databaseBackupLsn)
Expand Down
7 changes: 6 additions & 1 deletion src/SmoFacade/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ public decimal MostRecentFullBackupLsn()
using var reader = cmd.ExecuteReader();
if(!reader.Read())
throw new Exception("MostRecentFullBackup SQL found no results");

var lsnValue = reader["most_recent_full_backup_checkpoint_lsn"];

return (decimal)reader["most_recent_full_backup_checkpoint_lsn"];
if (lsnValue == DBNull.Value)
throw new Exception("MostRecentFullBackup SQL found no results");

return (decimal)lsnValue;
}

public List<BackupMetadata> BackupChainFromLsn(decimal checkpointLsn)
Expand Down