Step-by-Step Large WordPress Site Migration Guide

In this article, we will walk through the process of migrating a large WordPress site, focusing on both the large database (i.e. over 40 GB) and the large uploads directory size (i.e. over 100 GB). We will assume that you have shell access to both the old and new servers and that tools such as mydumper and rsync will be used for the migration. The steps outlined here will help ensure that the migration is done efficiently, especially when dealing with large amounts of data.

Prerequisites:

  • Shell access to both the old and new servers.
  • Ensure mydumper and rsync are installed on both servers.
  • Basic knowledge of PHP, SQL, and Bash.

Key Details:

  • Old domain: www.old-site.com
  • New domain: www.new-site.com
  • Old database name: olddb
  • New database name: newdb

Step 1: Verify Tools Installation

First, check if mydumper and rsync are installed on both servers. If not, you can install them using the following commands:

Check for MyDumper and Rsync:

Install MyDumper:

Install Rsync:


Step 2: Export the Database in Smaller Compressed Chunks

Use mydumper to export the large database from www.old-site.com in smaller, compressed chunks. mydumper is particularly useful because it allows parallel exports and compression.

Export Command:

  • --threads=4: Number of threads for parallelism.
  • --chunk-filesize=100: Each chunk file size will be around 100MB.
  • --compress: Compresses each chunk during export.

Step 3: Transfer the Exported Database to the New Server

After the export is complete, use rsync to transfer the database chunks from www.old-site.com to www.new-site.com.

Rsync Command:

  • -a: Archive mode.
  • -v: Verbose.
  • -z: Compress during transfer.

Step 4: Import the Database into the New Server

On www.new-site.com, use the myloader command to import the database chunks into the new database (newdb).

Import Command:

  • --overwrite-tables: Overwrite any existing tables.
  • --compress: Automatically handles decompression of the exported files.

Step 5: Migrate the Uploads Directory in Chunks

The WordPress upload folder can be very large, so it’s efficient to split it into smaller chunks before transferring. We will use PHP and rsync to automate this process.

PHP Script to Split the Upload Directory:

Run the script to copy the files in smaller chunks.

Transfer the Chunks using Rsync:

Reconstruct the chunked file(Only needed if you have done chunking using the PHP script for chunking)


Step 7: Update URLs and GUIDs in the WordPress Database

After migrating the files and database, update the old domain references in the new database. This includes replacing all instances of the old domain (www.old-site.com) with the new domain (www.new-site.com) in the database.

SQL Procedure to Change Domain:

Use the following stored procedure to update the domain across the posts, options, and postmeta tables.

This script will update the home, siteurl, guid, post_content, and meta_value fields.


Conclusion

Migrating a large WordPress site requires careful planning, especially when dealing with large databases and files. The combination of mydumper, rsync, PHP, and SQL procedures ensures that both the database and uploads folder can be transferred efficiently without overwhelming the system or network. Follow these steps closely to achieve a smooth and successful migration.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *