We get caught up trying to get something to work, that we forget to back it up.
I’ve done it, and still do it…until something happens and I’m kicking myself in the pants for not mitigating it from happening.
There is no wrong way of implementing backups. The best way to know if it works for you is to practice restoring your backup regularly.
Why do you want to backup your wordpress website?
Your reasons may vary. The most common two that I’ve been prepared for is the following:
File corruption. This can happen different ways. Maybe the file system had a bad disk and causing some errors. A downloaded plugin gets corrupted after updating. A database drops the table for no reason at all!
Site migration. The easiest way to migrate a site is to take a backup and restore it to your new hosting provider. Simple and effective.
There are two important componants to backing up your wordpress website. The first is the wp-content folder. This folder containsall your themes, plugins, and uploads. Don’t worry about any other folders that get generated during the wordpress install or provided by the hosting provider. The second important componant is the database. This is everything! It has your content, your html, your design, and all your settings.
Back up /wp-content!
I personally like to use wget with ftp access to the site. The following command will download everything in your wp-content.
localhost# cd /backups/wp-content/date20230101/
localhost# wget -m --user="[email protected]" --ask-password --ftps-implicit ftp://ftp.domain.com/wp-content
The above command changes to the directory where you want to download the files to.
We are using the wget command with -m. This is the mirror option. I found this easier that specifiying how many levels of directories to go through.
Verify with your hosting provider how to ftp to your site. You will need it to specify the user name in this command, the URL, and if it requires any kind of additional additions like the ftps-implicit. This will avoid downloading your username credentials getting captured in plaintext.
Back up your database!
You can do this a number of ways. I will give you an example using a simple command. You will need ssh access to connect to.
localhost# ssh [email protected]
db# mysqldump -u username -p dataBaseName > ~/backup.sql
db# exit
localhost# scp [email protected]:~/backup.sql ~/backupdate20230101.sql
if you are missing your database name or unsure what it is. The easiest way is to look in your wp-config.php file.
I hope this was useful to you.