Backup Your WordPress Site (Manually)

!
Warning: This post is over 365 days old. The information may be out of date.

TL;DR – don’t use automated solutions. Do it properly and do it manually!

Create a temporary directory to work in:

mkdir backup-20200105
cd backup-20200105

Time to dump the MySQL database! It’s not that hard.

Quick note before you run this – this is assuming your MySQL installation authenticates via UNIX sockets. If you have password authentication I suggest moving away from it if your MySQL database is on the same server as your WordPress site. Less chance of things getting messed up and you don’t have to remember yet another root password that could be leaked.

sudo mysqldump --add-drop-table -u root wordpress > database.sql

If it prompts you for your sudo password, supply it. If it prompts you for your MySQL password, then you’ve done something wrong.

Now you need to copy the static files and what not. Run:

cp -a /var/www/example.com ./

The -a flag tells the cp program to copy over all attributes. It doesn’t always work, however. In my case it rewrote the www-data user to ericswpark. Nothing a simple chown can fix, though!

Time to tarball the entire thing. Back out and then run:

tar -czvf backup-20200105.tar.gz backup-20200105/

You’ll get a neat tarball you can throw on Google Drive or something like that! Wasn’t that easy?

Restoration

Get the tarball and unpack it:

tar -xzvf backup-20200105.tar.gz

Go inside, and then run:

sudo mysql -u root wordpress < database.sql
cp -a example.com /var/www/

Restore permissions if required. Done!

Related Posts

comments