Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

Automating Database Syncs with WP Migrate and WP-CLI

11 May 2026 at 19:45

Modern development workflows have mostly solved the file problem. We use Git to version our themes and plugins, and we use CI/CD pipelines to deploy those files to staging and production. But for many teams, the database remains a manual, high-stakes bottleneck.

Whether you are pulling production data down to a local environment for debugging or pushing a new ACF field structure up to staging, relying on manual SQL exports and imports is a recipe for disaster. It’s slow, it’s prone to human error, and it’s the most common way to break serialized data.

To reach true deployment maturity, you need to automate the database layer. That’s where WP Migrate’s integration with WP-CLI comes in.

Why wp db export Isn’t Enough

Many developers start by using the native wp db export and wp db import commands. While these are great for simple backups, they are dangerous for migrations between environments.

The primary culprit is serialized data. WordPress often stores complex data (like widget settings or ACF configurations) as serialized PHP objects. If your search-and-replace changes the length of a string (e.g., changing http://localhost to https://production.com), a standard SQL find-and-replace will break the serialization, and the data will simply vanish from the frontend.

Unlike standard SQL exports that treat the database like a flat text file, WP Migrate’s background logic handles search-and-replace at the PHP level. When the migration runs, the plugin identifies serialized data and temporarily unserializes it to perform the string replacement on the actual data structure. Once the strings are updated, it re-serializes the data and automatically recalculates the internal string-length counts before committing it to the destination database. This process ensures your metadata remains intact even when the new site URL has a completely different character count than the old one.

The Bridge: Migration Profiles

You can start firing off commands in the terminal at this point, but it’s probably better to create a Migration Profile first. Migration Profiles are a specialized feature provided by WP Migrate to manage complex configurations.

Migration Profiles are basically saved presets for your migration. In the WP Migrate UI, you define:

  • Which tables to include or exclude.
  • Specific find-and-replace pairs.
  • Whether to sync the Media Library or theme files.

By defining these in the UI first, you avoid the headache of passing dozens of complex arguments into a terminal command. Once saved, the CLI can trigger the entire logic of that profile using a single ID.

Selective Table Syncing: Protecting Production

The most significant risk in database automation is the push operation, when you move data from a lower environment (like Local or Staging) to the live Production server. If you push a full database that you’ve been working on for several days, you will overwrite the live site with your outdated local data, potentially wiping out every eCommerceorder or user registration that happened while you were developing.

This is where selective syncing becomes a mandatory safety measure. Instead of an “all or nothing” approach, WP Migrate’s integration with WP-CLI allows you to be surgical. In your Migration Profile, you should configure specific exclusions for transactional tables:

  • wp_users and wp_usermeta
  • wp_comments
  • wp_posts and wp_postmeta (specifically if you only want to sync settings/structures, not content)

By excluding these, you can perform a structural push that sends new ACF field groups or plugin configurations to production without the nightmare scenario of deleting customer data.

The Workflow: Push vs. Pull

In a professional pipeline, the direction of your migration depends on your goal.

Direction Command Best For… Risk Level
Pull wp migrate pull <ID> Refreshing staging with fresh production data. Low (Overwrites local/staging)
Push wp migrate push <ID> Deploying new ACF structures or settings to staging. High (Overwrites remote)

Automating with Secret Keys

WP Migrate uses secret keys for authorization. This means you don’t need to manage complex SSH tunnels just to move data. When setting up your CI/CD pipeline (like GitHub Actions), you should store these credentials as environment-scoped secrets within your CI/CD provider (like GitHub Actions or GitLab CI).

By scoping secrets specifically to the Production environment, you can implement protection rules, such as requiring a manual approval before the secrets are injected into a workflow. This ensures that a database push to your live site only happens when a senior team member has signed off on the deployment.

Real-World Implementation: GitHub Actions Snippet

Here’s how you might automate a Pull request to refresh a Staging site with Production data whenever a new release is tagged.

jobs:
  db-refresh:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger WP Migrate Pull via SSH
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.STAGING_HOST }}
          username: ${{ secrets.STAGING_USER }}
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          script: |
            # Navigate to the site root and trigger the saved profile
            cd /var/www/html
            wp migrate pull 5 --path=/var/www/html

