Category: Proverbs 19:25

  • backUpMySQL.pl – is it cool?

    Originally published on April 29, 2003, I’ve made some formatting corrections & bumped this up a bit.

    Yesterday, Mark Pilgrim’s message of the day was
    You know what’s cool? Backups.

    Well who am I to argue with such coolness? So in the spirit of “what is Hip“, and myself being in a situation where my host is also changing data centers, I would like to share with you a little utility script I run on my system every night ubiquitously entitled “backupMySQL.pl.”

    Basically this little Perl takes advantage of naming conventions used by the standard-fare Apache configuration many of us enjoy. That is, our accounts are usually stored in directories such as “/home/USERNAME” and our database are prefixed with our USERNAME, such as USERNAME_mt. Moreover, a properly configured system will allow you to securely house and run such scripts BELOW the public /public_html &/or /www directory where all your public stuff is published.

    With this configuration in mind, I FTP this script in ASCII mode to my root directory (below HTTP access), a chmod -755 so it would execute. I then created a subdictory entitled /dbs and chmod -755 /dbs so my script can access it. I then went to my control panel and cron’d the job to run every night. Okay, so I lied, I did this all from the command line, but as you can see, you can implement this script without having to bash yourself silly.

    One other optional feature I have in this script is the ability to FTP my backup to a friend who hosts a website on an entirely different server and service. I reciprocate in kind for him. What this does is insures that we have an “off site” backup — based on the principle that if both our servers go down, then we’ve got a much larger issue at hand (how about global thermonuclear war?). So here it is. Use it, tweak it, let me know ho you like it — just make sure to check the files from time to time to make sure your backups can be restored.

    #!/usr/bin/perl -w
    # ———————————————————————–
    # copyright Dean Peters © 2003 – all rights reserved
    # http://www.HealYourChurchWebSite.org
    # ———————————————————————–
    #
    # * Obligatory Legal Stuff *
    #
    # backupmysql.pl is free software. You can redistribute and modify it
    # freely without any consent of the developer, Dean Peters, if and
    # only if the following conditions are met:
    #
    # (a) The copyright info and links in the headers remains intact.
    # (b) The purpose of distribution or modification is non-commercial.
    #
    # Commercial distribution of this product without a written
    # permission from Dean Peters is strictly prohibited.
    # This script is provided on an as-is basis, without any warranty.
    # The author does not take any responsibility for any damage or
    # loss of data that may occur from use of this script.
    #
    # You may refer to our general terms & conditions for clarification:
    # http://www.healyourchurchwebsite.com/archives/000002.shtml
    # For more info. about this code, please refer to the following article:
    # http://www.healyourchurchwebsite.com/archives/000802.shtml
    #
    # * Technical Notes and ASSUMPTIONS (PLEASE READ) *
    #
    # this code assumes a standard Apache configuration where
    # the $HOME directory is a path beneath public_html &/or www
    # and employs a naming scheme such as /home/YOURACCOUNTNAME/…
    #
    # it also assumes that your databases are prefixed with your
    # account name, such as YOURACCOUNTNAME_mt
    #
    # do NOT under any circumstances run this from a directory accessible
    # via HTTP (e.g. public_html/… or www/…)
    # it makes system calls, and although it takes no input, just don’t!
    #
    # this program works best with CRON, e.g.
    # 0 0 * * * /home/YOURACCOUNTNAME/backupmysql.pl
    #
    use DBI;
    use Net::FTP;
    
    # this assumes you have previous created a subdirectory named /dbs
    # and have chmod 777 /dbs
    $path = “/home/$username/dbs/”;
    $file = “/home/$username/dbs.tar.gz”;
    
    # databse connection info …
    $host = “localhost”;
    $username = “YOURACCOUNTNAME”;
    $password = “YOURPASSWORD”;
    
    # connect to the database and retrieve a tuple of your databases
    $dbh = DBI->connect(“DBI:mysql:host=$host”,$username,$password) or die “Bad login info”;
    $sth = $dbh->prepare(“show databases like \’$username\_%\'”);
    $sth->execute();
    
    # for each database … back it up!
    while(@row = $sth->fetchrow_array()) {
    	if(!$row[0]) { die “No dbs to backup!”; }
    	foreach $db (@row) {
    		system(“mysqldump –opt –user=$username –password=$password $db > /home/$username/dbs/$db\.sql”);
    	}
    }
    
    # you’re done with the database
    $sth->finish();
    $dbh->disconnect();
    
    # delete the old version — probably should “grandfather it”
    if(-e $file) { unlink $file; }
    
    # create a single, easy to use and transport file
    system(“tar -cf dbs.tar dbs”);
    system(“gzip dbs.tar”);
    system(“rm $path\$username_*”)	if $path =~ m/home\/$username/;
    
    #
    # OPTIONAL – you can comment this out, or not
    # this assumes you have a friend on a different server
    # with whom you’ve made arrangements to hold backups of each
    # other’s data. This way, if a server fails, you can get it
    # from your friend’s site
    #
    # it also assumes your friend has created a directory for
    # you entitled “/backup” — this of course can be changed
    # if your friend sets up an individual FTP account to a directory
    # … which is what I actually do … I love my friends!
    #
    $ftp = Net::FTP->new(“MYFRIENDSDOMAIN.COM”, Debug => 0);
    if($ftp->login(“FTPUSERNAME”,’FTPPASSWORD’)) {
      $ftp->binary();
      $ftp->cwd(“/backup”);
      $ftp->put(“dbs.tar.gz”, $username.”_dbs.tar.gz”);
      $ftp->quit;
    }
    
    # bye bye
    exit;
    
  • Politically active on your church website? Kiss your tax exemption goodbye!

    In case you didn’t know, since 1954 there has been a federal ban on political activity for tax exempt, 501(c)(3) organizations such as charities and churches.

    A lesson Atlah World Ministries may be learning the hard way when this past February, pastor James David Manning stood in the pulpit of his little church on 123rd Street in Harlem and denounced Senator Barack Obama as a … well it doesn’t matter.

    What matters is that said event soon afterward went viral on YouTube. The result, according to the NY Times, was a formal complaint to the IRS by a watchdog group focused on 501(c)(3) violating rules regarding political activity.

    Another example on the other end of the ideological aisle was a case concerning the United Church of Christ (UCC) . Back in 2006 they invited then Senator Barack Obama to its annual Synod in Hartford Connecticut in 2007.  And despite the Synod making it clear that this shouldn’t be a campaign event – it none-the-less it got politicized  – inspiring yet another investigation by the IRS.

    There are other such stories, but my point here is not to aggregate such instances, but rather to remind congregational leaders,  web masters, and even Sunday school teachers that they need to take a moment and make sure everyone is aware of the July 28, 2008 memorandum from the Director, Exempt Organizations Examinations, describing how the IRS will analyze political campaign activity issues involving websites of section 501(c)(3) organizations.

    In it you’ll see that it’s not just overt acts like the reckless and financially suicidal ‘die by the sword‘ Pulpit Initiative launched by the Alliance Defense Fund, but things that can occur in the normal operation of your church and/or charity website such as:

    • podcasting a sermon that favors a candidate
    • posting a Sunday school lesson that opposes a candidate
    • distributing emails that props up one candidate over another
    • links to another website that endorses a candidate
    • fails to monitor a link that subsequently endorses a candidate

    At least that’s this layperson’s, non-legal, untrained understanding of the IRS Tax Guide for Churches and Religious Organizations and what they communicate on their websites.

    That said, and with my likely ignorance of some aspect of the law in mind, I’ll list below some links to sites that seem smarter than me on this tricky topic:

    And from the blogosphere … these thoughts:

    Remember, regardless of your political leanings, violating this ban may result in denial or revocation of your organization’s tax-exempt status and the imposition of an excise tax on the amount of money spent on the activity …

    … that and the loss of the many freebies and discounts your church currently enjoys with its 501(c)(3) status (think Google Apps for starts).

  • Religion is a ‘Chruch’

    We all know know at least one atheist, agnostic or skeptic who boldly (and often blindly) asserts religion is a crutch. Much in part due to the overbearing legalism and spiritual abuse that goes on in a minority of cases.

    That said, I it is my prayer that the Church on the whole prove these individuals wrong, not only with Christian love and charity, but also with correctly spelled <title> tags. Case in point, the ‘North Shore Baptist Chruch‘ of BaySide NY – which is just one of the 4,410 hits Google returned to me when I searched on the phrase “baptist chruch.”
    click here to see larger image of North Shore Baptist Chruch screenshot

    Yes, as a dyslexic, I completely understand how this can happen … yet I implore you … please, please, please, double and triple check your “chruch’s” <title> tags … you’ll be glad you did.

    (update – see related article entitled: Again with the “Religion is a ‘Chruch’”)

  • The Perfect 404

    Fatigue, typing too fast, dyslexia, crumbs in the keyboard and bad handwriting are just some of the causes that come to mind that might put your users on the wrong end of a 404 page. I’ve even known a case or two where a typo or programming error on my part has caused a user to bump up against the often ubiquitous “This page cannot be found” error.

    In other words, mistakes happen, so anticipate them and give your users a graceful way of recovering from them.

    At least that’s what I’m preaching … and will practice once I get back in town on my beefy DSL line at home. Until then, I’d like to direct your attention to a thorough article on the topic by the good people at A List Apart entitled “The Perfect 404” (hat tip to Gadetopia)

    There they explain how and why it is important to not make your users feel like idiots. They also go onto explain some things you can do to help keep your users from wandering in the wilderness. Some of these points include:

    • A link to the site map (if you have one) and the home page.
    • A search box
    • A distinctly minimalist look

    Along with these excellent suggestions, I’d suggest showing the users what page they actually typed in. If it’s a typo, they’ll see it and correct it. If it isn’t, then provide them a means of forwarding that information to your church or charity’s webmaster.

    Why bother? Because users can get frustrated and leave when they don’t find what they want when they want it. Offering them some grace, along with a graceful recovery will go a long way to inviting and encouraging them to stay.

  • Using Wget to download large distributions

    It’s 11:59pm, I’m slouched in front of my computer thinking about a topic for tomorrow while in the background, I’ve initiated the all-night download of the most recent version of Knoppix, all 700 megabytes of it. Hey, if the Senate can stay up spinning their wheels, so can my computer? Provided that the high winds here near D.C. don’t blow down my DSL connection …

    … hey wait … Congress is up all night talking … high winds here in Rockville … Canadian cold front my eye! … but I digress ..

    Anyway, with the weekend upon us, I thought that those of you looking to download and burninate the latest and greatest distro of Fedora, OpenOffice or some other Linux-based fun, might not be aware that you can use Wget to download large applications … even when blowhards break your connection intermittently.

    For those of you who don’t know, GNU Wget is a free software package for retrieving files using HTTP, HTTPS and FTP. It is a non-interactive commandline tool, so it may easily be called from scripts, cron jobs and in my case, a batch file.

    By using this Wget with the –continue command to resume getting a partially-downloaded file after getting disconnected, in combination with the –no-clobber directive not to delete existing files … like the partially-downloaded I’ve been downloading all night … I can begin a download at 8pm, and then wake-up at 8am without worrying about disconnections during the time in between.

    Below is an example of this in the form of a batch file I created on my Win2k machine to download Knoppix … a script that could just as easily be implemented in bash (just ignore the linewrap):

    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso
    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso.md5
    wget -nc -c http://mirror.csit.fsu.edu/knoppix/KNOPPIX_V3.3-2003-11-03-EN.iso.md5.asc
  • A quick look inside my installation bag of tricks

    When a plumber visits your house, they often bring with them a part canvas, part leather bag that weighs in and about 50lbs. I know this because my brother is a plumber, and I’ve had ample opportunity to look inside at all the unusual looking tools he carries with him. I also noticed recently that he’s somewhat particular in how he puts the tools back in … not one can neatly align them in such a bag, but he has three or four well-worn tools he puts in last. This is because these are often the tools he uses first.

    So if you were to look into my virtual ‘what dean uses to install applications’ toolbag, what might you see along the top? Glad you asked: putty, wget,tar, pico, mysql … usually in that order.

    Now I believe I’ve discussed each of these tools (as you can see from the above hyperlinks!-), but don’t think I’ve really ever put it all together to show you what I do to install an application directly onto my web server. Nor do I think I’ve completely explained why I prefer the direct approach.

    On the latter, nothing is more frustrating than downloading a file locally, expanding/uncompressing it, editing various files, FTPing it to your web host, only to find that it doesn’t work due to a file or directory that was either uploaded binary when it should have been uploaded ASCII … or requires an additional step of changing the errant item’s file permissions.

    Instead, I avoid this hassle by using putty to login to my web server, and from the shell, execute some variant of the following commands

    cd $HOME
    wget http://www.foo.org/downloads/foo.tar.gz
    cd $HOME/tmp
    tar -zxvf $HOME/foo.tar.gz
    cd $HOME/www
    mv $HOME/tmp/foo-version2.0.1 foo
    cd foo
    pico config.php
    mysql -uUSERNAME -pPASSWORD mydbNAME < foo.sql

    Now of course, each installation is going to be a little different, for example, you can see that I throw mkdir and chmod into the mix in a past article I wrote entitled “Moving MovableType.

    That said (and finally to the ‘former’) the above boilerplate also provides some other unseen advantages. First, you don’t have to have to download the file locally. This is good because it also means you don’t kill bandwidth FTPing each file. This is good because you don’t have to worry about uploading the file in the wrong mode … and you install the files using the permissions defined by the developer.

    As always, your mileage may vary … especially in those one or two cases where the individual making the .tar.gz file doesn’t put stuff into it’s own directory … which explains why I put everything in $HOME/tmp first …

  • Host File Configuration Fun

    I realize I’ve been a bit ‘preachy’ the past couple of days, so let me make that up to you by offering something very ‘geeky.’

    If you’re like me, you prefer to develop software outside of the production environment. Okay, now to translate that last sentence into English for those of you who are not fluent in ancient geek:

    Those of us who program for a living rarely, if ever, perform any major software surgery on live/active website. Instead, we keep a copy of the website, either in a subdirectory on the same web server, or if you are an ‘uber-nerd,’ on a web server you have running in your house (or in the basement of your church) .

    Running a web server at home (or in the church basement) for development isn’t all that hard, but setting one up is a topic for a later discussion. Today, I want to talk about how to play some domain games to trick your routers and computers so instead of having to address your site like this:

    http://192.168.1.120/index.php

    You can instead address it like this:

    http://foobar/index.php

    Notice, I didn’t enter the URL foobar.com, but just foobar. There a variety reasons for this. First, I really don’t want to spend $8.95 per year to register a test domain for each domain I’m developing. Second, I’m running my Linux/Apache server on an old Pentium II, so excluding the overhead of a DNS daemon gives my tired old machine a bit of a break. Third, unless someone hacks past the Zone-Alarm enhanced firewall on my LinkSys router, there’s a slim-to-none chance that anyone else entering http://foobar/ on their machine is going to see my test site on my intranet.

    To do this, it means modifying a file named “hosts” on both my Windows and Linux systems. Here is how mine is configured (almost, the IPs have been changed to protect the innocent). Here is the how the file c:\winnt\system32\drivers\etc\hosts is configured on my Windows 2000 box:

    127.0.0.1     localhost
    192.168.1.120     foobar

    Here is how the file /etc/hosts looks on my Linux box (and please note, though I use spaces in this article to delimit the columns, you should use tabs):

    127.0.0.1     foobar     localhost.localdomain     localhost

    There are some drawbacks to this approach. First, my Linux configuration assumes I’m working on only one project. If I wanted to work on multiple projects, I would have to configure the Apache system for multiple virtual domains (a.k.a. virtual hosts), each with it’s own IP. In that case, the /etc/hosts file might look like this:

    127.0.0.1     localhost.localdomain     localhost
    192.168.1.120     foobar
    192.168.1.121     blog4god
    192.168.1.122     healed

    The file c:\winnt\system32\drivers\etc\hosts would look essentially the same. Which leads me to another drawback, unlike a DNS server that automagically maps these tables for you, you’ll need to keep both hosts files in sync some how – or should I say, rsync (t the reader understand)? Also, if you’re still using Windows 95, 98 or ME, you’ll have to remember that the hosts file is in the c:\windows\host directory, and that Windows XP may be configured so that hosts can be found the directory c:\windows\system32\drivers\etc\.

    Another thing you need to remember is that if you haven’t installed some form of web server on your Windows system, then it is more than likely that hosts is actually residing on your system as hosts.sam. This means you need to remove the .sam extension to get things to work.

    For you non-BDS Mac users, I believe (and I could be wrong) the hosts file can be found in either the system or the system/preferences filter, and if not, and someone PLEASE correct me if I’m wrong, you simply open up your text editor and create one with the following entries:

    127.0.0.1     A     localhost
    192.168.1.120     A    foobar

    I know the above sounds like a lot of work, but honestly, it took me all of 10 seconds to get it done at home. Once done, this allows me to work on a localized copy of MovableType, Drupal or any other tool/toy to work out formats and kinks before they go live. That is, once I go through the ‘heck’ of installing MySQL, php, Perl, and any of other libraries and schtuff required to get a particular app. up and running.

    One thing you should note, this approach also works for those of you running an IIS web server at home (on in the church basement) as a development server — and for those of you running a web server on your PC on which you develop — though my preference is always to set it all up an old computer just in case it does get hacked and wacked.

    Disclaimer – as always, before you try stuff like this, backup your files, write down your configurations and remember – your mileage may vary (esp. if your router is different than mine).

  • ESV Bible RSS Feed using PHP

    As promised, the ESV Bible RSS Feed, now peachy PHP flavor! To get this done, I dipped back into two past articles. One entitled Using PHP from the command line. This is necessary as we want to add our application to the CRONTAB. For those of you new to this site, and for those of you who are not fluent in classical geek, CRON is the scheduling process associated with various flavors of *NIX, such as Linux. The CRONTAB is the table where jobs are enumerated and defined. Here is a past article of mine which points to some effective CRON tutorials you might find useful.

    The other tool we need is an effective way of slicing-n-dicing RSS files. As I stated in yesterday’s article, RSS is an XML file designed to talk to computer programs via the HTTP protocol. This means once we obtain the ESV RSS feed, we need to extract the data so we can render it in a human-friendly format. To do this, I’m going to again dip back into a past article and employ a wonderful little PHP library known as MagpieRSS.

    In about ten minutes, I had a working code that read the ESV Bible RSS Feed, extracted the good stuff, and then created an include file I could … well include in my web pages using pretty much the same techniques I stated in my article Similar in concept to “Using Cron with LWP::Simple and XML::RSS to retrieve news feeds.” You’ll also note that this program bails without creating content if it finds no data elements. And if it does, it takes care of some of the “whitespace” issues I mentioned in yesterday’s post.

    Yeah, I know, alot of repeating myself going on. It comes from fathering a strong-willed 3.5 year old. I’ll stop that now and give you what you really came here for, the code. Feel free to use it and improve it. But if you do the later, then please, com’n back and share a comment so the rest of us can benefit from it.



    BTW, since everyone loves a happy ending, I figured I’d let you know that I did finally hear from the good folks at Good News Publishers. A very nice note that’s going to lead into some very cool code in the not too distant future. Part of the communications issue was a DDoS attack on my side, and Glenn Slaven being 12 hours ahead of me. Now if Glenn would only tell me if the Oriole’s are going to win tonight, I’d be set.

    Stay tuned. Leave comments. Let me know if the above works for you. Share improvements. Enjoy the day. I know I wil!-)