How to Back Up and Restore WordPress Completely

WordPress backups need to cover two distinct pieces: the database (posts, settings, users) and the files (themes, plugins, uploaded media). Missing either results in an incomplete restore. This guide covers both.

What Needs to Be Backed Up

  • Database — all post content, pages, comments, settings, and user accounts
  • wp-content/uploads — all media library files
  • wp-content/themes — active and installed themes, including any custom modifications
  • wp-content/plugins — installed plugins
  • wp-config.php — site configuration, including database credentials (handle securely)

Backing Up the Database

mysqldump -u root -p wordpress_db | gzip > wp-db-backup.sql.gz

See How to Back Up and Restore MySQL/MariaDB Databases for full detail.

Backing Up Files

tar czf wp-files-backup.tar.gz /var/www/wordpress/wp-content

Including wp-config.php separately, handled with care given its sensitive database credentials:

cp /var/www/wordpress/wp-config.php /var/backups/wp-config-backup.php

Automating a Complete WordPress Backup

sudo nano /usr/local/bin/backup-wordpress.sh
#!/bin/bash
TIMESTAMP=$(date +%F)
BACKUP_DIR="/var/backups/wordpress"
WP_PATH="/var/www/wordpress"

mkdir -p "$BACKUP_DIR"

mysqldump -u root -p"YOUR_DB_PASSWORD" wordpress_db | gzip > "$BACKUP_DIR/db-$TIMESTAMP.sql.gz"
tar czf "$BACKUP_DIR/files-$TIMESTAMP.tar.gz" -C "$WP_PATH" wp-content

find "$BACKUP_DIR" -type f -mtime +14 -delete
sudo chmod +x /usr/local/bin/backup-wordpress.sh

Scheduling

sudo crontab -e
0 3 * * * /usr/local/bin/backup-wordpress.sh >> /var/log/wp-backup.log 2>&1

Backing Up Docker-Based WordPress

If running WordPress via Docker Compose (see Deploy WordPress with Docker Compose), back up the named volumes instead:

docker exec wordpress-db mysqldump -u root -pYOUR_PASSWORD wordpress > wp-db-backup.sql
docker run --rm -v wordpress_wp_data:/data -v $(pwd):/backup alpine tar czf /backup/wp-files-backup.tar.gz /data

Restoring WordPress

Step 1 — Restore the Database

gunzip -c db-2026-08-01.sql.gz | mysql -u root -p wordpress_db

Step 2 — Restore the Files

tar xzf files-2026-08-01.tar.gz -C /var/www/wordpress/

Step 3 — Restore wp-config.php

cp wp-config-backup.php /var/www/wordpress/wp-config.php

Step 4 — Fix File Permissions

sudo chown -R www-data:www-data /var/www/wordpress

Step 5 — Verify the Site

Visit the site and confirm content, media, and plugins all display correctly.

Handling Domain Changes During Restore

If restoring to a different domain (e.g. staging), WordPress stores the site URL in the database, requiring a search-and-replace across serialized data — use a dedicated WordPress-aware search-replace tool rather than a naive text find-replace, since naive replacement can corrupt PHP-serialized data.

Common Errors

"Error establishing a database connection" after restore — verify wp-config.php's database credentials match the restored database's actual name/user/password.

Site loads but images/media are broken — the wp-content/uploads directory wasn't restored, or file permissions are incorrect.

Best Practices

  • Always back up both database and files together — neither alone is a complete backup
  • Test restores periodically in a separate environment
  • Follow the 3-2-1 rule — keep an off-site copy

Related Articles

  • How to Back Up and Restore MySQL/MariaDB Databases
  • Deploy WordPress with Docker Compose
  • Backup Strategy 101: The 3-2-1 Rule Explained
  • wordpress backup, wordpress restore, wp-content backup, wordpress migration
  • 0 משתמשים שמצאו מאמר זה מועיל
?האם התשובה שקיבלתם הייתה מועילה

מאמרים קשורים

Backup Strategy 101: The 3-2-1 Rule Explained

Before diving into specific backup tools, it's worth understanding the industry-standard...

How to Back Up to Object Storage (S3-Compatible)

S3-compatible object storage provides durable, cost-effective off-site backup storage —...

How to Test and Verify Your Backups Actually Work

A backup that has never been restored is not a verified backup — it's an assumption. This...

How to Create a Disaster Recovery Plan for Your VPS

A disaster recovery (DR) plan is a documented, tested procedure for restoring service after a...

How to Use VPS Provider Snapshots Effectively

Most VPS providers offer a snapshot feature — a point-in-time image of your entire server....