Sync Sites with Command

Advertisement

  1. Create a new WordPress site.
  2. Export the database of old site in /wp-content/
    wp db export wp-content/database.sql
  3. Navigate to the new site “root”.
    cd <path-to-new-site>
  4. Copy files of the old site to new site directory.
    rsync -av --delete --exclude=.git/ --exclude=wp-config.php <path-to-old-site> <path-to-new-site>

    -a = Copies all the files from source to destination recursively it also compresses the files when copying so less bandwidth is used.
    -v = Verbose, Displays all the files that are being copied.

    –delete = delete’s the extra files present on the new site so that all the files/folders are exactly same as the old site.
    –exclude = Exclude files/folders when copying.

    NOTEAfter this process make sure the wp-config.php file is not copied over, the new site should have it’s same file.

  5. In the new site drop the current database and import the database in wp-content directory (this databse was copied from old site in step 4)
    wp db drop

    – drop the current database

    wp db create

    – create the database using the wp-config file.

    wp db import wp-content/database.sql

    – Import the database copied from the old site.

  6. If the site is multisite, copy the extra Multisite constants from the old site to new site.
  7. Search Replace the old URLs to new URLs
    wp searh-replace <old-url> <new-url> --precise --recurse-objects

    If the site is a multisite –

    wp --url=<old-site> searh-replace <old-url> <new-url> --precise --recurse-objects --network
  8. IF any cache is used on teh site clear it.
    wp beaver clearcache

    – Clear the beaver builder cache.

    wp nnginx-helper purge-all

    – Clear nginx helper cache.

%d bloggers like this: