Archive

Archive for the ‘General Programming’ Category

Backing up your Database (with GoDaddy and Cron)

March 18th, 2009 10 comments

In short, this is  a guide to setting up a cron job in GoDaddy so that your databases can be backed up (and later restored). It’s generally a good idea to regularly backup your databases, whether you think you need to or not.

This guide assumes that you are using the Linux hosting of GoDaddy.

First, get familiar with mysqldump. It’s the utility we’re going to use to do the backing up. Do you have access to your sites shell? It’s that thing you get when you log into yourdomain.com through SSH. I’ll assume you’ve got access to the command line to try this yourself and if you don’t then just follow along and trust me.

I’ll paste a facsimile of the mysqldump command that I use in my account, and then explain what it does. Keep in mind, the following command is continuous, all on one line, but I’ve broken it down to fit on this page.

mysqldump
-h DBHOSTADDRESS
-u DBNAME
-pDBPASSWORD
DBNAME |
gzip >
$HOME/html/somefolder/DBNAME_`date '+%m-%d-%Y_%H-%M'`.sql.gz

I’d like to point out the workings of that “date” thing first. Simply put, that gives the backup a name like “MyDB_03-18-2009_02-15.sql.gz” which tells us that the database, MyDB, was backed up March 18, 2009 at 2:15am.

DBNAME is whatever you named the database. As we all know by now, GoDaddy shares the database name and the database username, which is why it shows up so often.

DBPASSWORD is worth noting. There is no space between the -p and the password. That is not a typo. Just keep it as -pNoSpace or it will not work (of course, use the database password in place of “NoSpace”).

DBHOSTADDRESS can be found in the GoDaddy control panel. The control panel is found at

GoDaddy.com >> Hosting >> My Hosting Account >> Manage Account >> Databases >> MySQL

Then click the “Edit/View Details” Action for the database you want. The host address can be found in the Host Name row of the MySQL Database Information.

GZIP is what zips up the backup for us. It keeps the backup small (or at least smaller than the raw backup file).

$HOME is the full path to the backup directory. You do not need to worry about the path, just keep $HOME as it is.

And now for the easy part.

Create a file and write #!/bin/bash for the first line. Then on the second line, paste in the mysqldump command for your database. Remember to change the variables in the command to suit your account and database configuration.

Now change the permission of the script you just created to be executable by you. From the command line the command is

chmod 744 WhateverTheScriptIsCalled

You could probably change the permission from within an FTP program, like FileZilla, by right clicking and changing the permission.

Next, open Cron Manager. It is located in the Control Panel under the Content tab.

Give the cron job a name and set the frequency. Next, in the command box, browse to the location of the script you just created. Select it. Save. Done.

1234567890

February 13th, 2009 No comments

Hopefully I’m within liberty to reproduce this information here.  comp.lang.perl.misc user, Jean-Luc, has this to say about a certain timestamp (as copied from my newsreader):

Hi,

  As some of you know, Unix epoch time will reach the number
1,234,567,890
today at 23:31:30 UTC.

  If you don't know, epoch time is a measure of time in number of
(non-leap) seconds since Midnight UTC on January 1, 1970.  (That means
over
a billion seconds have passed since then.)

  Nostradamus once cryptically said, "The world will end when all
numbers
are visible."  I wonder if he was talking about this epoch time stuff.
(Disclaimer:  I just made that quote up.)

  You can view the epoch time ticking away by typing the following at
any
DOS/Unix prompt (provided you have Perl installed):

     perl -le "print time and sleep 1  while 1"

