By using the Pagely Sync tool, you can easily create one-time copies of your site without the manual process of copying, pasting, exporting, and importing.
This article covers utilizing the Pagely Sync command for syncing your files and database between sites. It is a useful tool for one-time copies of a WordPress site. If you need more granular or repetitive cloning processes, we recommend using the Pagely Cloning Tool.
How it Works
Pagely Sync can create a copy of established sites to a new instance or overwrite old copies on the destination application. These are designed to clone the site exactly as it is on the source application. So it will sync/import a copy of the source files and database entirely from one site to the target site, overwriting any pre-existing target database.
File syncs are bi-directional using a PHP-based wrapper, the database is uni-directional to allow users to quickly clone, or duplicate an instance. If you’re seeking to merge changes back to the master install, or push changes live, a Git-based workflow will suit you best.
Basic Usage
To use Pagely Sync, you'll need to log into your Pagely site using SSH.
Once logged in, you can run the following to see all available parameters for the Pagely Sync command:
pagely sync --help
Here's what you'll see when accessing the --help parameter:
Usage:
sync [--ignore-table[="..."]] [--ignore-path[="..."]] [--target-host="..."] [--ssh-identity="..."] [--dry-run] [--skip-file] [--skip-db] [--rename] source target
Arguments:
source The source directory
target The target directory
Options:
--ignore-table[=IGNORE-TABLE] Ignore this table while syncing db (multiple values allowed)
--ignore-path[=IGNORE-PATH] Ignore this path, rsync rules (multiple values allowed)
--target-host=TARGET-HOST Remote host to use in rsync target
--ssh-identity=SSH-IDENTITY ssh identity file to use with rsync
--dry-run Print what you would do
--skip-file Don't sync files
--skip-db Don't sync db
--db-recent-only Only sync the last 100 posts from wp_posts (and children) and there matching rows in post_meta
--limit-to-multisite[=LIMIT-TO-MULTISITE] blog_id of sites you want to limit the sync to, repeatable (multiple values allowed)
--reset-target-db Delete all tables in the target db before syncing, useful when the source has a different table prefix, or the target has extra tables
Cannot be used in combination with the --dry-run option.
--rename Update wp_options/wp_blogs and search/replace at target, with targets orginal name (on multisite only renames the primary domain)
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Creating a Staging Site from a Production Site
Pagely Sync is perfect for things like cloning sites between staging and production environments. If you don't already have a staging site to test changes before making them live, creating a staging site is a great way to get started with Pagely Sync!
- Begin by logging into the server with SSH.
- Before cloning, you'll want to double-check the table prefix that your existing production site is using. You can check it from the SSH terminal by running the following:
If your table prefix anything other than wp_, you'll want to edit your staging site's wp-config.php file and change it to the correct prefix that matches your current production site.cat ~/sites/example.com/wp-config.php | grep '$table_prefix'
- Now it's time to do a quick test to make sure that everything runs properly before running the clone process.
To do a dry run of the Pagely Sync tool without making any changes yet, run the following command:pagely sync --dry-run --rename ~/sites/example.com ~/sites/staging.example.com
- Did everything run successfully in the last step? Great! Now let's remove the
--dry-run
parameter to perform the sync from production to staging:
pagely sync --rename ~/sites/example.com ~/sites/staging.example.com
Once the Pagely Sync tool completes, your production site has been successfully cloned over to your staging environment!