Site icon Fix I.T. Phill – Your Go-To Tech Guru

How to Automate WordPress Backups with WP-CLI and Cron

How to Automate WordPress Backups with WP-CLI and Cron backup tutorial showing files database offsite storage and restore verification

How to Automate WordPress Backups with WP-CLI and Cron backup tutorial showing files database offsite storage and restore verification

How to Automate WordPress Backups with WP-CLI and Cron is for developers, server admins, advanced site owners, and hosting teams who have SSH access. Use this method when repeatable database exports, scripted file archives, offsite syncs, and monitoring backup schedules outside wp-admin.

A good WordPress backup includes the website files and the database. The files carry themes, plugins, uploads, configuration, and custom code. The database carries posts, pages, users, settings, WooCommerce orders, booking records, form entries, menus, and plugin data. Before you change WordPress core, PHP, DNS, plugins, themes, checkout, or a page builder, make sure you know which backup contains both halves.

When this backup method makes sense

WP-CLI and server cron is a good fit when you already have that tool available and need a practical restore path. It is especially useful before updates, redesign work, hosting migrations, malware cleanup, PHP changes, database work, and plugin troubleshooting.

Before you begin

Backup steps

  1. Confirm you have SSH access and WP-CLI works for the target site.
  2. Use wp db export to create a database SQL file in a protected backup directory.
  3. Archive the WordPress files or at minimum wp-content and configuration files needed for recovery.
  4. Move or sync the backup to offsite storage using your approved server backup process.
  5. Add retention so old backups are removed after a safe window.
  6. Log output and alert on failures instead of assuming cron always worked.

Automated backups and cron

WP-Cron is WordPress traffic-triggered scheduling. Server cron is better for predictable backup jobs because it runs on time even when the site has no visitors. Many plugins use WP-Cron internally, so monitor both layers.

For WordPress plugin backups, remember that WordPress scheduled tasks often depend on WP-Cron. WP-Cron runs when WordPress receives traffic and notices a task is due. That is fine for many small sites, but low-traffic sites can run late. For business-critical sites, pair plugin schedules with a real server cron, hosting-panel backups, or provider backups where available.

How to test restore readiness

Use wp db import for database restore when appropriate, then restore files from the matching archive. Always test commands on staging before running them against production.

Do not test your only restore for the first time during an outage. Use a staging copy, temporary subdomain, local development environment, or provider restore preview when available. After restore, check login, home page, important pages, media, forms, checkout, email delivery, permalinks, and cache behavior.

Common mistakes

Where to store the backup

Keep at least one copy outside the web server. Good destinations include your own Google Drive, Dropbox, OneDrive, S3-compatible storage, Backblaze B2, Wasabi, SFTP, a provider backup vault, or a secure internal backup server. The exact tool matters less than the restore test, retention policy, and separation from the production account.

Fix I.T. Phill recommendation

Use WP-CLI and server cron as one layer, not the whole plan. Keep a second backup path for important sites, especially WooCommerce, bookings, memberships, and agency-managed sites. Before major updates, take a fresh manual backup even if automatic backups are already scheduled.

Related Fix I.T. Phill guides

Sources checked

Exit mobile version