I now have this note to test out (The easy way out: Duplicator + Plugin Detective)
How to Backup a WordPress Site & Restore on Local Linux
This guide explains how to:
- Backup an existing WordPress site,
- Restore it later, e.g., for testing or migration.
Prerequisites
Before proceeding, confirm the following are in place:
- SSH/SFTP access to your WordPress host (for production backups).
- A local Linux server (e.g., Ubuntu) where restores will occur.
- Basic command-line proficiency, using tools like
wget, tar, scp for backups, and database updates.
Step 1: Backup the WordPress Site
A full backup encompasses:
- Database (mySQL or MariaDB).
- WordPress files/directories.
We rely on manual scripting (recommended for control) via terminal commands.
1. Generate Database Backup
Begin by securing your current database records:
mysql> USE wordpress;
mysql> SHOW TABLES;
myql> mysqldump -uuser -pdbname > db_backup.sql
Proceed only if the dump was saved successful.
2. Backup File System (Using tar + gzip)
For remote host backups, prevent partial downloads by compressing files. Here’s a script to automate this:
- Generate and install public/private SSH keys (place the private key under
~/.ssh/id_rsa).
- Use the below one-liner from source (target directory) to your local backup location:
<smtcmp_block>
Tar and gzip all files in remote WordPress:
scp -r * root@target-ip:/path/to/backup/
gzip -9 /var/temp/example.com.tar.gz
Replace variables as needed.
Step 2: Restore Backup to Your Local Linux Server
Assume you now possess:
? A database dump (db_backup.sql).
? Archive of WordPress files (site.tar.gz).
Step A: Restore Database
- Create a new MySQL/MariaDB instance.
creato databases;
GRANT PRIVILEGES ON database.*;
myql> mysql -u root -prootpassword mydb < db_backup.sql
Check if data transferred successfully. If so, proceed to step 2 (below).
Step B: Extract and Deploy Site Files
- Uncompress the archive:
- Replace outdated WordPress configurations with this updated one.
Example Configuration for Testing
Adjust the below snippet within your local_wordpress.conf* file.
define('DB_NAME', 'newbackup');
define('DB_USER', 'rootpassword');
define('DB_PASSWORD', 'proper_password');
define('DB_HOST', '127.0.0.1');
define('DB_CHARSET', 'latin1');
$table_prefix = "migrate";
Update the values for DB_NAME, DB_USER, and DB_PASSWORD to match your database setup.
Manually Verify Restore Accuracy
After deploying files, validate data integrity using:
Post-Restore: Finishing Touches
- Ensure your local copy of WordPress is fully operational in its new home.
- If using NGINX with Let’s Encrypt, configure DNS records to point there first, then manually verify SSL functionality.
Next Steps & Best Practices
Automation Tips for Faster Rollbacks
- Use cron jobs for scheduling weekly backups (e.g.,
gzip + rsync approach).
- Leverage Vagrant for disposable test environments (simulate your hosting environment locally).
Security & Hygiene Considerations
- Always Encrypt Backups if stored off-site via passphrases.
- Maintain offline backups in air-gapped storage to prevent data corruption from malware or systemic failures.
Advanced Troubleshooting Guide
| Issue Category |
Symptom Description |
Root Cause Analysis & Resolution |
| MySQL Database Auth Fail |
“Cannot find database.” in local WordPress dashboard. |
Likely: Incorrect DB_NAME, DB_USER or DB_PASSWORD in local_wordpress.conf file. Solution: Open conf file via terminal, correct entries there and save. |
| Post-Restore Permalinks Broken (“404 Pages”) |
All permalink pages return errors post-restore. |
Likely: Outdated .htaccess file or missing rewrite_rules table in database. Resolution: |
- Re-save the settings in WordPress’ Permalinks Settings (save without changes first, then verify).
- Ensure database restore includes postmeta, termmeta tables.
|
|.tar.gz Backup Archive Corruption | “Missing files” post-extraction. | Likely: File was truncated during transfer. Solution:
- Rerun backup without the gzip pass (reduce reliance on network stability).
- Verify original local copy’s integrity against source.