If you’re a frequent blogger/writer you’ll know how valuable in terms of time and effort your articles are, especially if you’re writing isn’t earning you a living. What protection do you have though for your long coffee drinking sessions of inspiration?
Well, you have this somewhat illusive process called backing up. Unfortunately this relatively pain-free process is often overlooked. In this article I’ll show you how you can keep piece of mind by backing up your WordPress (WP) blog – saving you days and hours of torment when that horrible day comes and your site gets erased from the face of the WWW (this can also be applied to many other blogging systems and database driven sites so don’t run away just yet if you’re not using WordPress).
What’s going to get backed up
- The WordPress database
- A WordPress XML file (details on this later)
- Remote WordPress Core files
- Local WordPress Core files
Set up a folder structure
You need to be organised on your local machine before we do anything. Dedicate a backup folder for each of your websites and create folders inside this that indicate the date and type of backup. By type, I mean local or remote backups. I’d advise remote and local copies just incase there any differences in the WP installation. This may include any updates to plugins or similar updates done with your browser.
First, backup your database
Right, I’m going to say it, brace yourselves, SQL. Yes, the best type of backup you can possibly do is to export your WordPress database to an SQL file.
Depending on your hosting company, you should have access to cPanel or phpMyAdmin at the least, so we’ll use phpMyAdmin for this. Open phpMyAdmin and select Export from the top menu.
You should now see the Export options. First, choose the database you want to export, in my case ‘nouvelle_worpdress’. Next, select the export file type, choose SQL. Make sure you tick the ‘Save as file’ option and choose either ‘zipped’ or ‘gzipped’. Then hit go!
You should now be downloading a zipped up SQL file. Once downloaded, place it in your remote backup folder for the current day. That’s your entire WP database backed up, simples?
WP has an in-built tool for exporting your posts, pages, comments, custom fields, categories, and tags. Though you shouldn’t rely on this method as your main backup, it’s still best to get your XML fix. Log into your WP admin area and select ‘Tools’, then ‘Export’.
All you need to do now is to select which authors you want to export (I recommend exporting all the authors each time) and hit ‘Download Export File’. This will give you an XML file which you should place in the same folder as the SQL file.
WordPress’s core files
You should have an up-to-date copy of your entire site (WP installation) on your local machine, cut this from the current folder and place it into the local backup folder for the current day. Now re-download from your FTP server what you just cut from your local files and copy it into your remote backup folder for the current day.
You should now have a local copy of your of:
- Remote SQL file
- Remote XML file
- Remote WP Core files
- Local WP Core files
Once you have all these files you should then backup your information to an external HDD or use a system similar to Time Machine. Your backup should now be complete!
How often should I back up?
Well, this purely depends on how much and how often your write. Usually a week’s backup will suffice but if you do any larger changes then a backup on that day wouldn’t go a miss.
Programs like Time Machine will help to keep your local backups up-to-date by the hour if needed but remember, you’ll still have to monitor your remote backups too.
Automation? Cron jobs, at your service
If you don’t want to keep going into phpMyAdmin to export your database to SQL every time you can use something called a ‘Cron Job’ to do the hard work for you. Cron jobs are simply pieces of scripts that are executed by your server at a given time. These are normally handled in the cPanel (or similar) interface (You can find them under ‘Advanced Tools’).
There are many ways you can configure each job so I’ll just show one method for now. Go into the ‘Cron Job’s section and choose ‘Advanced (Unix Style)’ and paste in the below code into the ‘Command Line’. This will export your database to an SQL file in the specified directory, make sure you’ve replaced the capital letters in the code with your information.
You will also need to specify a date for this function to occur. In this case I’ve used
1 1 * * 1 which will export my database on the first minute, of the first hour on the first day of each week. Then I simply download it from my FTP.
mysqldump -uUSER_NAME -pPASSWORD DATABASE_NAME > /home/username/www/path_to_backup/localhost.sql
I hope you found some of the processes helpful to backup your blogs and if you have any questions please leave a comment. If you have any backup methods of your own, let us know!