WP-CLI Commands for WP Staging

The WP STAGING plugin is a powerful tool for creating a staging environment for your WordPress website or high-performance backups. It allows you to make changes, test new features, and perform updates without affecting your live site. This document provides instructions on how to use WP CLI commands specifically designed for the WP STAGING plugin.

Prerequisites

Before using the WP CLI commands for the WP Staging Pro plugin, ensure that the following requirements are met:

  1. WordPress installation: Make sure you have WordPress installed on your server.
  2. WP CLI: Ensure that WP CLI (Command Line Interface for WordPress) is installed on your server. Read the WP_CLI installation instructions.

Create a regular Backup via WP CLI

The wp wpstg backup-create command allows you to create a backup of your WordPress environment. This backup ensures you can revert to a previous state if any issues arise during testing or updates.

Syntax

Bash
wp wpstg backup-create

There are several parameters you can use:

name

default value: null

Description: Name of the backup file. Supported input type string

Usage:

ShellScript
wp wpstg backup-create name=my-backup 
# or
wp wpstg backup-create name='backup name with spaces'

includes

default value: database, mu-plugins, plugins, themes, uploads, others

Description: Parts to include in the backup. Supported values are databasemu-pluginspluginsthemesuploads and others.
It also support multiple values. Use comma to add multiple values like database,plugins,uploads.

Use only the includes or excludes parameter. If both are used, the includes parameter will be preferred and excludes parameter will be ignored

Usage:

ShellScript
wp wpstg backup-create includes=plugins,themes
# or
wp wpstg backup-create includes=database

excludes

default value: null

Description: Parts to exclude from the backup. Supported values are databasemu-pluginspluginsthemesuploads and others. It also support multiple values. Use comma to add multiple values like database,plugins,uploads. Only one of includes or excludes parameter to be used. If both are used in command includes param will be preferred and excludes param will be ignored

Usage:

ShellScript
wp wpstg backup-create excludes=database
# or
wp wpstg backup-create excludes=plugins,mu-plugins

advanced-excludes

default value: null

Description: Extra parts to exclude from the backup.

Supported values: logs, caches, deactivated-plugins, unused-themes, post-revisions, spam-comments

Usage:

ShellScript
wp wpstg backup-create advanced-excludes=logs,caches,deactivated-plugin,unused-themes,post-revisions,spam-comments

storages

default value: local-storage

Description: Storages in which the backup should be stored/uploaded. Some common supported values are local-storagegoogle-driveamazon-s3dropbox, and sftp.

It also support multiple values. Use comma to add multiple values like google-drive,amazon-s3,sftp. Make sure the storages that you want to use are already authenticated using your WordPress admin.

Usage:

ShellScript
wp wpstg backup-create storages=google-drive
# or
wp wpstg backup-create storages=local-storage,sftp

Create a scheduled backup plan via WP CLI

You can create scheduled backup plans by using WP CLI:

schedule

default value: null

Description: How often the backup should repeat. Supported values: hourlyevery-six-hoursevery-twelve-hoursdailyevery-two-daysweeklyevery-two-weeksand monthly. Only one value is supported at a time. If its value is not set, backup will not be schedule.

Usage:

ShellScript
wp wpstg backup-create schedule=hourly
# or
wp wpstg backup-create schedule=monthly

retention

default value: 2

Description: Name of the backups to retain for this schedule. Supported values: 1 to 10. Valid schedule value other than null is required otherwise this option will be ignored.

Usage:

ShellScript
wp wpstg backup-create schedule=monthly retention=3 
# or
wp wpstg backup-create schedule=monthly retention=5

time

default value: 00:00

Description: At what time the backup should start first schedule. Supported value is time in 24-hour format i.e. 13:0005:4223:5900:00 and 10:45. You can also use now to create backup immediately using current time as first repeating time. Valid schedule value other than null is required otherwise this option will be ignored.

Usage:

ShellScript
wp wpstg backup-create schedule=daily time='00:15'
# or
wp wpstg backup-create schedule=monthly time='12:12'
# or
wp wpstg backup-create schedule=monthly time='now'

Show the status of a running Backup with WP CLI

The wp wpstg backup-status command displays the status and details of a running backup available in your WordPress environment. It provides information such as the backup ID, title, creation date, and description.

Syntax

Bash
wp wpstg backup-status

Conclusion

The WP STAGING plugin and the provided WP CLI commands offer a convenient way to manage backups and monitor their status in your staging environment. By following the instructions outlined in this documentation, you can effectively create backups and stay informed about the available backups within your WordPress site.

Updated on February 7, 2024