Schedule WordPress Exports Using Cron Jobs

Schedule WordPress Exports Using Cron Jobs

To run a WordPress export on a schedule, create two cron jobs on your server. Set one cron job to run every 2 minutes and execute the processing URL from WP All Export. Then, set up another cron job that executes the trigger URL and runs however often you want the export to run.

Manual Scheduling vs Automatic Scheduling

WP All Export offers two ways to schedule or automate exports. The first option is to manually create the cron jobs in the server. The second option is to use our paid Automatic Scheduling Service, which is integrated within WP All Export and doesn't require any setup. Learn more about Automatic Scheduling.

This guide focuses on Manual Scheduling.

Manual Scheduling Uses Cron Jobs

Cron jobs are like reminders for your web server. When you create a cron job, you are basically telling your server that you want to do a specific thing over and over at specific times.

These cron jobs consist of two things: a time and a command. The way they handle time is a little weird, but there are tools like https://crontab.guru/ that make it easy to understand. When the cron job is triggered, the web server will execute the command you provided. In this case, you'll tell the server to open a URL that will trigger your export to run.

To set up an export with Manual Scheduling, WP All Export actually uses two cron jobs to make sure they run on time and finish the export.

Trigger URLs and Processing URLs

Each scheduled export requires two cron jobs. The first one uses the trigger URL, which will fire whenever you want the export to run. The second uses the processing URL, which will fire every two minutes. Web servers generally don't like processes running in the background for a long time, and will kill them after a few minutes. The processing URL goes through and checks to make sure that your export has completed running. If it hasn't, it will start it up again.

To get your trigger URL and processing, navigate to the Manage Exports page, then click on Scheduling Options:

Once there, select the Manual Scheduling option. There you will find the trigger URL and processing URL. There's also a File URL, and a Bundle URL, used to retrieve the latest export files:

The trigger URL is structured like this: https://[YOUR-WEBSITE].com/wp-load.php?export_key=[YOUR_SECRET_KEY]&export_id=[YOUR_EXPORT_ID]&action=trigger

The processing URL is structured like this:https://[YOUR-WEBSITE].com/wp-load.php?export_key=[YOUR_SECRET_KEY]&export_id=[YOUR_EXPORT_ID]&action=processing

Your secret key can be accessed and reset from All Export › Settings.

The trigger cron should be set to run however often you want your export to run.

The processing cron should be set to run every two minutes.

Example Cron Jobs

You should be able to create your cron job in your web hosting control panel. To create a cron job that hits the cron URLs, commonly the wget command is used.

wget -q -O - /dev/null "https://example.com/wp-load.php?export_key=ph2Pyi_dMN&export_id=1&action=trigger"
wget -q -O - /dev/null "https://example.com/wp-load.php?export_key=ph2Pyi_dMN&export_id=1&action=processing"

Alternatively, you can use cURL.

curl -s "https://example.com/wp-load.php?export_key=ph2Pyi_dMN&export_id=1&action=trigger" > /dev/null
curl -s "https://example.com/wp-load.php?export_key=ph2Pyi_dMN&export_id=1&action=processing" > /dev/null

Please note that in both cases, the URLs need to be in quotes. Here's how these cron jobs would look in cPanel:

Get Help From Your Host

If you're not sure how to create these cron jobs manually, your web host support team will be able to set them up for you. Here's an e-mail template you can use:

Please set up two cron jobs.

CRON JOB 1
Fetch this URL every 24 hours:
https://[YOUR-WEBSITE.com]/wp-load.php?export_key=[YOUR_SECRET_KEY]&export_id=[YOUR_EXPORT_ID]&action=trigger

CRON JOB 2
https://[YOUR-WEBSITE.com]/wp-load.php?export_key=[YOUR_SECRET_KEY]&export_id=[YOUR_EXPORT_ID]&action=processing

If your web host doesn』t have a cron feature, you can use an external service such as EasyCron.

Call Cron URLs from the Command Line

You can also call the WP All Export cron URLs from the command line. This may be necessary if your site's configuration doesn't allow inbound calls to the regular cron URLs.

It'd look something like this:

/path/to/your/php-cgi /path/to/your/wordpress/install/wp-load.php export_key=[YOUR_EXPORT_KEY] export_id=[YOUR_EXPORT_ID] action=trigger
/path/to/your/php-cgi /path/to/your/wordpress/install/wp-load.php export_key=[YOUR_EXPORT_KEY] export_id=[YOUR_EXPORT_ID] action=processing

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注