TIL: Get-DbaLastBackup

(This post comes from one of our Junior DBAs – @SQLDork)

I’ve been learning dbatools over the past week or so, you can read the previous blog posts here and here.

You can read the current one here, or just scroll down i guess.

Today’s Command: Get-DbaLastBackup

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016

Nothing fancy, just spits out the last backup info for each database on the box.

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 | `
    Select-Object *

This gives us some more useful information, telling us the number of days since the database was created/backed up, the backup type, etc.

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 `
    -Database test

Specify which database you want to check, defaults to all of them.

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 `
    -ExcludeDatabase test

Specify that you don’t want to check a certain database. Again, not using this or -Database will return data on all of them.

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 | `
    Select-Object * | `
    Out-Gridview

Formatting, puts the data in a grid. Useful for pasting into excel or something. Though there’s no way to copy the headers as far as i can tell, so you’ll have to put those in manually.

(Click image to enlarge in new tab)
Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 | `
    Select-Object Database,RecoveryModel | `
    Out-Gridview

Only select some columns, rather than all of them.

Get-DbaLastBackup `
    -SqlInstance PRECISION-M7520\SQL2016 | `
    Select-Object * | `
    Export-Csv `
    -Path C:\output.csv `
    -NoTypeInformation

How about we pipe the output to excel/CSV directly instead of pasting it in? Sounds like a good idea to me!

(Click image to enlarge in new tab)

 

That’s all i (b|t) have for today, but it wouldn’t be a SQLDork blog post without several links to my twitter at the end!

(follow my twitter)

Leave a Comment

Sign up for our Newsletter

%d bloggers like this: