AUTOMATED HOT BACK UP IN LINUX

STEP 1) CREATE .sh file using text editor

example::::
-------------------------------------------------------------------------------------
#!/bin/bsh -f
usr=sys
pswd=sys
myDate="$(date +%d-%b-%y_%H:%M)"
export ORACLE_HOME=/home/oracle/oracle/product/10.2.0/db_1
export ORACLE_SID=toms

$ORACLE_HOME/bin/sqlplus -s $usr/$pswd as sysdba<<eof

alter database begin backup;

exit;

eof

cp /home/oracle/oracle/product/10.2.0/oradata/toms/sysaux01.dbf /home/oracle/backup/
cp /home/oracle/oracle/product/10.2.0/oradata/toms/example01.dbf /home/oracle/backup/
cp /home/oracle/oracle/product/10.2.0/oradata/toms/system01.dbf /home/oracle/backup/
cp /home/oracle/oracle/product/10.2.0/oradata/toms/undotbs01.dbf /home/oracle/backup/
cp /home/oracle/oracle/product/10.2.0/oradata/toms/users01.dbf /home/oracle/backup/


$ORACLE_HOME/bin/sqlplus -s $usr/$pswd as sysdba <<eof

alter database end backup;

exit;

<<eof

step2) run .sh file and check whether its running or not
./test.sh


step3) create crontab file(for auto scheduling)

$crontab -e

add the following

  * * * * * /home / oracle / test3.sh > /home / oracle / new3.txt
  in the given example test3.sh will execute in each minute......


*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

More examples:::

              30 0 1 1,6,12 *    –  00:30 Hrs  on 1st of Jan, June & Dec.
              0 20 * 10 1-5      – 8.00 PM every weekday (Mon-Fri) only in Oct.
       0 0 1,10,15 * *    –  Midnight on 1st ,10th & 15th of month
       5.10         0 10 * 1   –  At 12.05,12.10 every Monday & on 10th of every month


More example

If i want to run a particular file on 11.30 in morning daily then

 30  11  *  *  * /home/oracle/test.sh >> /home/oracle/text.txt

All operations will be noted on the text file, and '>>' will append the text to the existing file

No comments:

Post a Comment