An array of C#, PHP, and HTML programming articles, tutorials, and resources

Archive for August, 2008

I was given the task of setting up a nightly back up of files located on one Linux Machine (Red Hat) to another Linux Machine (Red Hat). All the files requiring backup are located in one folder. This folder contains both files and folders (which can contain more files and folders). Each files is only very small (couple bytes each) and once a file is created, it is never changed or edited).

Having not a very clear idea on how to approach this task, I began to experiment and look for various other methods. My searches only gave way to many applications specializing in performing backups, none of which I really wanted to implement.

I realized that if I mounted the folder containing files from the host machine to the backup machine, and then performed a simple cp command. After running man cp, I came across the following command that would accomplish what I needed. Therefore, after mounting the folder as a directory, I do all these changes the Backup Machine.


cp -upR --reply=yes /mountedDirectory /backupDirectory

The following is a breakdown of what each command means.

-u
copy only when the SOURCE file is newer than the destination file or when the destination file is missing

-p (same as –preserve=mode, ownership, timestamp)
preserve the specified attributes (default:mode,ownership,timestamp) and security context, if possible attributes: links, all

-R
copy directories recursively

–reply={yes, no, query}
specify how to handle the prompt about an existing destination file.

During the testing phase, I found that the first execution took the longest (above six minutes), but each susequent execution was shorter (about one minute). I figured that most of the time spent during the first execution was due to many copy operations where most of the time spent during each subsequent execution was comparing.

The next step was to put my single line command into a script file. This is done by creating a *.sh file. I decided to put this file where the rest of these files live, which is mainly /bin. Create a new file with the following format and give it a name. In this example, we are using nightlyBackup.sh.


#!/bin/sh
cp -upR --reply=yes /mountedDirectory /backupDirectory

Next, navigate to the files and change the chmod. We want to chmod to 777 to give the owner read, write, and execute priveliges. The group and others will get read and execute preiveliges. This can be accomplished by:


chmod777 nightlyBackup.sh

The next step to get this simple singe line script to run nightly. This I found could be accomplished by running a crontab. A crontab is a linux application that will run scripts at specified times (similiar to schedulers in Windows)

crontab -l will list all scripts set for execution.
crontab -e will bring up a prompt to add scripts.

Since I want mine to run sometime during the night each night, I set mine to by adding this to the file as a new line:


0 0 * * * /bin/nightlyBackup.sh

Save and close the file and now the script is set to run nightly. What is obvious in this setup is that both the host machine and the backup machine need to be up and running each night for this to work. Otherwise, this is a perfectly great solution that requires little setup and maintenance.

In this solved challenge, I had a GridView on my C# Web Application that was dynamically creating columns based on user selections. In the general case, everything was working without any problems. The potential column names were listed in the database, which were selectable from a checkbox list.

One day, I got reports that the page was breaking (javascript error), but not blowing up completely. I narrowed down to the fact that one of the potential column names added to the database included a period (or dot). During the debugging phase, I found the following error, where in fact the column name should have been called ‘12.5′.

DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name ‘12′.

This was then causing the code that at runtime creates columns to error. The column seems to be successfully created, but the column name was only displaying as ‘12′ as opposed to ‘12.5′. As it turns out, the Eval function accepts a pattern, which the period (or dot) is assigned different meaning.

hl.Text = DataBinder.Eval(row.DataItem, columnName).ToString();

Through searching the MSDN libraries and the internet, I came across a similar solution where we assign the hyperlink via a different function. The GetPropertyValue function appears not to use a pattern search and instead searches for the string exactly as is passed in the function.

hl.Text = DataBinder.GetPropertyValue(row.DataItem, columnName).ToString();

Therefore, this was a solution to my problem. Through other various web developer forums and sites, I have also found that this problem applies not only to the period (or dot), but also to other special characters of the pattern. I believe dot means wildcard.