Local to cloud: WordPress Migration Full Chain Solutions, Data Backup, Database Restoration, etc.
I. Background and core challenges
1. Migration scene
Local development environmentlocalhost:8081Other Organiser 666.comThis involves containerization deployment (Docker) and cross-environmental migration of databases.
2. Core issues
- First Page Jumping Unusual: visits
666.comAutojump tolocalhost:8081because the database contains old domain names. - Data consistency risk: Docker container data are not backed up and the migration process may lose configuration or plugin data.
II. Analysis of the root causes of the problem
- Database old domain name
wp_optionsTablesiteurlandhomefield is not updated.- Articles, metadata and sequenced data (e.g., menus, small tools) contain hard-coded old addresses.
- Docker Data Management Missing
- Failure to adopt a data volume or
mysqldumpComplete backup, direct handling containers resulting in an irreversible loss of data.
- Failure to adopt a data volume or
- Server Configuration Interference
- Redirective rules of the old environment (e.g.
.htaccessNot cleared.
- Redirective rules of the old environment (e.g.
III. Full-chain solutions
Phase 1: Docker Data Backup and Migration
1. Backup MySQL Database Method 1: Adoptionmysqldump Export SQL File
# 导出数据库(容器内操作)
docker exec dockerwordpress-db-1 mysqldump -uroot -p123456 --hex-blob --default-character-set=utf8mb4 wordpress > /tmp/backup.sql
# 复制到宿主机
docker cp dockerwordpress-db-1:/tmp/backup.sql /host/backup.sql
Method 2: Backup MySQL Data Volume
# 备份数据卷(宿主机操作)
docker run --rm -v mysql_data:/source -v /host/backup:/backup alpine tar czf /backup/mysql_data.tar.gz -C /source .
2. Import MySQL databases into the production environment
# 导入 SQL 文件(生产环境容器)
docker cp /host/backup.sql prod-mysql-container:/tmp/backup.sql
docker exec -i prod-mysql-container mysql -uroot -p123456 wordpress < /tmp/backup.sql
# 或从数据卷恢复
docker run --rm -v prod_mysql_data:/target -v /host/backup:/backup alpine tar xzf /backup/mysql_data.tar.gz -C /target
3. Validation of data integrity
# 检查关键表数据
docker exec prod-mysql-container mysql -uroot -p123456 -e "USE wordpress; SELECT COUNT(*) FROM wp_posts;"
Phase II: restoration of domain name jumps
1. Security replacement database old domain names Tool selection and operation- BetterSearchReplace Plugin:
- Full library replacement
localhost:8081Yes666.comI don't know. - Resize Maximum Page to
500, batch processing of large tables.
- Full library replacement
- Search-Replace-DB command line tool:
php srdb.cli.php -h localhost -u root -p 123456 -n wordpress -s "localhost:8081" -r "666.com" -g
// 在 wp-config.php 中定义绝对域名
define('WP_HOME', 'https://666.com');
define('WP_SITEURL', 'https://666.com');
3. Clean-up of server configuration residues
- Remove old orientation rule:
# .htaccess 中删除旧规则
RewriteRule ^(.*)$ https://localhost:8081/$1 [R=301,L] # 删除此行
Phase III: Certification and optimization
- Function Authentication
- Home page access:
curl -I https://666.comCheck status code200Not301/302I don't know. - Checks randomly whether articles, pages, media files URLs point to new domain names.
- Home page access:
- Performance optimization
- Configure the Redis or Memcached cache database query.
- Use
docker system pruneClears the image of the invalid container.
Operational risks and circumvention
| Risk scene | Performance | Refusal measures |
|---|---|---|
| Database Permission Conflict | Packaging startup failed, log hint denied | Harmonize the group of users of the data scrolls before backup 999:999(MySQL Default) |
| Sequenced data damage | Page layout is confused or plugin functions are abnormal | Use -g Parameters to process serialized data |
| Backup file incomplete | The structure of the imported watch is missing | Double Backup (SQL + Data Volume) to restore MD5 Hash |
V. Lessons learned and standardization processes
1. Standardized migration process
- Local Environment Backup:
# 备份数据库 + 数据卷
docker exec mysql-container mysqldump -uroot -p123456 wordpress > backup.sql
docker volume inspect mysql_data > volume_backup.json - Pre-configuration of the production environment:
- Creates the same version of MySQL container in advance, mounts the data volume.
- Incremental Data Sync:
- Use
rsyncSyncwp-content/uploads.
- Use
2. Example of automated scripts
#!/bin/bash
# 备份脚本
docker exec mysql-container mysqldump -uroot -p123456 wordpress > /backups/wordpress_$(date +%Y%m%d).sql
tar -czf /backups/mysql_data_$(date +%Y%m%d).tar.gz /var/lib/docker/volumes/mysql_data
# 恢复脚本
docker cp /backups/wordpress_20231001.sql prod-mysql-container:/tmp/
docker exec -i prod-mysql-container mysql -uroot -p123456 wordpress < /tmp/wordpress_20231001.sql
Long-lasting monitoring mechanisms
- Log Monitor:
docker logs -f prod-mysql-container | grep -E "ERROR|WARNING" - Health screening:
curl -s https://666.com/health-check | grep "OK"
VI. Final value
Through this migration practice, "Containerization WordPress 4-step method.":
- Standardized Backup: SQL + Data Volume Double Insurance.
- Tool rehabilitation: Security replacement data combined with plugins and command line tools.
- Atomic authenticationPhased check pages, API, media resources.
- Automated monitoringLogs, health checks, regular rollback tests.
This option could provide a generic template for the transport of containerization applications and reduce technical thresholds resulting from environmental differences.