Skip to content

Instantly share code, notes, and snippets.

@Nav-Appaiya
Created July 16, 2021 15:16
Show Gist options
  • Select an option

  • Save Nav-Appaiya/0474b230eecc927fea754190dbe7080f to your computer and use it in GitHub Desktop.

Select an option

Save Nav-Appaiya/0474b230eecc927fea754190dbe7080f to your computer and use it in GitHub Desktop.
Backup / Restore full wordpress site
wp db export
zip -r my_export_file_name.zip *
rm (name of sql file you exported)
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:
Option Requirement Description Example
[--label] Required: No Add a label to the backup wp updraftplus backup --label="UpdraftplusCLI Backup"
[--exclude-db] Required: No Excludes database entity from being backed up. By default database is included in backup wp updraftplus backup --exclude-db=true
[--send-to-cloud] Required: No Exclude the backup being sent to remote storage. By default, if set up, backups will be sent to remote storage wp updraftplus backup --send-to-cloud=false
[--include-files] Required: No Decides 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: No Indicates 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:
Option Requirement Description Example
[--components] Required: No The 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: No If the database backup is encrypted, provide the database decryption phrase here. wp updraftplus restore b290ee083e9e --db-decryption-phrase="password"
[--over-write-wp-config] Required: No Whether 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: No Incremental restore point. This option requires the “Support for incremental backups” add-on. wp updraftplus restore b290ee083e9e incremental=5
[--migration] Required: No Whether 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: No To 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: No Whether to delete backup archives after they have been restored. Defaults to false. wp updraftplus restore b290ee083e9e --delete-during-restore=true
[--db-dummy-restore] Required: No Restores 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: No If 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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment