A simple Bash script to export all incidents from PagerDuty month by month basis.
It:
- Queries the PagerDuty Incidents API v2
- Handles pagination (for large result sets)
- Outputs one JSON file per month like
pagerduty-incident-export-12-2021.json,pagerduty-incident-export-01-2022.json, etc. - Compatible with macOS (uses BSD
datesyntax)
- Bash shell (default on macOS/Linux)
- jq installed (
brew install jqon macOS) - A valid PagerDuty API token with read access to incidents
Open the script and update:
API_TOKEN="TOKEN_GOES_HERE"Replace with your actual PagerDuty API token.
chmod +x export-incidents.sh
./export-incidents.shThis will generate .json files in the same directory, one for each month in the range.
Each file will look like this:
[
{
"id": "PABC123",
"title": "Database latency alert",
"status": "resolved",
"urgency": "high",
"created_at": "2022-03-15T03:42:00Z",
"service": "Primary Database"
},
...
]You can customize the fields extracted by modifying the
jqcommand in the script.
Error: date: illegal option -- d
→ You're probably using macOS — this script is already compatible using date -v. Just make sure you're running it with the macOS-native shell (not inside Docker or a Linux container).