Skip to content

Commit e6b4602

Browse files
Get-DbaDbRestoreHistory - Add BackupStartDate, StopAt, and LastRestorePoint columns
Adds three new properties to the output of Get-DbaDbRestoreHistory: - BackupStartDate: the start time of the backup being restored - StopAt: the point-in-time stop value used during the restore (if any) - LastRestorePoint: computed column showing the effective restore point (StopAt when specified and earlier than BackupStartDate, otherwise BackupStartDate) Also adds backup_start_date to the Select-DefaultView exclude list for consistency with how backup_finish_date is handled (raw column hidden, aliased column shown). Closes #7854 (do Get-DbaDbRestoreHistory) Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
1 parent aa4e253 commit e6b4602

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

public/Get-DbaDbRestoreHistory.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ function Get-DbaDbRestoreHistory {
7878
- From: Comma-separated list of physical device names where the backup source(s) are located
7979
- To: Comma-separated list of physical file paths where the database files were restored
8080
81-
Additional properties available (from MSDB backupset table):
81+
Additional properties available (from MSDB backupset/restorehistory tables):
8282
- first_lsn: First log sequence number in the backup
8383
- last_lsn: Last log sequence number in the backup
8484
- checkpoint_lsn: Checkpoint log sequence number
8585
- database_backup_lsn: Log sequence number of database backup
86+
- BackupStartDate: Timestamp when the backup operation started
8687
- BackupFinishDate: Timestamp when the backup operation completed
88+
- StopAt: The point-in-time stop value specified during the restore operation (NULL if not specified)
89+
- LastRestorePoint: The effective point in time the database was restored to (StopAt if specified and earlier than BackupStartDate, otherwise BackupStartDate)
8790
8891
All properties from the underlying DataRow object are accessible using Select-Object *.
8992
@@ -180,8 +183,15 @@ function Get-DbaDbRestoreHistory {
180183
bs.last_lsn,
181184
bs.checkpoint_lsn,
182185
bs.database_backup_lsn,
186+
bs.backup_start_date,
187+
bs.backup_start_date AS BackupStartDate,
183188
bs.backup_finish_date,
184-
bs.backup_finish_date AS BackupFinishDate
189+
bs.backup_finish_date AS BackupFinishDate,
190+
rsh.stop_at AS StopAt,
191+
CASE
192+
WHEN COALESCE(rsh.stop_at, '9999-12-31') < bs.backup_start_date THEN rsh.stop_at
193+
ELSE bs.backup_start_date
194+
END AS LastRestorePoint
185195
"
186196
}
187197

@@ -247,7 +257,7 @@ function Get-DbaDbRestoreHistory {
247257
}
248258
$results = $tmpres
249259
}
250-
$results | Select-DefaultView -ExcludeProperty first_lsn, last_lsn, checkpoint_lsn, database_backup_lsn, backup_finish_date
260+
$results | Select-DefaultView -ExcludeProperty first_lsn, last_lsn, checkpoint_lsn, database_backup_lsn, backup_start_date, backup_finish_date
251261
} catch {
252262
Stop-Function -Message "Failure" -Target $SqlInstance -Error $_ -Exception $_.Exception.InnerException -Continue
253263
}

0 commit comments

Comments
 (0)