Skip to main content

Export & Backup

warning

Backups must be tested. A backup you cannot restore is not a backup.

Prerequisites

ArtifactWhat it capturesExample path
Database exportcontent, options, settings/tmp/wp-backup.sql
Theme mods snapshotCustomizer settings/tmp/theme_mods_generatepress.json
Elements inventoryElement list for audits/tmp/gp-elements.csv
Child themeCustom code and CSSwp-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

PracticeWhy
Store backups outside docrootPrevents accidental exposure
Keep a restore runbookFaster recovery
Version your child themeEnables code rollback
Test restores regularlyProves backup quality
Keep backups encrypted at restProtects customer data
Keep an offsite copyProtects against server loss

Troubleshooting

SymptomCauseFix
wp db export failsDB permissionsVerify DB creds and WP-CLI environment
Restore works but site looks wrongCachePurge LSCache and flush caches
Exports missing expected changesWrong site rootConfirm wp core path
Backups too largeUploads bloatPrune unused media and keep image budgets

Hands-On

  1. Export DB and theme mods on staging.
  2. Make a visible change (e.g., site title), then restore.
  3. Confirm the change is rolled back.
  4. Backup the child theme to /tmp/generatepress-child.tgz and verify you can extract it.
  5. 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