Here is a detailed prompt for creating a database administrator (DBA) automation tool. This prompt can be used with GitHub Copilot, ChatGPT, or Gemini.
The "Master" Prompt:
"As a SQL Server DBA, I aim to automate backup reporting for Always On Availability Groups (AG). Please create a Python or PowerShell script that performs the following tasks:
- Server Connection: Connect to the SQL environment using Windows Authentication. Automatically identify primary and secondary replicas using the AG Listener.
- Data Extraction: Query the
msdb..backupsetandmsdb..backupmediafamilytables across all nodes to find the last successful backup (Full, Differential, and Log) for every database. - Intelligence Logic: Flag any database without a Full Backup in more than 7 days as 'MISSING' or 'CRITICAL'.
- Dashboard Generation: Generate a color-coded HTML report (Dashboard) with columns for Database Name, Last Backup Date/Time, Backup Type, File Location, and Status (SUCCESS/FAILED/MISSING).
- Email Automation: Include a function to send the formatted HTML report as an email summary to the DBA team.
Ensure the code includes error handling, secure connection strings, and comments explaining each step."
Pro Tips for a Better Result:
- Specify the SQL Server version (e.g., "for SQL Server 2022") to ensure accurate T-SQL syntax.
- Include server naming conventions or preferred libraries (like
pyodbcfor Python orSqlServermodule for PowerShell) in the prompt. - Iterate: After the AI generates the first draft, request additional features like handling offline servers or formatting the HTML table with CSS.