MySQL Backup Script

JRB Technology blog offers a script on how to backup a MySQL database. The described solution uses perl to call three commands:

@b1 = `mysqldump -h localhost -u mysql_username –password=mysql_password mysql_database > /path/to/put/mysql_database.sql`;@z1 = `zip -r -9 ~/path/to/mysql_database.zip ~/path/to/mysql_database.sql`;@d = `rm -f ~/path/to/mysql_database.sql`;

I have posted a comment directly to the origin blog with some (as I see it) improvements, but unfortunately the comment was deleted, so I will reproduce it here.

First of all I think that there is no need to create a temporarily SQL file with dump from the database and then zipping it. The zip command supports getting data from STDIN, so this way, instead of running 3 commands, only one is needed:

mysqldump -h hostname -u username –password=somepassword databasename | zip -9 mysql_database.zip

Then I offered to hide a password, since otherwise it is possible to see it by running the ps command under any user during script execution, and password will be seen in the arguments list. To hide a password, we can create a text file which is accessible only to us (chmod 600) and store a password string there, then modify the backup command accordingly:

mysqldump -h hostname -u username –password=`cat /path/to/securefile.txt` databasename | zip -9 mysql_database.zip

This way, even if someone will see that the password for accessing database is in the specified text file, it will be harder to get it, since file is readable only by owner user.

Finally, I would like comment a bit on Perl script itself, which author of the original script provides: first of all, I don\’t see any point of using Perl here, since nothing, except for calling standard commands is done during execution. A plain bash script would do a job fine. Anyway, even if you prefer using Perl, I would strongly recommend using -w switch and use strict; statement (even in such simple script, it is just good to use this every time)

Got myself a photo camera

I have finally got myself a photo camera. I was planning to buy one for a long time and I did it. While selecting a type of camera , I had a number of criterias:- The camera should use Memory Stick Duo as a storage since I also have the same in my phone

– The camera should be 5+ megapixels (I don\’t think that whatever is above matters a lot for non-professional photographer)

– The camera should operate on AA size batteries since they are easy to find anywhere.

– The camera should use standart USB cable for connecting to PC, since it is easy to replace in case of failures

– The camera should be able to take videos in MPEG format and 640×480 size
I got myself a Sony Cybershot 600s and I like it a lot. In addition I have purchased a number of accessories like carrying case, battery charger and 1GB memory card.

Here is how it looks like:

\"Sony

Cyprus Trip

Since now I have a car, I try to do some small trips to different places in Cyprus. This Sunday we went a long way through Paphos, to Polis, Latchi, Baths of Aphrodite, Akamas, back to Paphos through Lara Beach and back to Limassol. A friend of mine Michael who joined us in a trip had a photo camera with him, so we were lucky to get some pictures as well. Have uploaded all of the pictures on my Flickr page as well as one short video on YouTube.

I am thinking of getting my own camera as well since I really liked the photos and I do travel a lot these days :)

Java Stuff

I think I have already mentioned before that due to the Object Oriented Programming college class I have to play around Java now. I was assigned to do a project in Java and I decided to check what I can do there. Being more a perl guy, I have a faced a numerous problems with Java which I try to overcome in all possible ways. Here is what problems I have:

1. Static method declaration in abstract class. This really drives me crazy :(. I have a case where I really need to have static methods in abstract class (with implementation code inside) and I can not do it which causes me a lot of headache.

2. I am really missing an analog of perl keyword __PACKAGE__ in Java. This, sometimes also have to do with the first issue. For example I want to create an abstract class which defines the structure of a database table model, and this class should have static methods such as retrieveAll or search to return an array of objects of this class. Lets assume that I am allowed to have static methods in abstract classes and that I have a __PACKAGE__ option, then I would write something like this:

abstract public class DBModel extends DB {

abstract static private String dbTableName;

static public __PACKAGE__ retrieveAll () {

DB myDB = new DB();
myDB.query(\"SELECT id FROM \" + dbTableName + \"\");

if (myDB.getResultCount() > 0) {
int i = 0;

__PACKAGE__ itemList[];
while (myDB.getResultSet().next()) {

itemList[i++] = __PACKAGE__ new( myDB.getResultSet().getInt(\"id\") );
}
return itemList;

}

return null;
}
}

public class MCategories extends DBModel {

static private String dbTableName = \"customers\";
}

Like this, all classes which extend DBModel would have a static method retrieveAll() which would retrieve a list of all items from the DB.

3. Declaration and assignment to a variable inside of if/while/whatever. Sometimes I just need to do something like this (using the above example):

if ((Object[] objectsList= MCategories.retrieveAll()) != null) {

// do something with objectsList[].
}

If you know some workarounds, please let me know.

Got my car back

I have finally got my car back from the garage and here is what I think:

First of all the door was replaced. It looks good and I feel happy. This was the main purpose of giving the car to the garage. I also liked the fact that garage had provided me with their car while they were dealing with mine, but here are some things I didn\’t like:

1. It took them 1 week to replace the door. A friend of mine who is working on car repairs told me that he could do it in 2 days. Maybe the guys were very busy, but still – kinda too long.

2. They have not did any additional things I have asked them to do like: change oil, change filters, check the handbrake and check if they can fix the fuel amount sensor. Pity. Now I need to give car to repair these items :(

3. When I called the garage today to ask about a car, they told it will be ready in 1 hour. I came to them 3 hours later and they told me that they haven\’t manage to wash it yet, so I have to wait for another hour – no way, I took the car unwashed since I was in a hurry and now I will give it for washing myself.

Seems to be it, but I think I will be looking for different garage (not that busy one). I was already advised to check one garage owned by friend of friend of mine :) I will check it up and let you know.