We can create a corn job to run a shell script periodically. But
creating a job schedule for taking database backup is subtle difference.
In the script you have to write code to navigate to database bin
directory and then the script for exporting.
Steps:
1. Edit the crontab using following command and add the line as below:
$crontab -e
0 19 * * * /usr/db_backup/export.sh
Scheduling backup at 7pm every day.
here,
* * * * * 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)
Contents of export.sh:
export ORACLE_BASE=/orafs/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_2
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=remittance
exp userid=dbbl/ggg@remittance file=/usr/db_backup/remdb_$(date +%Y_%m_%d_%s).dmp log=/usr/db_backup/remdb_$(date +%Y_%m_%d_%s).log owner=dbbl buffer=200000
cron commands:
$crontab -l To list the cron jobs scheduled
$crontab -r To remove the cron job
$crontab -e To edit/schedule cron jobs
Crontab Environment:
cron invokes the command from the user’s HOME directory with the shell, /usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Special words:
If you use the first (minute) field, you can also put in a keyword instead of a number:
By default cron saves the output of
Steps:
1. Edit the crontab using following command and add the line as below:
$crontab -e
0 19 * * * /usr/db_backup/export.sh
Scheduling backup at 7pm every day.
here,
* * * * * 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)
Contents of export.sh:
export ORACLE_BASE=/orafs/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_2
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID=remittance
exp userid=dbbl/ggg@remittance file=/usr/db_backup/remdb_$(date +%Y_%m_%d_%s).dmp log=/usr/db_backup/remdb_$(date +%Y_%m_%d_%s).log owner=dbbl buffer=200000
cron commands:
$crontab -l To list the cron jobs scheduled
$crontab -r To remove the cron job
$crontab -e To edit/schedule cron jobs
Crontab Environment:
cron invokes the command from the user’s HOME directory with the shell, /usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Special words:
If you use the first (minute) field, you can also put in a keyword instead of a number:
@reboot Run once, at startup @yearly Run once a year "0 0 1 1 *" @annually (same as @yearly) @monthly Run once a month "0 0 1 * *" @weekly Run once a week "0 0 * * 0" @daily Run once a day "0 0 * * *" @midnight (same as @daily) @hourly Run once an hour "0 * * * *Leave the rest of the fields empty so this would be valid:
@daily /bin/execute/this/script.shStoring the crontab output
By default cron saves the output of
/bin/execute/this/script.sh in the user’s mailbox (root in this case). But it’s prettier if the output is saved in a separate logfile. Here’s how:*/10 * * * * /bin/execute/this/script.sh 2>&1 >> /var/log/script_output.log For More details: http://pdpshetty.blogspot.com/2008/06/scheduling-backup-using-crontab-in.html http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_cro
No comments:
Post a Comment