WordPress Backup and Update

There are two kinds of site owners: who take backups, and who will start. A backup saves you from a hack, a bad update and your own mistakes.

What to back up

PartWhereWhy
DatabaseMySQL or MariaDBPosts, pages, comments, users and settings
wp-contentYour server folderThemes, plugins and uploaded media
wp-config.php and .htaccessRoot folderConnection settings and rules

The WordPress core files do not need a backup, because you can download them again.

Backup with WP-CLI

Terminal output

$ wp db export backup.sql
Success: Exported to 'backup.sql'.
$ tar -czf backup-files.tar.gz wp-content wp-config.php .htaccess
$ ls backup*
backup-files.tar.gz
backup.sql

Keep the backup away from the web server (for example in cloud storage), because a database file on the same server can be downloaded by others.

Restore

Terminal output

$ wp post create –post_title="Mistake" –post_status=publish –porcelain
5
$ wp post list –post_type=post –format=count
2
$ wp db import backup.sql
Success: Imported from 'backup.sql'.
$ wp post list –post_type=post –format=count
1

The database import brought the site back to the state of the backup, and the post “Mistake” is gone. For the files, extract the archive on the server again.

Backup plugins

  • UpdraftPlus: schedules backups and sends them to Google Drive, Dropbox and more.
  • All-in-One WP Migration: exports the full site in one file, and helps to move it.
  • Your host: many hosts take daily backups. Check how long they keep them, and if you can restore by yourself.

Updates

Updates fix security problems and add features. There are updates for the WordPress core, plugins, themes and translations. See what is waiting:

Terminal output

$ wp core check-update
Success: WordPress is at the latest version.
$ wp plugin list –update=available –format=count
0
$ wp theme list –update=available –format=count
0

A safe update routine

  1. Take a full backup first.
  2. Update on a staging copy of the site if the site is important.
  3. Update the plugins and themes one by one (or in small groups), and test the site after it.
  4. Update WordPress core, and test again.
  5. If something breaks, restore the backup, or roll back the one plugin.

Minor and security releases of WordPress are updated automatically by default. The automatic updates for plugins and themes can be turned on from the plugin and theme list, one by one.

Terminal output

$ wp core update
Success: WordPress is up to date.
$ wp plugin update –all
Success: Plugin already updated.

Note: Never edit the files of a plugin or theme directly, because the next update will remove your changes. Next: you have finished the basics. Go to the theme development chapters, starting with WordPress Development.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.