Verificar Backups por TSQL
Verificar que se hayan realizado correctamente los backups es tarea fundamental de un DBA.
Para ello contamos con una serie de tablas provistar por Microsoft SQL Server para almacenar dicha información:
- msdb.dbo.backupfile
- msdb.dbo.backupmediafamily
- msdb.dbo.backupmediaset
- msdb.dbo.backupset
Los siguientes scripts pueden facilitar dicha tarea.
Más adelante trabajaremos con más detalle.
Atención: Si copian y pegan puede que la comilla simple (‘) se convierta a comilla doble («»).
/*******************************************************************************
Último Backup de la Base
******************************************************************************/
SELECT S.Name AS DB, MAX(B.backup_finish_date) Fecha,DATEDIFF(hh,MAX(B.backup_finish_date),GETDATE()) Antiguedad_HS ,
CASE
WHEN DATEDIFF(hh , MAX(B.backup_finish_date) , GETDATE()) > 24 THEN ‘SI’
WHEN MAX(B.backup_finish_date) IS NULL THEN ‘SI’ ELSE »
END AS SinBackupUltimas24hs
FROM sys.sysdatabases S LEFT OUTER JOIN msdb.dbo.backupset B ON B.database_name = S.name
WHERE B.type NOT LIKE ‘L’ AND S.name NOT LIKE ‘tempdb’
GROUP BY S.Name ORDER BY S.Name
/*******************************************************************************
Ultimo Backup del Log
******************************************************************************/
SELECT S.Name AS DB,MAX(B.backup_finish_date) Fecha ,
CASE WHEN DATEDIFF(hh , MAX(B.backup_finish_date) , GETDATE()) > 4 THEN ‘SI’
WHEN MAX(B.backup_finish_date) IS NULL THEN ‘SI’ ELSE »
END AS SinBackupUltimas24hs
FROM sys.sysdatabases S LEFT OUTER JOIN msdb.dbo.backupset B ON B.database_name = S.name
WHERE B.type LIKE ‘L’ AND S.name NOT LIKE ‘tempdb’
GROUP BY S.Name ORDER BY S.Name
/*******************************************************************************
Detalle por Backups de los últimos 7 días
******************************************************************************/
SELECT database_name as DB, name AS Backup_Name, backup_finish_date AS LastBackup,
CASE [type] WHEN ‘D’ THEN ‘Full’
WHEN ‘L’ THEN ‘Log’
WHEN ‘I’ THEN ‘Differential’ ELSE ‘Other’
END AS Tipo_Backup
FROM msdb.dbo.backupset B
WHERE backup_finish_date > DATEADD(dd,-7,GETDATE())
ORDER BY database_name, backup_finish_date desc
Dejar un comentario
¿Quieres unirte a la conversación?Siéntete libre de contribuir!