Skip to content

Commit 946da21

Browse files
committed
fix(backups): no full backup
1 parent a894188 commit 946da21

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/AgDatabase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,19 @@ public List<BackupMetadata> RecentBackups()
131131
{
132132
// find most recent full backup LSN across all replica servers
133133
var fullBackupLsnBag = new ConcurrentBag<decimal>();
134-
_listener.ForEachAgInstance(s => fullBackupLsnBag.Add(s.Database(Name).MostRecentFullBackupLsn()));
134+
_listener.ForEachAgInstance(s =>
135+
{
136+
try
137+
{
138+
fullBackupLsnBag.Add(s.Database(Name).MostRecentFullBackupLsn());
139+
}
140+
catch { }
141+
});
135142

136143
// find all backups in that chain
144+
if (fullBackupLsnBag.Count == 0)
145+
throw new Exception("Could not find any full backups");
146+
137147
var databaseBackupLsn = fullBackupLsnBag.Max();
138148
var bag = new ConcurrentBag<BackupMetadata>();
139149
_listener.ForEachAgInstance(s => s.Database(Name).BackupChainFromLsn(databaseBackupLsn)

src/SmoFacade/Database.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ public decimal MostRecentFullBackupLsn()
131131
using var reader = cmd.ExecuteReader();
132132
if(!reader.Read())
133133
throw new Exception("MostRecentFullBackup SQL found no results");
134+
135+
var lsnValue = reader["most_recent_full_backup_checkpoint_lsn"];
134136

135-
return (decimal)reader["most_recent_full_backup_checkpoint_lsn"];
137+
if (lsnValue == DBNull.Value)
138+
throw new Exception("MostRecentFullBackup SQL found no results");
139+
140+
return (decimal)lsnValue;
136141
}
137142

138143
public List<BackupMetadata> BackupChainFromLsn(decimal checkpointLsn)

0 commit comments

Comments
 (0)