You’ve got your WordPress blog up & running, but now you need a backup in the event of a hardware failure, security breach, or something else unexpected. You don’t have a process in place for your backups just yet, but you need to do a manual backup in the mean-time.
Is this you? If so, read on.
Before we get started with our backup, you’ll need the following:
- Command-line/terminal access to your server
- Read & write access to the WordPress directory
- Sufficient disk space for your backup
- Database credentials for your WordPress database
- Have mysqldump installed
Step 1 : Prepare A Folder For Your Backup
First, we’ll change in to our directory where we want to keep the backup. For the sake of simplicity, we’ll use our home directory. We’ll then create a folder called backup/ , and within that directory we’ll create a files/ & a database/ directory. To achieve this, execute the following commands
Step 2 : Back Up Your WordPress Files
Now, we’ll copy the WordPress files from your production server to your backup directory, where we will call it something meaningful to you. For the sake of this example, we’ll assume that your files are in /www/wordpressdomain.com/ , and we’ll assume that you’ll want to call it wordPressBackupFiles in your local backup.
cp -vR /www/wordpressdomain.com/ wordPressBackupFiles
This process copies every file recursively from /www/wordpressdomain.com/, and copies it into ~/backup/files/wordPressBackupFiles. Adding the -v option enables verbose output, so you can watch the files get copied over in real time.
Step 3 : Back Up Your WordPress Database
Now that we’ve got your WordPress files backed up, now we’ll need to back up the WordPress database. The easiest, most portable way to achieve this is by dumping the contents of the database into a text file.
For this example, we’ll use the following for our credentials
- Database Host : database.wordpressdomain.com
- Database User : dbUser1
- Database Password : 123password123
- Database to back up : wordPressDB
- Output file name : wordPressDB.sql
mysqldump -h database.wordpressdomain.com -u dbUser1 -B wordPressDB -p'123password123' > wordPressDB.sql
Step 4 : Compress The Backup
Now that we’ve got all of the files we want in our backup in the backup/ directory, now we’ll compress the files into a nicely compressed .bzip file.
tar cfvj backup.tar.bz2 backup/
Now, your files have been compressed into the file backup.tar.bz2 in your home directory.
Step 5 : Delete Your Temporary Files
We don’t need the temporary files any longer, so now we’ll just delete them.
rm -rf backup/
Congratulations – your backup is now complete.
Next Steps : Automating Your Backups
Now that you’ve done your manual backup, you’ll want to automate this process to create a daily backup. Daily backups may seem excessive, but they’re typically pretty small & can come in handy if you need to get your production environment back online in a timely fashion.
Next Steps : Remote Backups
Keeping your backups on your production machine are pretty easy, but it won’t do you any good if your production machine was compromised, had a hardware failure, or cannot be reached.
Keeping backups in a remote location is the ideal in the event that this happens. With a remote backup, restore your production environment on a new machine even if your existing production environment goes down.
A few of the more popular services you can use for your remote backups are:
And remember, it’ll take some effort to get automated backups delivering to a third party service, but it can save your neck some day. Invest the time to get this set up & you won’t regret it.