← Back to list

Local to cloud: WordPress Migration Full Chain Solutions, Data Backup, Database Restoration, etc.

itadol5j

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.com Autojump to localhost: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

  1. Database old domain name
    • wp_options Table siteurl and home field is not updated.
    • Articles, metadata and sequenced data (e.g., menus, small tools) contain hard-coded old addresses.
  2. Docker Data Management Missing
    • Failure to adopt a data volume or mysqldump Complete backup, direct handling containers resulting in an irreversible loss of data.
  3. Server Configuration Interference
    • Redirective rules of the old environment (e.g. .htaccessNot cleared.

III. Full-chain solutions

Phase 1: Docker Data Backup and Migration

1. Backup MySQL Database Method 1: Adoption mysqldump 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:
    1. Full library replacement localhost:8081 Yes 666.comI don't know.
    2. Resize Maximum Page to 500, batch processing of large tables.
  • 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  
2. Force Update WordPress Configuration
// 在 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

  1. Function Authentication
    • Home page access:curl -I https://666.com Check status code 200 Not 301/302I don't know.
    • Checks randomly whether articles, pages, media files URLs point to new domain names.
  2. Performance optimization
    • Configure the Redis or Memcached cache database query.
    • Use docker system prune Clears the image of the invalid container.

Operational risks and circumvention

Risk scenePerformanceRefusal measures
Database Permission ConflictPackaging startup failed, log hint deniedHarmonize the group of users of the data scrolls before backup 999:999(MySQL Default)
Sequenced data damagePage layout is confused or plugin functions are abnormalUse -g Parameters to process serialized data
Backup file incompleteThe structure of the imported watch is missingDouble Backup (SQL + Data Volume) to restore MD5 Hash

V. Lessons learned and standardization processes

1. Standardized migration process

  1. Local Environment Backup:# 备份数据库 + 数据卷  
    docker exec mysql-container mysqldump -uroot -p123456 wordpress > backup.sql  
    docker volume inspect mysql_data > volume_backup.json  
  2. Pre-configuration of the production environment:
    • Creates the same version of MySQL container in advance, mounts the data volume.
  3. Incremental Data Sync:
    • Use rsync Sync wp-content/uploads .

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.":

  1. Standardized Backup: SQL + Data Volume Double Insurance.
  2. Tool rehabilitation: Security replacement data combined with plugins and command line tools.
  3. Atomic authenticationPhased check pages, API, media resources.
  4. 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.