how to get the location of the backup too? you can use multiple columns pivoting or any other way!
0
votes
1
answer
80
views
I got this great query that shows the latest backup for each existing database .
SELECT
M.name,
[Recovery Model] =
M.recovery_model_desc,
[State] =
M.state_desc,
[Last Full Backup] =
FORMAT(ISNULL(M.D, '19000101'), 'dd-MM-yyyy hh:mm'),
[Last Differential Backup] =
FORMAT(ISNULL(M.I, '19000101'), 'dd-MM-yyyy hh:mm'),
[Last log Backup] =
FORMAT(ISNULL(M.L, '19000101'), 'dd-MM-yyyy hh:mm')
FROM
(
SELECT
db.name,
db.state_desc,
db.recovery_model_desc,
a.type,
a.backup_finish_date
FROM master.sys.databases AS db
LEFT OUTER JOIN msdb.dbo.backupset AS a
ON a.database_name = db.name
) AS Sourcetable
PIVOT
(
MAX(backup_finish_date)
FOR type IN
(
D,
I,
L
)
) AS M --ostRecentBackup
WHERE name NOT IN
(
N'master',
N'msdb',
N'model',
N'tempdb'
);
I noticed it uses pivoting - what if I had to add the location too? that would be multiple columns .
Either by pivoting using multiple columns , or unpivoting , how could I add the location of each backup type to the above query?
basically where is the latest full backup, where is the latest diff and the latest log (if any).
this is the script I use to see the location of the backup:
SELECT
CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server,
msdb.dbo.backupset.database_name,
msdb.dbo.backupset.TYPE,
msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date,
msdb.dbo.backupset.expiration_date,
msdb.dbo.backupset.backup_size,
msdb.dbo.backupset.backup_size * 1.024 /1024/1024 as [Backup size in MB],
msdb.dbo.backupmediafamily.logical_device_name,
msdb.dbo.backupmediafamily.physical_device_name,
msdb.dbo.backupset.name AS backupset_name,
msdb.dbo.backupset.description
FROM msdb.dbo.backupmediafamily
INNER JOIN msdb.dbo.backupset
ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
--WHERE msdb.dbo.backupset.database_name = 'PivCRM_Prod_Online_ED'
--AND TYPE = 'D' -- L D and I
ORDER BY msdb.dbo.backupset.backup_start_date DESC
the question is:
how would I add the location of the backup (each type) to the first query?
Asked by Marcello Miorelli
(17274 rep)
Nov 5, 2024, 01:24 PM
Last activity: Nov 5, 2024, 09:14 PM
Last activity: Nov 5, 2024, 09:14 PM