(You may want to synchronize your computer's clock by going to
http://www.time.gov/ .)

  You can see the exact time of 1234567890 for your timezone by
typing:

     perl -le "print scalar localtime 1234567890"

  Have a happy 1234567890 day!

  -- Jean-Luc

Only 1 hour 25 minutes to go.

Edit:

Dan C helpfully adds (yes, credit where credit is due)

watch -n 1 date +%s

as a handy way to watch the timer tick up to the timestamp.

34 minutes left.

Mouse-following text

January 23rd, 2009 No comments

There are too many “Look at this text wiggle as it follows your mouse cursor” tutorials out there. They are outdated and who really wants to clog up their site with tacky cursor-following-wiggly-text?!

If you’re looking for static text that follows your cursor, and an easy-to-follow tutorial to show you how then look no further than this tutorial on About.com.

Google and jQuery (and others)

December 1st, 2008 No comments

I’ve spent the last 30 minutes Googling for help to use Google’s AJAX Libraries API. You know what? The solution was right there on that page.

My problem was that I could get a jQuery example to work if I loaded the API like this

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" >
	// Do whatever
</script>

but I couldn’t get the example to work if I used the recommended

<script src="http://www.google.com/jsapi"></script>
<script>
	google.load("jquery", "1.2.6");
	// Do whatever
</script>

Are you in the same boat? Short and simple, here’s the solution:

<script src="http://www.google.com/jsapi"></script>
<script>
	google.load("jquery", "1.2.6");

	google.setOnLoadCallback(function() {
		// Do whatever
	});
</script>

Yep, you’ve got to put all your jQuery code inside the google.setOnLoadCallback method. Use the following to test that it works for you.

<html>
	<head>
		<script src="http://www.google.com/jsapi"></script>
		<script>
			google.load("jquery", "1.2.6");

			google.setOnLoadCallback(function() {
				$("a").click(function(event){
					event.preventDefault();
					$(this).hide("slow");
				});
			});
		</script>
	</head>
	<body>
		<a href="http://jquery.com/">jQuery</a>
	</body>
</html>

Laconica with GoDaddy

November 20th, 2008 10 comments

I may be jumping the gun here a little bit as I’ve only successfully managed to get Laconica talking to the database and have successfully registered my user. If for some reason not everything is up and working 100% then I’ll append a note to the end of this article. In the meantime, you’re probably here because you want to know if it’s possible to get Laconica, the micro-blogging utility that is the basis for which Identi.ca is built upon, working in a GoDaddy hosting account.

Yes you can. Here’s how.

The Laconica README says that Laconica requires that it is the only process using any particular database, so go ahead and create one from your GoDaddy hosting account manager. I’ve chosen MySQL 5.x myself. It’ll take a few minutes while a (presumably) real human sets up the database and permissions for your user. When the technician is done setting up your database then it should, after a page-refresh, show “Open Manager” in the database manager screen.

There’s a particular piece of info you’ll need now, which is the address of the database (different, often-times, for each database you set up). So click the “pencil” icon in the “actions” column. If you hover over the pencil it should say “edit/view details”.

When the page opens you’re looking for the “Host Name” which is something like “pXXmysqlXXX.secureserver.net”. That’s the location of the server holding your database and you’ll need it later on. So make a note of it and let’s carry on.

The next step would be to actually have downloaded the Laconica software. A link to the latest version can usually be found on the http://laconi.ca/trac/ site. Currently it is version 0.6.2 which was released November 18 of 2008.

Download it, extract the archive (the zip, tar, etc) and then open your favorite FTP client and transfer to your webserver (or copy it over via command line FTP). Don’t expect it to work just yet. You need to edit a couple files.

First, find the laconica_0.6.2/config.php.sample wherever you extracted the archive and drop the .sample part of it. Now open up config.php in whatever text editor you prefer and change the following lines:

$config['site']['name'] = 'Just another Laconica microblog';
$config['site']['server'] = 'n3wt0n.com';
$config['site']['path'] = 'micro';

n3wt0n.com becomes whatever your URL is, but don’t include http:// or it’ll screw it up. Or do, and you’ll see for yourself. Also, change “micro” to the name of the directory that Laconica exists in on your server. If you just copied the extracted directory over then it may be called “laconica_0.6.2″ but I renamed mine to “micro”.

I also changed

#$config['site']['logfile'] = '/tmp/laconica.log';

to

$config['site']['logfile'] = 'laconica.log';

because I am hoping that the log file will be printed to the site-root (n3wt0n.com/) where I might be able to retrieve it some time, rather than the server’s /tmp/ directory where I cannot reach it. But that’s your call.

Last, but certainly not least, within the config.php file is the “db” configuration. Particular to working in a GoDaddy account, modify the following lines to suit your account.

$config['db']['database'] = 'mysql://DB_NAME:DB_PASSWORD@DB_LOCATION/DB_NAME';
$config['db']['ini_your_db_name'] = $config['db']['DB_NAME'].'/DB_NAME.ini';

Remember that with a GoDaddy account, the MySQL database username is the same as the database name. Thus “DB_NAME” is used for both. Change that to whatever you named your database. DB_LOCATION is that “pXXmysqlXXX.secureserver.net” thing we noted earlier.

Additional note:

mysql://DB_NAME:DB_PASSWORD@DB_LOCATION/DB_NAME

follows the format

mysql://username:password@serverlocation/databasename

That should cover the configuration, but there’s one more file we’ll need to change. Change the name of laconica_0.6.2/classes/laconica.ini to DB_NAME.ini (remember, DB_NAME is replaced with whatever you named your database). It should be noted that you may have to rename laconica.links.ini to DB_NAME.links.ini as well. I just haven’t played around long enough to know.

Another additional note:
Copy htaccess.sample and rename it to .htaccess
Within that file, change “RewriteBase /mublog/” to be “RewriteBase /micro/” where micro is the path to your laconica directory.

Now everything is set up for Laconica to work, all we need now is to import the database! That’s easy, too. Within the GoDaddy Hosting Contol Center, click “Open Manager” for your Laconica database and log in to the PHPMySQLAdmin interface. From the database drop down menu on the left, select the DB_NAME to bring up the database. Now on the right side of the screen click on the “import” tab.

The “Location of the text file” to import is the directory of the extracted Laconica archive/db/laconica.sql

Click “Go” at the bottom right of that screen and now you should be good to go with Laconica on your GoDaddy hosting account. And if it’s not GoDaddy then this was probably an easier task for you.

The best thing you can do for yourself to set up Laconica is to read the Laconica README.

Switch to our mobile site