Load Database
Instructions
When this skill is invoked — either via /load-db or through a natural language request like "clone the live database from december 12" — download a database backup from Pantheon and load it into the local development environment.
Usage
/load-db # Interactive: choose environment and backup
/load-db live # Use latest backup from live environment
/load-db dev 2026-02-10 # Use backup from dev matching the given date
"clone the live database" # Natural language: infer environment=live, pick latest
"load the db from test dec 12" # Natural language: infer environment=test, date=dec 12
"pull down the production database"# Natural language: default to live, pick latest
Interpreting Natural Language
When invoked through conversation rather than a slash command:
- Look for an environment name in the request (live, dev, test, qa, training, or any multidev name). If none mentioned, proceed to environment selection interactively.
- Look for a date reference in the request (e.g., "december 12", "feb 3", "yesterday", "last tuesday"). Convert it to a date string like
2026-02-10for matching. - If the user says "latest" or "most recent", skip backup selection and use the newest available.
- If the user says "production", treat it as the
liveenvironment.
Steps
Parse Arguments and Context:
- From slash command: first argument is environment, second is date
- From natural language: extract environment and date from the user's message as described above
- If both environment and date/latest are known, skip interactive selection steps
Select Environment:
- If an environment was already determined, use it directly — skip interactive selection
- Otherwise, list available environments using terminus:
terminus env:list ${TERMINUS_SITE} --format=list --fields=id - Use the AskUserQuestion tool to let the user pick an environment from the list
- Present the most commonly used environments first:
live,test,dev,qa, then others - Include up to 3 options in the question, plus the user can type "Other" to specify a different environment
- Recommend
liveas the default choice since it has production data
Download Backup:
- Latest backup (no date specified): Skip the
backup:liststep entirely. Useterminus backup:getwithout--fileto get the latest database backup URL directly, then download it in one command:
This avoids fetching and parsing the full backup list JSON, which is large and wastes context tokens.curl -L "$(terminus backup:get ${TERMINUS_SITE}.{environment} --element=db)" --output /tmp/pantheon-db-backup.sql.gz - Specific date requested: Only in this case, list backups to find the matching one:
Filter to entries whose filename contains the target date string (e.g.,terminus backup:list ${TERMINUS_SITE}.{environment} --element=db --format=json2026-02-10), then download:curl -L "$(terminus backup:get ${TERMINUS_SITE}.{environment} --element=db --file={backup_filename})" --output /tmp/pantheon-db-backup.sql.gz - Interactive (no environment or date): List backups using the same
--element=dbfiltered command above and use AskUserQuestion to let the user pick:- Present backups sorted by date (newest first)
- Show the filename and size for each option
- Recommend the most recent backup
- Include up to 3 most recent backups as options, with "Other" available for older backups
- If no database backups exist for the environment, inform the user and stop
- If the download fails, inform the user and stop
- Verify the downloaded file exists and has a non-zero size
- Latest backup (no date specified): Skip the
Import Database:
- IMPORTANT: The
db-rebuild.shscript prepends$(pwd)/to positional file arguments (see line 80 of the script). You MUST either:cd /tmpbefore invoking the script and pass the relative filename, OR- Pass the file using the
--separator to avoid the path prepending
- Run the import:
cd /tmp && /usr/local/bin/db-rebuild.sh pantheon-db-backup.sql.gz - This script will:
- Drop and recreate the local database
- Detect compression format and decompress
- Import the SQL into the local database
- Run
drush deployto apply config and migrations
- Stream the output to the user so they can see progress
- This command takes a long time to run — use a generous timeout (at least 10 minutes)
- IMPORTANT: The
Clean Up:
- Remove the downloaded backup file:
rm -f /tmp/pantheon-db-backup.sql.gz - Inform the user that the database has been loaded successfully
- Report which environment and backup were used
- Remove the downloaded backup file:
Error Handling
- If
TERMINUS_SITEis not set, inform the user they need to set it (should bemyeap2for this project) - If terminus authentication fails, suggest running
terminus auth:login - If no backups are found for the selected environment, inform the user and suggest trying a different environment or creating a backup first with
terminus backup:create - If the download or import fails, preserve error output and present it to the user