Export & Backup
warning
Backups must be tested. A backup you cannot restore is not a backup.
Prerequisites
| Artifact | What it captures | Example path |
|---|---|---|
| Database export | content, options, settings | /tmp/wp-backup.sql |
| Theme mods snapshot | Customizer settings | /tmp/theme_mods_generatepress.json |
| Elements inventory | Element list for audits | /tmp/gp-elements.csv |
| Child theme | Custom code and CSS | wp-content/themes/generatepress-child/ |
Safety Notes
- Imports and redesigns are large changes.
- Rollback needs artifacts (DB + settings) and a tested process.
- Exports support migration between environments.
How It Works
Most site state lives in:
- the database
wp-content/(themes, plugins, uploads)
You export both categories depending on the change.
Step-by-Step Export and Backup
Step 1: Export Database
export-db.sh
cd /var/www/html
wp db export /tmp/wp-backup.sql
ls -lh /tmp/wp-backup.sql
Step 2: Export Theme Mods
export-theme-mods.sh
cd /var/www/html
wp option get theme_mods_generatepress --format=json > /tmp/theme_mods_generatepress.json
wc -l /tmp/theme_mods_generatepress.json
Step 3: Export Elements Inventory (Optional)
export-elements-inventory.sh
cd /var/www/html
wp post list --post_type=gp_elements --fields=ID,post_title,post_status --format=csv 2>/dev/null > /tmp/gp-elements.csv || true
wc -l /tmp/gp-elements.csv 2>/dev/null || true
Step 4: Backup the Child Theme Files
backup-child-theme-files.sh
cd /var/www/html
tar -czf /tmp/generatepress-child.tgz -C wp-content/themes generatepress-child
ls -lh /tmp/generatepress-child.tgz
Step 5: Validate Restore (Staging Drill)
restore-db-drill.sh
cd /var/www/html
# Only do this on staging
wp db import /tmp/wp-backup.sql
wp cache flush 2>/dev/null || true
caution
Do not run wp db import on production unless you are executing a planned rollback.
Optional Configuration
Example 1: Backup Before a Site Library Import
- DB export
- theme mods snapshot
- plugin list
Example 2: Backup Before a Redesign
- DB export
- child theme repo tag
- element inventory export
Example 3: Keep an Export Inventory File
write-export-inventory.sh
cd /tmp
ls -lh wp-backup.sql theme_mods_generatepress.json gp-elements.csv generatepress-child.tgz 2>/dev/null || true
Best Practices
| Practice | Why |
|---|---|
| Store backups outside docroot | Prevents accidental exposure |
| Keep a restore runbook | Faster recovery |
| Version your child theme | Enables code rollback |
| Test restores regularly | Proves backup quality |
| Keep backups encrypted at rest | Protects customer data |
| Keep an offsite copy | Protects against server loss |
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
wp db export fails | DB permissions | Verify DB creds and WP-CLI environment |
| Restore works but site looks wrong | Cache | Purge LSCache and flush caches |
| Exports missing expected changes | Wrong site root | Confirm wp core path |
| Backups too large | Uploads bloat | Prune unused media and keep image budgets |
Hands-On
- Export DB and theme mods on staging.
- Make a visible change (e.g., site title), then restore.
- Confirm the change is rolled back.
- Backup the child theme to
/tmp/generatepress-child.tgzand verify you can extract it. - Store backup file paths in a small runbook entry.
Quick Reference
export-backup-cheatsheet.sh
cd /var/www/html
wp db export /tmp/wp-backup.sql
wp option get theme_mods_generatepress --format=json > /tmp/theme_mods_generatepress.json
What's Next
- Next module: Child Theme
- Next lesson: Why Use a Child Theme