WordPress backup from CLI within a minute

All WordPress owners are struggling with WordPress platform updates or new plugin releases. And only really brave one deals with it without making a full backup of files and wordpress database.

I’m not one of them and also I have a bare CLI interface. So all the magic with CPanel, phpMyAdmin or other ways described in official WordPress backup instruction don’t work for me.
But it becomes even more easy when done manually.


Backup blog’s directory with all files preserving permissions and ownership:

$ cp -Rp dev-aux.com/ dev-aux.com.bac



Then backup you database:
Not sure that everyone keeps their database connection params in memory, so let’s retrieve them from blog’s wp-config.php file

$ cat dev-aux.com/wp-config.php
# and search for
define('DB_NAME', 'blog_db');
define('DB_USER', 'blog_db_user');
define('DB_PASSWORD', 'blog_pass');
# most likely is set to localhost
define('DB_HOST', 'localhost');

MySQL database is the most common choice when installing WordPress but not the only one.

If you have different DB – simply choose another utility for backup, but the previous step with determining connection params would stay the same.

For MySQL pass this params in mysqldump utility:

$ mysqldump -h localhost -u blog_db_user blog_db > blog_db.dump.2020.05.05.sql
Enter password: 
...

Don’t forget to copy your backup to another server or local machine.
Just in case.

Wish you a smooth update.

Leave a Reply

Your email address will not be published. Required fields are marked *