In this example, the number 5 represents the specific ID of a Migration Profile created in the WP Migrate UI. Once you’ve identified your ID via the wp migrate profiles list command, the CLI takes it from there, automatically executing the authentication, the PHP-level search-and-replace, and the table exclusions you’ve already defined. This keeps your deployment script clean, as the heavy lifting of the configuration stays within the profile itself.

Conclusion

Manual migrations are basically technical debt. They eat up developer time and introduce unnecessary risk into your deployment cycle. By leveraging WP Migrate’s integration with WP-CLI, you move the database out of the manual task column and into your automated pipeline.

Whether you are syncing data for QA or deploying complex structural changes, using Migration Profiles and WP-CLI ensures that your environments stay in parity and your serialized data stays safe.

The post Automating Database Syncs with WP Migrate and WP-CLI appeared first on Delicious Brains.

Ars Asks: Share your shell and show us your tricked-out terminals!

I spend more time today than ever before interacting with terminal windows, which is something I don't think Past Me would have believed in the early '90s. Back then, poor MS-DOS was the staid whipping boy of the industry, and at least on the consumer side, graphical environments like Windows (and maybe even odder creatures like AmigaOS) seemed poised to stamp the command line into oblivion, leaving text interfaces behind as we all blasted into the ooey-GUI future.

