Permalink
Browse files

[Dashboard] query for backup column

  • Loading branch information...
gboge committed May 10, 2017
1 parent 4a8f65d commit e9315a9d876270bfedf51ec6f3ee0198a23740fc
Showing with 35 additions and 1 deletion.
  1. +35 −1 KServer.cs
View
@@ -313,7 +313,6 @@ public static DataTable GetLiveQueriesProfiler(this smo.Server s)
, qt.text";
return d.ExecuteWithResults(_sql).Tables[0];
}
#endregion
#region Backups
@@ -1023,5 +1022,40 @@ public static DataTable GetTempDBSortWarning(this smo.Server s)
}
#endregion
#region Dashboard
/// <summary>
/// Get list of databases which are not backup for a while
/// </summary>
/// <param name="s">your smo server</param>
/// <param name="checkSystemDb">True if you want to check system database backup</param>
/// <param name="fromDays">Last backup must be done before this number of day</param>
/// <param name="fromHours">Last backup must be done before this number of hour</param>
/// <param name="fromMinutes">Last backup must be done before this number of minute</param>
/// <returns></returns>
public static DataTable DashboardBackup(this smo.Server s, bool checkSystemDb = false, int fromDays = 1, int fromHours = 0, int fromMinutes = 0)
{
smo.Database d = s.Databases["master"];
string filterDb = " WHERE sdb.name NOT IN ('master', 'tempdb', 'model', 'msdb') ";
if (checkSystemDb)
filterDb = " WHERE sdb.name != 'tempdb' ";
string sql = string.Format(@"SELECT DatabaseName
, LastBackUpTime
FROM
(
SELECT TOP 30 sdb.name AS DatabaseName
, MAX(bus.backup_finish_date) AS LastBackUpTime
FROM sys.databases sdb (nolock)
LEFT OUTER JOIN msdb.dbo.backupset bus (nolock) ON bus.database_name = sdb.name AND bus.is_snapshot !=1
{0}
AND sdb.state != 6
GROUP BY sdb.name
ORDER BY LastBackUpTime, DatabaseName
)a
WHERE a.LastBackUpTime IS NULL
OR a.LastBackUpTime < dateadd(DAY, {1}, dateadd(HOUR, {2}, dateadd(MINUTE, {3}, GETDATE())))", filterDb, fromDays, fromHours, fromMinutes);
return d.ExecuteWithResults(sql).Tables[0];
}
#endregion
}
}

0 comments on commit e9315a9

Please sign in to comment.