You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns last backup information for all databases on both instances, excluding availability group databases
108
+
where the current instance is not the preferred backup replica. This prevents false alerts when secondary
109
+
replicas appear to have no recent backups because backups are only performed on the preferred replica.
97
110
#>
98
111
[CmdletBinding()]
99
112
param (
@@ -103,6 +116,7 @@ function Get-DbaLastBackup {
103
116
$SqlCredential,
104
117
[object[]]$Database,
105
118
[object[]]$ExcludeDatabase,
119
+
[switch]$ExcludeReplica,
106
120
[switch]$EnableException
107
121
)
108
122
begin {
@@ -131,6 +145,16 @@ function Get-DbaLastBackup {
131
145
if ($ExcludeDatabase) {
132
146
$dbs=$dbs|Where-Object Name -NotIn$ExcludeDatabase
133
147
}
148
+
149
+
if ($ExcludeReplica-and$server.IsHadrEnabled) {
150
+
Write-Message-Level Verbose -Message "Excluding non-preferred backup replicas for $instance"
151
+
$notPreferredQuery="SELECT DB_NAME(database_id) AS DatabaseName FROM sys.databases WHERE sys.fn_hadr_backup_is_preferred_replica(DB_NAME(database_id)) = 0"
0 commit comments