WP-CLI UpdraftPlus Documentation

Before using WP CLI:

Before using WP CLI, make sure it is installed. For installation of WP CLI, refer to this page: https://make.wordpress.org/cli/handbook/installing/.

Using WP CLI with UpdraftPlus:

UpdraftPlus provides WP CLI commands to take backups and manage backups. It is not mandatory to login to the admin dashboard to use UpdraftPlus. Here are some commands you could use with UpdraftPlus’ WP-CLI.

    • To install the plugin (free version): wp plugin install updraftplus
    • To install and activate the plugin: wp plugin install updraftplus --activate
    • To list all installed plugins: wp plugin list
    • To update all plugins: wp plugin update --all

The below are the commands that can be run to interact with UpdraftPlus, just as you would interact with it within the WordPress dashboard:

Backup

To take a backup, simply run the command below. Generally, the default options are those which are saved in your settings:

wp updraftplus backup

You can enhance the backup command by adding the following parameters to it:

OptionRequirementDescriptionExample
[--label]Required: NoAdd a label to the backupwp updraftplus backup --label="UpdraftplusCLI Backup"
[--exclude-db]Required: NoExcludes database entity from being backed up. By default database is included in backupwp updraftplus backup --exclude-db=true
[--send-to-cloud]Required: NoExclude the backup being sent to remote storage. By default, if set up, backups will be sent to remote storagewp updraftplus backup --send-to-cloud=false
[--include-files]Required: NoDecides which backup file entity should be added to backup. By default its value is same as Settings > UpdraftPlus Backups > Settings > Include in files backup.

You have to pass multiple values by comma-separating them. [--include-files] Possible backup entities are plugins, themes, uploads, wpcore and others.

wp updraftplus backup --include-files= "plugins,themes,uploads"
[--include-tables]Required: NoIndicates which tables should be added to database backup. By default all WordPress tables are included in the database backup.

You canpass multiple values by comma-separating them. You can pass the table name with the WordPress database table prefix or without the prefix.

wp updraftplus backup --include-tables= "wp_posts,wp_postmeta"

 

Restore

To restore a backup, run the command below.

wp updraftplus restore <nonce>

The <nonce> is the unique identifier for the backup set that you wish to restore.

You can enhance the restore command by adding the following parameters to it:

OptionRequirementDescriptionExample
[--components]Required: NoThe components to restore. Multiple component names should separate by comma (,). If you do not pass this argument, UpdraftPlus will restore all backup entities in the given backup (“all”).wp updraftplus restore b290ee083e9e --components="db,plugins,themes"
[--db-decryption-phrase]Required: NoIf the database backup is encrypted, provide the database decryption phrase here.wp updraftplus restore b290ee083e9e --db-decryption-phrase="password"
[--over-write-wp-config]Required: NoWhether the wp-config.php file will be overwritten or not. This option requires the “More files” add-on.wp updraftplus restore b290ee083e9e --over-write-wp-config=true
[--incremental-restore-point]Required: NoIncremental restore point. This option requires the “Support for incremental backups” add-on.wp updraftplus restore b290ee083e9e incremental=5
[--migration]Required: NoWhether the restoration is a migration or not. If you are restoring another site backup, This option’s value will be considered. Otherwise this is ignored. This option requires the “Migrator” add-on.wp updraftplus restore b290ee083e9e --migration=true
[--site-id-to-restore]Required: NoTo restore a specific sub-site in a Multisite setup. The option value -1 is for restoring all sites. If you are restoring a Multisite backup, this options’ value will be considered. Otherwise this is ignored. This option only affects the restoration of the database and uploads – other file entities (such as plugins) in WordPress are shared by the whole network. This option requires the “Network / Multisite” add-on.wp updraftplus restore b290ee083e9e --site-id-to-restore=2
[--delete-during-restore]Required: NoWhether to delete backup archives after they have been restored. Defaults to false.wp updraftplus restore b290ee083e9e --delete-during-restore=true
[--db-dummy-restore]Required: NoRestores the backup. When we pass ‘–db-dummy-restore=true’ to our command it will run a dummy restore of the database with a random prefix and delete all dummy tables after finishing the process. The purpose of adding this option is to check if the process times out during the restore backup. It’s totally optional. If we don’t pass this option restores process would work as it currently does.wp updraftplus restore [nonce] --components="db" --db-dummy-restore=true
[--collate]Required: NoIf specified, and if the database contains any collations unavailable on the local MySQL server, then this will be substituted in its place.wp updraftplus restore [nonce] --components="db" --collate=utf8mb4_general_ci

In addition to backing up your website, you can also run the following commands to return extra information:

OptionDescriptionExample
existing_backupsDisplays existing backupswp updraftplus existing_backups
get_latest_full_backupGet the job_id of the latest backup that includes every entity (i.e. plugins, themes, …) configured to be backed up in your settings.wp updraftplus get_latest_full_backup
existing_backupsDisplays existing backupswp updraftplus existing_backups
backup_progressSee backup progress by job_idwp updraftplus backup_progress <Job ID>

e.g. wp updraftplus backup_progress c23c41b1f567

get_most_recently_modified_logDisplays the most recently modified log file’s contentswp updraftplus get_most_recently_modified_log
get_log Displays the log content for a given backup job_idwp updraftplus get_log <Job ID>

e.g. wp updraftplus get_log c23c41b1f567

activejobs_delete Terminates a running backup jobwp updraftplus activejobs_delete <Job ID>

e.g. wp updraftplus activejobs_delete c23c41b1f567

rescan_storageRescan either local or remote storage for backup sets. Default: remotewp updraftplus rescan_storage [--type=<remote|local>]

e.g. wp updraftplus rescan_storage local

incremental_backupsList incremental backupswp updraftplus incremental_backups

 

Commands for assisting with migration and UpdraftCentral –

OptionDescriptionExample
create_migration_keyCreates a RSA keypair for migration one part is saved the other part needs to be copied/sent to the remote site.wp updraftplus create_migration_key <name> <size>

e.g. wp updraftplus create_migration_key my_key_name 2048

create_updraftcentral_keyCreates a UpdraftCentral key. NOTE: this command must be run with the –user flag otherwise the key created will be invalid

<where_send>: “updraftpluscom” for hosted UpdraftCentral or the host of the self-hosted version

wp --user=<User ID> updraftplus create_updraftcentral_key <name> <size> <use-alternative-connection-method> <where-send>

e.g. p --user=1 updraftplus create_updraftcentral_key my_key_name 2048 0 updraftpluscom

search_and_replaceRuns a search/replace operation using UpdraftPlus’s search/replace mechanism.wp updraftplus search_and_replace <search> <replace> [--page-size=5000] [--which-tables=<comma separated list>]

e.g. wp updraftplus search_and_replace example.com new_example.com 1000 options,users