As it turns out, though, the command line is still the best tool for some jobs—many jobs, in fact. I read a wise post some years ago (probably on Slashdot) arguing that a mouse-driven point-and-click interface essentially reduces the user to pointing at something on the screen and grunting, "DO! DO THAT!" at the computer. (The rise of right-click context menus adds the ability for the user to also grunt "MORE THINGS!" but doesn't otherwise add vocabulary.)

The command line, by contrast, gives the user the opportunity to precisely tell the computer what they want done, using words instead of one or two gestalts that the computer must interpret based on context.

Read full article

Comments

© Aurich Lawson | Getty Images

Getting Started with Basic Terminal Commands on macOS and Linux

MacOS and Linux share something in common that many new users overlook: the Terminal. The Terminal is the command-line interface (CLI) that allows you to communicate directly with your operating system. For many newcomers, it can look intimidating a black screen filled with text, seemingly expecting you to know secret codes. But once you start using it, you’ll quickly see that it’s one of the most powerful tools in your toolkit.

I’ve said it countless times, and I’ll say it again: learning to navigate and function in the Terminal is an essential skill for anyone using macOS or Linux. Even a little familiarity can save you hours of frustration when troubleshooting or performing tasks that would otherwise require several clicks in the GUI.

Before we dive into the commands, here’s a cardinal rule of Terminal usage: *

Never copy and paste commands from the internet without understanding them.*

While there are many tutorials online offering magical one-liners, blindly running commands can break your system or expose you to security risks. Instead, take the time to type out commands manually, paying attention to spaces, dashes, and syntax. This is how you learn. Trust me, those tiny details matter more than you think.

With that said, let’s explore some basic and safe Terminal commands that every MacOS or Linux user should know.

1. pwd Print Working Directory

The pwd command stands for Print Working Directory. This command shows you your current location within the filesystem.

Example:

pwd

Output might look like:

/Users/Craig/Desktop

This tells you that you are currently in the Desktop folder. Knowing where you are is crucial before performing any other operations—especially when moving or deleting files.

2. cd Change Directory

The cd command allows you to navigate between directories (folders) in the filesystem.

Examples:

cd /Desktop

This moves you into the Desktop directory.

cd ..

This moves you up one level in the directory hierarchy.

cd ~

This brings you back to your home directory.

A quick tip: pressing Tab while typing a folder name will autocomplete it if the folder exists. This is a real time-saver.

3. ls List Directory Contents

ls stands for list, and it displays the contents of your current directory.

Example:

ls

Output might look like:

Documents Downloads Music Pictures

You can also add options for more detail:

ls -l

Shows files with permissions, ownership, size, and date modified.

ls -a

Shows hidden files (files beginning with a .), which are usually configuration files in Unix-based systems.

4. mkdir Make Directory

mkdir creates a new folder.

Example:

mkdir MyNewFolder

Now you have a folder called MyNewFolder in your current directory. Combine it with cd to immediately enter the new folder:

cd MyNewFolder

5. touch Create Empty Files

The touch command creates a new empty file.

Example:

touch notes.txt

This will create a blank file called notes.txt in your current directory. It’s a handy way to quickly create test files or placeholders.

6. cp Copy Files and Directories

cp is used to copy files or directories.

Example:

cp notes.txt backup_notes.txt

This copies notes.txt into a new file called backup_notes.txt.

For directories, use the -r flag to copy recursively:

cp -r MyNewFolder MyNewFolderCopy

7. mv Move or Rename Files

mv can move a file to another directory or rename it.

Examples:

mv notes.txt Documents/

Moves notes.txt into the Documents folder.

mv notes.txt todo.txt

Renames notes.txt to todo.txt.

8. rm Remove Files and Directories (With Caution!)

rm deletes files or directories. Be careful—deleted files don’t go to the Trash.

Example:

rm todo.txt

Deletes the todo.txt file.

For directories:

rm -r MyNewFolder

This recursively deletes the folder and all its contents. Triple check before running this command.

9. man Manual Pages

man shows the manual page for any command. Think of it as the built-in help system.

Example:

man ls

This opens the manual for the ls command, showing all options and usage examples.

10. echo Display Text

echo prints text to the Terminal. It’s simple, but very useful.

Example:

echo "Hello, world!"

Output:

Hello, world!

It can also be used to append text to a file:

echo "My first line" >> notes.txt

This adds a line to notes.txt.

11. cat Display File Contents

cat reads a file and prints its contents to the Terminal.

Example:

cat notes.txt

It’s perfect for quick checks without opening a text editor.

12. clear Clear the Terminal

clear wipes the Terminal screen, giving you a clean workspace.

Example:

clear

13. Combining Commands with Pipes and Redirects

Once you’re comfortable with basic commands, you can combine them for more powerful operations:

  • Pipe |: Sends output from one command as input to another.
ls -l | grep "Documents"

Finds the word “Documents” in your directory listing.

  • Redirect >: Saves output to a file.
echo "Hello" > hello.txt

Creates a file called hello.txt with the text “Hello”.

Final Tips for Terminal Newbies

  1. Practice typing commands instead of copy-pasting. It’s how you truly learn.
  2. Start small don’t try to master everything at once.
  3. Use man often it’s your best friend.
  4. Be careful with sudo it gives commands administrative powers, which can break your system if misused.
  5. Experiment in a safe environment create test folders and files to play around.

Learning the Terminal may feel old-school, but it’s an invaluable skill for anyone serious about macOS or Linux. It gives you control, speed, and a deeper understanding of your computer. Even if you only use a handful of commands, you’ll be far better prepared for troubleshooting, automation, and advanced computing tasks.

Debugging WP-Cron With WP-CLI

3 February 2026 at 20:17

It’s a common situation. You schedule a backup for 2 a.m., but when you log in the next morning, the file isn’t there. Or perhaps a scheduled post missed its publication window, leaving you with a “Missed Schedule” error.

The root cause is often the WordPress cron system. Unlike a standard system cron that runs on a strict clock, WP-Cron is a pseudo-cron. It relies on page visits to trigger scheduled tasks. If no one visits the site, the tasks don’t run. If a visitor arrives while a heavy task is pending, their page load might hang while WordPress processes the queue in the background.

Debugging this via the WordPress dashboard is often frustrating. Installing a plugin just to view your cron events adds unnecessary bloat. A more direct and reliable method is to use the command line.

WP-CLI provides immediate visibility into the scheduler and, more importantly, allows you to force-run events to see if they fail.

Gaining Visibility

The first step in debugging is seeing what is actually in the queue. The default dashboard gives you no insight into this, but one command reveals the entire schedule.

Run the following command in your terminal:

wp cron event list

This outputs a table with four key columns: hook, next_run_gmt, next_run_relative, and recurrence.

The most important column for debugging is next_run_relative.

  • If it says “10 minutes” or “1 hour,” the event is scheduled for the future.
  • If it says “now”, “1 hour ago”, or “Yesterday”, the event is stuck.

A “stuck” event usually means one of two things: either the site hasn’t had any traffic to trigger the runner, or the PHP script attempted to run but crashed silently.

The Magic Fix: Force Running Events

Waiting for a suspect task to run naturally is inefficient. You need to see the error output immediately.

You can force any event to run right now, regardless of its schedule, using the run command:

wp cron event run <hook_name>

For example, if your backup hook is named my_daily_backup, you would run:

wp cron event run my_daily_backup

When WP-Cron runs normally (via a page visit), PHP errors are often suppressed or hidden in a log file you might not be checking. Fatal errors are output directly to your terminal when you run it via WP-CLI.

If the script is running out of memory or hitting a PHP timeout, the command line will tell you instantly.

Clearing the Backlog

If you manage a site that has been offline or neglected, you might find dozens of overdue tasks clogging the queue. Rather than running them one by one, you can force WordPress to process all overdue events at once:

wp cron event run --due-now

Cleaning Up the Junk

Over time, the wp_options table can accumulate orphaned cron events. These are scheduled tasks left behind by plugins that were deactivated or deleted incorrectly. They don’t break the site, but they do clutter the database and the cron list.

To delete a specific event:

wp cron event delete <hook_name>

Be careful not to delete core WordPress hooks (like wp_scheduled_delete or wp_version_check). Focus only on hooks clearly named after plugins you no longer use.

Alternative: Disabling the Default WP-Cron

For high-traffic sites, or sites where timing is critical, relying on page visits to trigger tasks is often insufficient. In these cases, it’s common to disable the default behavior and replace it with a system cron.

This involves two steps. First, you disable the trigger in wp-config.php:

define('DISABLE_WP_CRON', true);


This stops WordPress from checking for scheduled tasks on every page load, which can improve page load speed for users.

However, once this is disabled, nothing will run until you set up an alternative trigger. You must add an entry to your server’s system crontab to call WP-CLI every minute.

Important: Do not run this as the root user. WP-CLI limits root execution for security reasons. Instead, add this line to the crontab of your web server user (often www-data) or your specific hosting user:

* * * * * /usr/local/bin/wp cron event run --due-now --path=/var/www/yoursite/ > /dev/null 2>&1


There are three key changes in this command compared to a standard manual run:

  1. Full Path: We use /usr/local/bin/wp because system crons run in a minimal environment and might not know where the wp command is located otherwise.
  2. Path to Site: The --path flag ensures WP-CLI executes within the correct WordPress installation.
  3. Silencing Output: The > /dev/null 2>&1 at the end prevents the server from emailing you a notification every single minute that the task ran successfully.

This configuration ensures that scheduled tasks run precisely on time, regardless of whether anyone is visiting the website.

Conclusion

WP-Cron shouldn’t be viewed as a “black box” that developers cross their fingers and hope works. Shifting your workflow to the terminal turns that black box into a transparent queue. Using wp cron event list and run allows you to diagnose issues in seconds rather than days, ensuring your backups, emails, and scheduled posts happen exactly when they are supposed to.

The post Debugging WP-Cron With WP-CLI appeared first on Delicious Brains.

❌
❌