microsoft / sqlmanagementobjects

Sql Management Objects, an API for scripting and managing SQL Server and Azure SQL Database
Other
130 stars 21 forks source link

Backup Path in SMO? #121

Open potatoqualitee opened 1 year ago

potatoqualitee commented 1 year ago

Did we miss any sort of property or method that would show the Path in the Backup History? We ended up using a bunch of T-SQL in Get-DbaBackupHistory as seen in the Path (mediafamily.physical_device_name) property seen below.

ComputerName          : sqlcs
InstanceName          : MSSQLSERVER
SqlInstance           : sqlcs
AvailabilityGroupName :
Database              : model
DatabaseId            : 3
UserName              : sqladmin
Start                 : 01/19/2022 1:15:33 PM
End                   : 01/19/2022 1:15:33 PM
Duration              : 00:00:00
Path                  : {C:\temp\model-Full-202201192215.bak}
TotalSize             : 2.83 MB
CompressedBackupSize  : 475.72 KB
CompressionRatio      : 6.09
Type                  : Full
BackupSetId           : 1
DeviceType            : Disk
Software              : Microsoft SQL Server
FullName              : {C:\temp\model-Full-202201192215.bak}
FileList              : {@{FileType=D; LogicalName=modeldev;
                        PhysicalName=C:\MSSQL\MSSQL15.MSSQLSERVER\MSSQL\DATA\model.mdf}, @{FileType=L;
                        LogicalName=modellog;
                        PhysicalName=C:\MSSQL\MSSQL15.MSSQLSERVER\MSSQL\DATA\modellog.ldf}}
Position              : 1
FirstLsn              : 36000000136600001
DatabaseBackupLsn     : 0
CheckpointLsn         : 36000000136600001
LastLsn               : 36000000136900001
SoftwareVersionMajor  : 15
IsCopyOnly            : False
LastRecoveryForkGUID  : 90d16058-f1d1-4e96-8ec6-8d7bfda42f15
RecoveryModel         : FULL
KeyAlgorithm          :
EncryptorThumbprint   :
EncryptorType         :
shueybubbles commented 1 year ago

BackupMedia.MediaName uses physical_device_name https://github.com/microsoft/sqlmanagementobjects/blob/d6f3e68fe6fae09d22355a160baa525d8032fd64/src/Microsoft/SqlServer/Management/Smo/BackupMedia.cs#L53C26-L53C26

I think these types are only accessible from a BackupRestorePlanner instance in Smo.Extended but I'm not 100% certain how these classes work.