Category: How-To

  • Craigslist Down proves the need to plan for failure

    What does the PG&E induced craigslist outage have to do with your church or charity website? How about a reminder of the tired but true adage that reads ‘Those who fail to plan, plan to fail.’ Specifically using mysqldump, crontab and perhaps ftp or rsync to insure you’re data isn’t dead in the water when your host goes down.

    • One of the big advantages of running a web services company out of the San Francisco area is that you’re located where the majority of action is – at least in the U.S.
    • One of the big disadvantages of running a web services company out of the San Francisco area is that when the Bay area takes a power hit – you’re down with the best of them.

    This power-packed paragraph from the Boston Herald exemplifies the scope of the situation:

    Cool black light, or dim bulb? You decide with your plan of attackAT&T Park, home of the Giants, was also affected hours before a scheduled night game. Six Apart Inc., a blog-hosting service, said its sites began failing shortly before 2 p.m., and the company sent an e-mail to customers blaming the city’s “power issues.” Several other Internet sites with San Francisco offices had problems, including Craigslist, Technorati, Yelp, Red Envelope and CNet. It was unclear whether the problems were related to the outage.

    Now while I suspect the ‘big guys’ have contingency plans to quickly relocate had this been a long-term failure, I also speculate that your church and/or charity’s emergency plans may not be so robust as to handle something such as a hosting provider that goes belly-up due to either natural and/or financial disasters.

    That said, there are some no-cost, low-bandwidth solutions are already available to those of you opting to manage your site’s content on a LAMP platform using an application such as WordPress or Drupal.

    Here’s all you need to cook-up your own recipe for success:

    • putty for shell access to your website/host
    • access to the mysqldump command
    • optional access to the gzip command
    • your database username
    • your database password
    • your database server name
    • optional access to the crontab utility

    So if nothing else, with the above you could set up a nightly job that backs up and then gzips your database all in one fell swoop:

    $ mysqldump -uMYSQLUSERNAME -h localhost -pMYSQLPASSWD wp_MYDB | gzip -9 > wp_MYDB-db.sql.gz

    This approach is of course not without its downside, specifically:

    • you could be potentially overwriting a good backup with a corrupted data backup
    • you still have your backup on a server that could go down
    • you have no real report as to the validity of the backup

    Instead, it’s probably advisable to create a script and/or perhaps write a PERL program to enhance this process to:

    1. first grandfather the last good archive backup
    2. then archive the last good backup
    3. then add a date stamp to the file
    4. then make a copy of a successful backup to another location
    5. finally, email you and/or log the results

    But who as time to write a script you ask? Well, fear not, one of the reasons I’ve filed this article under ‘resource filled’ is because I found a wonderful little service entitled: the FTP backup script generator.

    You simply enter the parameters, it generates a script that you then copy and paste onto your system – then crontab to run on a nightly basis.

    And if that doesn’t float your boat, here are a few other articles on the topic of how to use crontab, MySql and FTP or rSync to keep your data safe and sound now matter how badly the power fluctuates about your backup-savvy server.

    • NixCraft – How to backup MySQL databases, web server files to a FTP server automatically
    • How to have automatic backups of your mySQL database – ThemeBot
    • How To Forge: Create Incremental Snapshot-style Backups With rSync And SSH
    • MySQL backups using mysqldump by CrazyToon
    • Peter’s Blog: rSync articles by tag
    • Automated Backups on Tiger Using rsync – O’Reilly MacDev Center
    • VoorBurg: Backup script for Linux using tar and find
    • How to backup your MySQL tables and data every night using a bash script and cron – CGI Interactive
    • Old Guy’s Scripts: MySqlDump database backup script

    I know we’re all busy, and I said, this approach is a mere pittance in light of true disaster recovery. That said, it is up to make sure you have at least taken the above precautions … and from there add more points and detail … for as it is written (with apologies to the inspirational text of Romans 10):

    How can they restore the data without knowing how?
    And how can they know how without having practiced?
    And how can they practice without someone teaching them?
    And how can someone teach without documentation?
    As it is written, “How beautiful are the webmasters who have planned ahead!”

  • Blocking bad bots without mod_rewrite

    “The Apache URL Rewriting Engine seems to grow more popular for each year. It certainly is a powerful, handy, and cool tool … But using mod_rewrite is difficult for non-programmers and the syntax is rather cryptic even for programmers. That means it’s easy to make mistakes and if used extensively the resulting mess of rewrite recipes can be hard to maintain.”

    Can I hear an Amen to the quote above from the Scatter/Gather thoughts blog?

    Yes, I know for some of you that was like a sermon in Greek – but what Johan Petersson is writing about is a way to stop spambots, and stop image thiefs from consuming your bandwidth without having to go all mod_rewrite about it.

    mod_rewrite, for those of you who don’t speak pure geek, is a rewrite engine that has been described as “the Swiss Army knife of URL manipulation” … meaning a way of taking an incoming URL request and redirecting towards/at something else … or in the case of a spambot, sending it straight to h-e-double-tooth-picks!

    Problem with that way is that it is not accessible to most on/in a shared hosting situation as it requires working at the operating system level.

    The simpler alternative? Manipulating the usually accessible .htaccess file so you can deny access to image thiefs and re-direct other nere-do-wells to the target spam poison website of your choice.

    Anyway, I’d suggest going over to said article and learning some of the nifty and not-as-hard as mod_rewrite techniques Johan has illustrated in some simple snippets.

    And I promise, next post won’t be so geeky that only 3 or 4 of is get the abundant utility the cited article suggests

  • RSS in Plain English – a how-to video by Turtle Interactive

    Tim Bednar over at Turtle Interacvie writes:

    “There are two types of Internet users, those that use RSS and those that don’t.”

    I’ve been saying this for years … which is why Tim has graciously produced a wonderful weekend video to instruct those wandering in the syndication wilderness how they can save time, lose 20 pounds, take 4 inches off their waist and look 10 years younger using RSS.

    Well okay, I exaggerated, so I’ll let Tim’s words describe what the real deal is:

    This video is for the people who could save time using RSS, but don’t know where to start.”

    Still, I coulda used the 10 years younger thing. Perhaps the next video? Either way, once you’ve been a hearer of Tim’s words, I’d suggest be a doer and add his feed to your aggregator. I know I am!

  • How to cron a MySQLDump

    Once again Rachael C. not only yanks the plank outta my eye, but smacks me upside the head for not scripting my backups on a regular basis. And she’s right to do so.

    Here is a link she recommended in a comment in my “make a ready defense” article The recommended tutorial is appropriately entitled How to backup your MySQL tables and data every night using a bash script and cron.

    Of course, this steals my thunder as I was, and still am, going to give you some PERL that will enumerate all your databases, then dump them, then compress them into a tidy little file good for downloading and such.

    But until I do, do what this article says, and not what I’m not doing.