Tuesday, September 26, 2006

Backup for a Rainy Day!

We all know that backups are important! However, most users realize the importance of backups only after lightning strikes. We need to protect our data from the usual suspects such as hard disk crashes, fire, floods, theft etc. I have been using a free tool from Microsoft called SyncToy that makes running backups an ease. This post describes the backup procedure using SyncToy.

Note: Windows XP Professional comes with an out-of-the-box Backup utility. This utility produces a single backup file (.bkf) that could be later used to restore data and system settings. I prefer using SyncToy as it creates an exact replica of the directory and file structure. Thus the backed-up copy can also be used as a read-only reference when away from the source computer.

Steps to Getting Backups Up and Running 1. Centrally arrange data for easy backups. 2. Get an external USB hard drive. 3. Download and install Microsoft SyncToy. 4. Run SyncToy to backup your data. 5. Create a backup schedule. 6. Store the external hard drive safely.

1. Centrally arrange data for easy backups.
The first thing to do is to arrange our data centrally, preferably in a single hard drive partition or folder to facilitate easy backups.

2. Get an external USB hard drive.
There are a number of options available to store backed up data. These range from CD-Rs, DVD-Rs, USB sticks, external USB hard drives, SAN drives etc. I personally prefer USB hard drives as they are fairly inexpensive, easy to use, mobile and have significant storage capacities.

3. Download and install Microsoft SyncToy.
Once installed, setting up a backup job is pretty straightforward. Start by creating a 'New Folder Pair' (Screenshot). After specifying the source and destination folders we need to specify the synchronization action. This needs to be 'Echo' in our case (Screenshot). Using Echo, new and updated files are copied across and renames and deletes are repeated on the backup. One point to note is that Echo does not delete directories on the backup. Our backup job is now ready to run!

4. Run SyncToy to backup your data.
Running the SyncToy backup is an easy process. Select the relevent folder pair from the list at the left side of the main window and then click 'Run' (Screenshot). A progress bar apprears showing the advancement of the process.

5. Create a backup schedule.
Backups are valuable only when they are run regularly! We can automate this process by creating a Scheduled Task in Windows. This can be accessed at Start -> All Programs -> Accessories -> System Tools -> Scheduled Tasks. The wizard is simple to follow (Screenshot). To run our backup job, add -R "<folder-pair_name>" to the end of the Run command. To run all folder pairs just add -R.

6. Store the external hard drive safely.
Once we have a backup schedule in place it makes sense to store the backup drive at a separate geographic location to the source. This proves essential in times of natural calamities such as fire, floods, theft etc.

Thanks to SyncToy we now have a backup procedure in place!

Wednesday, September 13, 2006

Spring MVC and AJAX with JSON

One of the main decisions to be taken while developing AJAX applications is the format of messages passed by the server to the client browser. There are many options to choose from including plain text, XML, CSV etc. One of the more popular choices today is the JavaScript Object Notation (JSON). JSON provides a nice name-value pair data format that is easy to generate and parse. This is especially true when using an AJAX toolkit like Dojo that provides built-in functionality to parse JSON messages at the client. If you are using Spring MVC as your web framework, generation of these JSON messages is very straight-forward as well. Below we understand how to produce JSON messages while using Spring MVC.

Spring MVC defines the View interface to render views to the client. The framework provides a number of implementations including JstlView, RedirectView, TilesView etc. In order to return JSON messages we implement the View interface to create a new class that returns data formatted using the JSON notation. We shall call this class JSONView.

The method that we need to implement is render(Map model, HttpServletRequest request, HttpServletResponse response). The render method accepts a Map as it's first parameter and produces the output. We could manually iterate through the Map, process and produce the JSON output. However, there is a Java library called JSON-lib that produces the JSON notation. The code below shows our JSONView class that can be used as a Spring MVC View to return JSON output to the client.

import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.springframework.web.servlet.View;
public class JSONView implements View {
    public void render(Map map, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
        JSONObject jsonObject = JSONObject.fromMap(map);
        PrintWriter writer = response.getWriter();

As can be seen from the code above, Spring exploits MVC to it's full potential and provides the flexibility to tailor the view to exactly suit our needs.

Saturday, September 09, 2006

Hello World!

Hello World! Well, I finally had to bite the bullet and start my very own blog. Starting off with modest ambitions, I primarily hope to blog about my experiences with software, programming, technology and also general topics that I find interesting…

I am a software developer by profession, primarily focusing on Java Enterprise and Open Source technologies. You can access my personal website at www.techvj.com.

Now, with the short introduction out of the way, get ready for the Blog Attack