Tuesday, July 21, 2009

Problem you may find during runing the cronjob for EBS

In one of my previous blog "how to run EBS(create snapshot) by using cron" I have shown how take incremental snapshot by using cron job on a linux machine. But I have found that there are some problem guys are facing when the want to run the cron job.
Let me discuss the most common mistake we are doing when we want to tak the snapshot.

Some guys were questioning when the guys still logged in to the server at this moment that cron job is taking the snapshot perfectly but when he/she logged out from the server it is not taking the snapshot.

Don't forget you have export some variables such as “EC2_PRIVATE_KEY” , “EC2_CERT” , “JAVA_HOME” as environment at the moment of taking the snapshot. When you export a variable that variable temporarily become environment variable for the time you are logged in to the server. As a result when you logged out the cron job does not get those variables.

Some people add these variables to their profile bash rc file. Remember that the system will load that file only when you will logged into the server at that moment these variables will be available for the cron job.

What you can do?

  1. To add those variable to global environment file so that it can become available from every where. But in this case it will be available to every one.
  2. What did I do??? I made another file and export the variables from there and also invoke the “ec2-snapshot-xfs-mysql” file from there. And now I have set this file to my cron job

Let’s have a look how this new file looks like

#!/bin/bash
export EC2_PRIVATE_KEY=path to your pk-XXXXXXXXXX.pem
export EC2_CERT=path to your cert-XXXXXXX.pem
export EC2_HOME=path to your api tools folder /ec2-api-tools
export JAVA_HOME=path to your java jdk bin folder /java-6-sun
path to your /ec2-snapshot-xfs-mysql /mount_folder(in our case /vol ) your_volume_id(vol-xxxxxx)

Suppose the name of the file is test_snapshot is usr/test folder

Then our cron job will be looks like following

* * 1 * * usr/test/test_snapshot


this will take the snapshot on the 1st day of each month.




No comments: