
Tree Replication on Your Web Server
This is the simplest and the fastest way to backup your WordPress blog. This methodology must be used in conjunction with other options. Relying only on this option is not a wise move as all of your data is saved on the same web server where your blog is running.
securebackup
created at the following the path /var/www/
. First simple step is to take a database backup to save all the MySQL tables to this directory.Throughout this tutorial, I'm assuming, you're logged in with root privileges via SSH login.
mkdir /var/www/securebackup && cd /var/www/securebackup
Now, use the following command to backup the WordPress database in the current directory. Let's assume that our WordPress MySQL database name is wp_mysite
. Here's a generic command for the database backup.mysqldump -u [username] -p[password] -h [host] [databaseName] > [DBbackup-name].sql
For demo purposes, let's assume, your MySQL account with administrative privileges is having the username as root
and the password as secretpass
. Now, the generic command will change as follows.mysqldump -u root -psecretpass -h localhost wp_mysite > mysitebackup.sql
Note that there is no space between password and the -p
switch.The next important step is to copy the entire WordPress installation directory tree to the backup folder. This strategy has the following advantages.
The restoration process is extremely fast and there's no complexity involved to save your backup. You must copy the installation tree recursively so that it can be restored in the same way, without any hassle. Here's the command to copy and save your installation tree, recursively.
cp -r /var/www/html /var/www/securebackup
Here, we're assuming that the installation tree path is /var/www/html
. The copy command given above uses the -r
switch and instructs to copy the installation tree, recursively, to the target backup directory.This way you'll have both the database as well as entire WordPress directory tree backed up on your web server. In case your blog is affected by a malware and the infection is limited to the blog's installation directory tree, you can restore your blog very quickly.
Start by dropping (deleting) the entire WordPress MySQL database and then import it directly from the backup. Here's how to do it. Use the following command to delete the database.
mysqladmin -u root -p drop wp_mysite
After firing this command, you'll be prompted for the MySQL password. Just before deleting the target database, the command will ask for confirmation. Simply, press y
key to complete the process.Now delete the infected WordPress directory tree using the following commands. First, switch to the directory where WordPress is installed.
cd /var/www/html
And now, use the recursive deletion command as shown below.rm -rf *
At this point, both the infected WordPress directory tree and the MySQL database has been deleted. Now is the time to reinstate both the directory tree as well as the database to their original locations from the saved copies residing within the backup directory.To copy the saved directory tree back to its original location in a recursive manner, use the following command.
cp -r /var/www/securebackup /var/www/html
You can note that it's just the opposite of the first copy command fired earlier. The last step involves restoration of the database. Here's the command to be used for the same.mysql -u root -psecretpass wp_mysite < mysitebackup.sql
And, that's it! This backup and restoration process is simple and easy-to-use. Usually, this method can help you recover your blog within minutes unless the archive is extremely huge.Caution: Never ever overwrite the infected directory tree as it may leave some extra infected files intact even after copying the backup tree.
The correct method is to first completely delete the entire infected tree (recursively of course) and then copy the backup tree back to its original location. This technique only works when the infection is limited to the installation tree and the web server itself has—no problem. It will not work if the server itself is down or it is experiencing system-wide infection.Cross-Server Replication
This is yet another interesting backup strategy that's fast and reliable. This methodology requires two parties who mutually agree to provide their server space to back up each other's data. Both parties sync the data stored on the partner's remote server within their local backup directory.This way, if one of the web servers fails, the data can be easily restored from the partner's remote web server. The challenge to implement this solution is to find a trusting partner who is ready to be a part of this solution.
Because both the parties are beneficiaries, a mutual agreement may not be a big problem if both the blogging buddies are on good terms with each other.

In simple words, party A syncs and keeps a backup of party B on his own server and party B syncs and keeps a backup of party A on his own server. It's a win-win situation for both the ends.
If you don't know how to create a zipped archive for the entire installation tree, here's a simple command to do that. Make sure you're in the backup directory created specifically for storing these compressed archives.
zip -r archive_`date '+%Y-%m-%d'`.zip /var/www/html/*
This command will recursively compress your WordPress installation directory tree and will pack it in a dated archive. Now, we move on to the most important step of remotely syncing the compressed archive.Remember, if you're looking to sync your data to the remote server, it's not you who will use the relevant command. It will be fired by your partner from his end to pull and sync your zipped archive on his web server and vice versa.
This essentially means that both the parties have to exchange their server login credentials to connect and fetch the archived data. Use the following rsync command to connect and sync your friend's archived data on your own web server.
rsync -e ssh -a —delete root@friendssite.com:/friends_site/backup_directory /your_site/backup_directory
While using this command, you have to supply the login credentials to complete the syncing activity. If you want to automate this process, you can use this excellent tutorial to implement automated cross-server backup syncing.Restoring a backup simply requires firing of rsync command from the original server where backup needs to be pulled. If you have a trusted blogging peer, I highly recommend using this methodology to keep a secure backup of your blog to a remote location.
The same syncing activity can be performed for zipped database archive too.