• Stars
    star
    461
  • Rank 95,028 (Top 2 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

βœ” SQL Server Environmental Validation

dbachecks

.github/workflows/deploy-module.yml
GitHub release badge GitHub pre-release badge
PowerShell Gallery
GitHub license badge GitHub releases badge
Ubuntu LinuxLinux Tests
macOSMacOs Tests
Windows badgeWindows pwsh Tests
Windows badgeWindows PowerShell 5.1 Tests

Please note - development on v2 has stopped and all efforts are focused on the v3 improvements to use Pester v5 and improve performance.

You are welcome to help by picking something from the project https://github.com/orgs/dataplat/projects/2 or by contacting @SQLDBAWithABeard @jpomfret @ClaudioESSilva or @shaneis

dbachecks is a framework created by and for SQL Server pros who need to validate their environments. Basically, we all share similar checklists and mostly just the server names and RPO/RTO/etc change.

This open source module allows us to crowd-source our checklists using Pester tests. Such checks include:

  • Backups are being performed
  • Identity columns are not about to max out
  • Servers have access to backup paths
  • Database integrity checks are being performed and corruption does not exist
  • Disk space is not about to run out
  • All enabled jobs have succeeded

Interactive dbachecks PowerShell Notebooks for Azure Data Studio

You can find a set of interactive PowerShell Notebooks which will introduce you to all of the core concepts in Robs GitHub. There is a set of .NET interactive Jupyter Notebooks

https://github.com/SQLDBAWithABeard/JupyterNotebooks/tree/master/notebooks/dotNETNotebooks/dbachecks

and a set of Jupyter Notebooks that will run in Azure Data Studio

https://github.com/SQLDBAWithABeard/JupyterNotebooks/tree/master/notebooks/NotDotNet/dbachecks

Both will use a docker container to show you how dbachecks works.

There is a zip file containing the Notebooks here

https://github.com/SQLDBAWithABeard/Presentations/raw/master/Notebooks/dbachecks/Notebooks.zip

Have questions about development? Please visit our Wiki. Anyone developing this module should visit that Wiki page (after fully reading this readme) for a brief overview.

Build Status

Development Branch Build - Unit testing Click Here
Master Branch Build - Module version update and Code Signing Click Here
Master Branch Release - Release to PowerShell Gallery Click Here

Want to know how our CD process works? Read this blog post and see how the team manage it

Prerequisites

Client requirements

  • PowerShell 5 + is required.
  • Automatic installation of the dependent modules will only be provided via the PowerShell Gallery.

When you install from the Gallery, it'll auto-install:

  • dbatools
  • PSFramework

You will also need to manually install the Pester module at version 4.10.0, this is due to inconsistencies between dbachecks and Pester v5. If you have Pester v5 installed it is recommended to remove this and use Pester 4.10.0 or force an import of 4.10.0 when running dbachecks

Install-Module Pester -SkipPublisherCheck -Force -RequiredVersion 4.10.0
Import-Module Pester -Force -RequiredVersion 4.10.0

When you import, it'll auto-import

  • dbatools
  • Pester
  • PSFramework

If you have already installed the module and you update it, you may be required to update the Pester or the PSFramework modules before it will import. If you see a message like

error

Then you need to

Install-Module Pester -SkipPublisherCheck -Force -RequiredVersion 4.10.0
Import-Module Pester -Force -RequiredVersion 4.10.0

You may need to do the same thing for the PSFramework or dbatools modules also

SQL requirements

dbachecks uses dbatools for most of it's data gathering so it supports SQL Versions from SQL 2000 to SQL vNext including SQL running on Linux. (dbachecks will not install on PowerShell Core yet so can not be run on a Linux client) Obviously some of the Services and disk space checks will not work against instances running on Linux as they are using gWindows API calls.

Getting started

Checks are performed using Invoke-DbcCheck which is basically a wrapper for Invoke-Pester. This means that supported Invoke-Pester parameters work against Invoke-DbcCheck.

In this module, a "Check" is synonymous with a "Tag" in Pester. So you can Invoke-DbcCheck and specify a Check that you want to run. You can see a list of the available Checks with Get-DbcCheck.

image

Once you've decided on the Check(s) you want to run, it's time to ensure you have a list of servers to run the checks against.

Making server lists

Similar to the dbatools module, dbachecks accepts -SqlInstance and -ComputerName parameters.

Invoke-DbcCheck -SqlInstance $servers -Checks SuspectPage, LastBackup

If you have a simplified (single) environment, however, you can set a permanent list of servers. "Servers" include both SQL Server instances and Windows servers. Checks that access Windows Server (e.g. disk space checks) will utilize -ComputerName parameter. A pure SQL Server command(s) (such as the backup check) utilizes the -SqlInstance parameter.

# Set the servers you'll be working with
Set-DbcConfig -Name app.sqlinstance -Value sql2016, sql2017, sql2008, sql2008\express
Set-DbcConfig -Name app.computername -Value sql2016, sql2017, sql2008

# Look at the current configs
Get-DbcConfig

# Invoke a few tests
Invoke-DbcCheck -Checks SuspectPage, LastBackup

What it looks like

image

Other ways to execute checks against specific servers

Additional Invoke-DbcCheck examples:

Invoke-DbcCheck -Check Backup -SqlInstance sql2016
Invoke-DbcCheck -Check RecoveryModel -SqlInstance sql2017, sqlcluster

$sqlinstance = Get-DbaRegisteredServer -SqlInstance sql2017 -Group Express
Invoke-DbcCheck -Check Backup -SqlInstance $sqlinstance

Invoke-DbcCheck -Check Storage -ComputerName server1, server2

Check and ExcludeCheck

We tag each of our Checks using singular descriptions such as Backup, Database or Storage. You can see all the Pester related Tags using Get-DbcTagCollection or Get-DbcCheck.

Each Check generally has a few Tags but at least one Tag is unique. This allows us to essentially name a Check and using these Tags, you can either include (-Check) or Exclude (-ExcludeCheck) in your results. The Exclude will always take precedence.

For example, the Database Tag runs a number of Checks including Backup Checks. The command below will run all Database Checks except for the Backup Checks.

Invoke-DbcCheck -Check Database -ExcludeCheck Backup -SqlInstance sql2016 -SqlCredential (Get-Credential sqladmin)

All valid Pester syntax is valid for dbachecks so if you'd like to know more, you can review their documentation.

Reporting on the data

Since this is just PowerShell and Pester, results can be exported then easily converted to pretty reports. We've provided two options: Power BI and SMTP mail.

Power BI Visualizations!

We've also included a pre-built Power BI Desktop report! You can download Power BI Desktop from here or it is now offered via the Microsoft Store on Windows 10.

Note: We strongly recommend that you keep your PowerBI Desktop updated since we can add brand-new stuff that appears on the most recent releases.

To use the Power BI report, pipe the results of Invoke-DbcCheck to Update-DbcPowerBiDataSource (defaults to C:\Windows\temp\dbachecks), then launch the included dbachecks.pbix file using Start-DbcPowerBi. Once the Power BI report is open, just hit refresh.

# Run checks and export its JSON
Invoke-DbcCheck -SqlInstance sql2017 -Checks SuspectPage, LastBackup -Show Summary -PassThru | Update-DbcPowerBiDataSource

# Launch Power BI then hit refresh
Start-DbcPowerBi

image

The above report uses Update-DbcPowerBiDataSource's -Environment parameter.

# Run checks and export its JSON
Invoke-DbcCheck -SqlInstance $prod -Checks LastBackup -Show Summary -PassThru |
Update-DbcPowerBiDataSource -Environment Prod

😍😍😍

Sending mail

We even included a command to make emailing the results easier!

$outputDirectory = (Get-DbcConfigValue -Name app.maildirectory)
$filename = $outputDirectory + '\file.xml'
Invoke-Dbccheck -OutputFile $fileName -OutputFormat NunitXML

$outputpath = $outputDirectory + "\index.html"
$reportunit = "ModulePath\bin\ReportUnit.exe"
& $reportunit $outputDirectory

$htmlbody = Get-Content -Path $outputpath -ErrorAction SilentlyContinue | Out-String

Send-MailMessage -To clemaire@dbatools.io -From nobody@dbachecks.io -SMTP smtp.ad.local -BodyAsHtml $htmlbody

image

If you'd like to test locally, check out PaperCut which is just a quick email viewer that happens to have a built-in SMTP server. It provides awesome, built-in functionality so you can send the reports!

Advanced usage

Skipping some internal tests

The Check LastGoodCheckDb includes a test for data purity. You may be in an environment that can't support data purity. If this check needs to be skipped, you can do the following:

Get-DbcConfig *skip*
Set-DbcConfig -Name skip.dbcc.datapuritycheck -Value $true

Need to skip a whole test? Just use the -ExcludeCheck which is auto-populated with both Check names and Pester Tags.

Setting a global SQL Credential

Set-DbcConfig persists the values. If you Set-DbcConfig -Name app.sqlcredential -Value (Get-Credential sa) it will set the SqlCredential for the whole module, but not your local console! So cool.

You can also manually change the SqlCredential or Credential by specifying it in Invoke-DbaCheck:

Invoke-DbaCheck -SqlInstance sql2017 -SqlCredential (Get-Credential sqladmin) -Check MaxMemory

Manipulating the underlying commands

You can also modify the parameters of the actual command that's being executed:

Set-Variable -Name PSDefaultParameterValues -Value @{ 'Get-DbaDiskSpace:ExcludeDrive' = 'C:\' } -Scope Global
Invoke-DbcCheck -Check Storage

Can I run tests not included the module?

If you have super specialized checks to run, you can add a new repository, update the app.checkrepos config and this will make all of your tests available to Invoke-DbcCheck. From here, you can pipe to Send-DbcMailMessage, Update-DbcPowerBiDataSource or parse however you would parse Pester results.

image

So first, add your repository

Set-DbcConfig -Name app.checkrepos -Value C:\temp\checks -Append

Then add additional checks. We recommend using the development guidelines for dbachecks.

image

I'd like to run my checks in SQL Server Agent

Great idea! Remember that this module requires PowerShell version 4.0, which doesn't always mesh with SQL Server's PowerShell Job Step. To run dbachecks, we recommend you use CmdExec. You can read more at dbatools.io/agent.

If you do choose to use the PowerShell step, don't forget to Set-Location somewhere outside of SQLSERVER:, otherwise, you'll get errors similar to this

image

I don't have access to the PowerShell Gallery, how can I download this?

This module has a number of dependencies which makes creating a GitHub-centric installer a bit of a pain. We suggest you use a machine with PowerShellGet installed and Save all the modules you need:

Save-Module -Name dbachecks, dbatools, PSFramework, Pester -Path C:\temp

Then move them to somewhere in your $env:PSModulePath, perhaps Documents\WindowsPowerShell\Modules or C:\Program Files\WindowsPowerShell\Modules.

Read more

Read more about dbachecks from a number of our original contributors!

Know of any more blog posts about dbachecks? - Please add them here.

Party

Nice work!

How to Contribute

We welcome contributions to the project. You can fork the repository, make changes and create a Pull Request. Rob has written a guide here

More Repositories

1

dbatools

πŸš€ SQL Server automation and instance migrations have never been safer, faster or freer
PowerShell
2,441
star
2

dbops

βš™ dbops - Powershell module that provides continuous database deployments on any scale
PowerShell
155
star
3

DataSaturdays

A repository for open sourcing a solution for Data Saturdays
HTML
142
star
4

dbaclone

πŸ‘― Clone SQL Server databases using PowerShell previously named PSDatabaseClone
PowerShell
133
star
5

dbareports

PowerShell Module to gather, store and report on data about your estate. **This repository has been archived due to no longer being maintained.**
PowerShell
110
star
6

Invoke-SqlCmd2

PowerShell module containing Invoke-SqlCmd2
PowerShell
68
star
7

community-presentations

Presentation Repository for SQL Server / PowerShell Presentations within the Community
Jupyter Notebook
41
star
8

dbatools-templates

Templates for dbatools commands
PowerShell
30
star
9

dbatools-lab

Build a lab environment for testing out dbatools
Jupyter Notebook
22
star
10

mastodon

Where to find Data Platform, PowerShell and Power BI Twitter friends on Mastodon
20
star
11

docker

The code that's used to create the dbatools SQL Server images on Docker Hub.
TSQL
18
star
12

dbadisa

πŸ¦… DISA STIG automation module for SQL Server
PowerShell
16
star
13

docs

The documentation for dbatools module. Issues with command doc and bugs should be reported to dataplat/dbatools.
HTML
15
star
14

ADSNotebook

PowerShell Module for interacting with Azure Data Studio Notebooks
PowerShell
14
star
15

AlwaysEncryptedSample

Sample ASP.NET MVC Application for demonstrating Microsoft SQL Server Always Encrypted Functionality
C#
14
star
16

dbarefresh

πŸ”„ Database refresh module to copy partial data from production to another database
PowerShell
12
star
17

dataplat.github.io

Resources for the SQL Collaborative
HTML
11
star
18

AzureDataPipelineTools

A collection of Azure Function to make building Azure Data Factory pipeline simpler and easier.
C#
10
star
19

dbasecurityscan

Baseline, check and correct your SQL Database Security
PowerShell
10
star
20

dbatools.library

dbatools smo library builder
C#
7
star
21

dbatools-traininglab

a nice lil tutorial to help with useful tutorials
4
star
22

ssis-reporting-pack

3
star
23

dbatools-lab-dotnet-extension

This repo will hold the code to make the Azure Data Studio Extension for the dbatools dotnet interactive Notebooks which enables you to run dbatools against a couple of containers on your machine
Jupyter Notebook
3
star
24

disa-docs

Crowd-sourced Template for SQL Server Documentation as required by DISA
3
star
25

DataSpeakers

A simple repository which can serve as a resource for event owners to find speakers. The data is displayed on https://callfordataspeakers.com/precon and controlled with GitHub Issues and GitHub Actions
Shell
3
star
26

appveyor-lab

repo for full-on appveyor tests
TSQL
2
star
27

AlwaysEncryptedSample.Docs

2
star
28

sqlpsweb

basically a redirector
HTML
2
star
29

dbatools-libary

Source code to the dbatools.dll library utilized by dbatools PowerShell module
C#
2
star
30

dbachecksweb

redirector site for dbachecks.io
HTML
1
star
31

yourrole

Shell
1
star
32

web

dbatools.io website
HTML
1
star