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
| Part | Where | Why |
|---|---|---|
| Database | MySQL or MariaDB | Posts, pages, comments, users and settings |
| wp-content | Your server folder | Themes, plugins and uploaded media |
| wp-config.php and .htaccess | Root folder | Connection settings and rules |
The WordPress core files do not need a backup, because you can download them again.
Backup with WP-CLI
$ 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
$ 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:
$ 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
- Take a full backup first.
- Update on a staging copy of the site if the site is important.
- Update the plugins and themes one by one (or in small groups), and test the site after it.
- Update WordPress core, and test again.
- 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.
$ wp core update
Success: WordPress is up to date.
$ wp plugin update –all
Success: Plugin already updated.
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |