Quantcast
Channel: Cranky Bit » Open Source
Viewing all articles
Browse latest Browse all 19

The Mysterious Vanishing WordPress Posts

$
0
0

Three of my recent posts from August 2006 have been mysteriously cut off at the knees (two articles about SELinux and one article about Apple releasing the Mac Pro). The first opening sentences remained, but then mid-sentence at a variant length, the article body was truncated. One of the posts was particularly lengthy, and naturally I didn't have a backup of the article in any fashion. That is extremely disappointing.

To prevent the lamentable agony of this kind of loss, I could: (a) Set up a WordPress scheduled task (with plugins that provide such functionality) to backup the database on a regular basis, or (b) I could backup the database manually after I post an article. As a different approach, and the most fun because it involves programming, (c) I could set up a scheduled task on my server at home to pull the RSS feed from my site on a daily basis and save that.

My server at home is a Linux box (currently Fedora Core 4), so a quick little Linux script is the best way to go. This is exceptionally easy, so let's take a look:

fn=/backuppath/rss/nazin-`date --iso-8601=date`.xml
url=http://blog.nazin.com/index.php/feed/
curl -o $fn $url

This obviously could be a one-liner, but to dumb it down, I put the backup file path and the URL of the RSS feed in script variables. The first line says, "Make the path inside the rss directory (relative to the location the script is ran from), with a file called 'nazin-yyyy-mm-dd.rss', using today's date." If you are new to Linux scripting, anything wrapped in ` symbols will be processed and replaced with its output. So "nazin-`date --iso-8601=date`.rss" will actually become "nazin-2006-09-07.rss" if that is today's date. The second line obviously just assigns the value of the url variable. The third line is then a basic curl call. It says, "Go browse the $url and put the output in the file at $fn."

I then just set up that script to run as a scheduled Cron job, and we're in business! A quick note about the path: You can leave it as a relative path, and the script will work fine when you execute it at a shell prompt, but it may fail as a Cron job. To be safe, provide an absolute path so that it works at both places.
Don't leave backups to humans. We're too unreliable. Leave it to your server to handle. :-)


Viewing all articles
Browse latest Browse all 19

Trending Articles