Backup transfer scripts for Linux to Windows

Hi folks!!!

This script will help you in understanding how to transfer the backup from a linux machine to windows. This is a small sample script you have to really tweak into it for a full proof system.
Step1: Create a share directory on windows machine

Step2: Create the transfer.sh script on your linux machine

Transfer.sh

#! /usr/local/bin

# specify the backup folder
backup_src=/backup/user1

# attach timestamp if required
# timestamp=`date +%d%m%y`
# dir=”$des”user1″$timestamp”

# Check if the backup source exist
if [ ! -d "$backup_src" ] ; then
echo “backup not possible directory does not exist”
echo “Source directory does not exist” | mail -s “Backup not possible: ” vyvaks@vyvaks.com
exit
else
# Mount the windows share point to transfer the backup
mount -t smbfs -o username=vyvaks,password=vyvaks //172.168.1.162/backupStore /mnt/backupStore/
if [ $? != 0 ]
then
echo ” Mount error “
echo ” Mount error ” | mail -s “Backup not possible: ” vyvaks@vyvaks.com
exit
fi
sleep 2
# copy the backup to mount point
cp -r $backup_src /mnt/bkup
if [ $? != 0 ]
then
echo “Copy Failed” | mail -s “Backup not possible: ” vyvaks@vyvaks.com
umount /mnt/bkup
exit
fi
# Unmount the windows mount point
umount /mnt/bkup
echo “Backup sucessfully transfered” | mail -s “Backup done : ” vyvaks@vyvaks.com

Step 3: Finally for scheduling add the script to the cron


Sparklines for JAVA

Finaly I could find the java implmentation for sparklines following are the two links

This one requires java1.5

http://www.representqueens.com/spark/

For java 1.4 and lower check this out

http://saucemaster.info/2005/08/09/jsparkline-001/#comments

For the above JSparkline I have implemented the antialiasing feature and also the slices for the pie chart.

Before antialising PieChart BeforeAreaChart Before LineChart Before and after PieChart After AreaChart After LineChart After

Sliced Pie Sliced Pie with border Sliced Pie


Why runtime.exec hangs in Java ?

I had hit with the same problem runtime.exec() hangs when i tried to execute a lengthy batch script in windows. The problem was clearly described in the java docs which i never read ;)

“Because some native platforms only provide limited buffer size for standard input and output streams, failure to promptly write the input stream or read the output stream of the subprocess may cause the subprocess to block, and even deadlock.”

The solution was to clear of the buffer so the process wont hit a deadlock. I have a small sample which could make you more clear.

public class ProcessHandler extends Thread {

InputStream inpStr;
String strType;

public ProcessHandler(InputStream inpStr, String strType) {
this.inpStr = inpStr;
this.strType = strType;
}

public void run() {
try {
InputStreamReader inpStrd = new InputStreamReader(inpStr);
BufferedReader buffRd = new BufferedReader(inpStrd);
String line = null;
while((line = buffRd.readLine()) != null) {
System.out.println(strType + ” —> ” + line);
}
buffRd.close();

} catch(Exception e) {
System.out.println(e);
}

}
public static void main(String args[])throws Exception {

/* For windows setting to cmd.exe */
String command[] = {“cmd.exe”,”/c”,cmd};

/* executing the command with environments set. */

Process pro = Runtime.getRuntime().exec(cmd);

/* handling the streams so that dead lock situation never occurs.  */
ProcessHandler inputStream =
new ProcessHandler(pro.getInputStream(),”INPUT”);
ProcessHandler errorStream =
new ProcessHandler(pro.getErrorStream(),”ERROR”);

/* start the stream threads */
inputStream.start();
errorStream.start();

}
}


Follow

Get every new post delivered to your Inbox.