i have a rman bash script which works when i execute it (./backup.sh). but when i use cronjob, it doesn't work. My scripts is as follows
backup.sh
rman target / @backup.rcv log=rman.log
backup.rcv
backup format '/backup/rman/backup/%U.arch.rman' filesperset 2 archivelog all delete input; backup format '/backup/rman/backup/%U.datafiles.rman' filesperset 2 incremental level 0 database; backup format '/backup/rman/backup/%U.arch.rman' filesperset 2 archivelog all delete input; backup format '/backup/rman/backup/%U.ctl.rman' current controlfile; delete noprompt obsolete;
my cronjob looks somthing like this
crontab -l
5 0 * * * /nas_backup/rman/svbo/backup/L0backup.sh >/dev/null 2>&1
i am very new to this rman and bash script so any help would be appreciated
inorder for this to be fixed replace the code in your "L0backup.sh" with
#!/bin/bash
#
export ORACLE_SID=your-sid
export ORACLE_HOME=your-oracle-home
$ORACLE_HOME/bin/rman target / nocatalog <<EOF
backup format '/nas_backup/rman/backup/%U.arch.rman' filesperset 2 archivelog all delete input;
backup format '/nas_backup/rman/backup/%U.datafiles.rman' filesperset 2 incremental level 0 database;
backup format '/nas_backup/rman/backup/%U.arch.rman' filesperset 2 archivelog all delete input;
backup format '/nas_backup/rman/backup/%U.ctl.rman' current controlfile;
delete noprompt obsolete;
EOF
to get your ORACLE_SID and ORACLE_HOME you can echo it out like
#echo $ORACLE_SID
your-sid
# echo $ORACLE_HOME
your-oracle-home
next to set your crontab - lets say you want the above file to run every midnight (Crontab Guru)
#crontab -e
5 0 * * * /bin/bash /nas_backup/rman/backup/L0backup.sh > /nas_backup/rman/backup/rman.log 2>&1
if you notice your output gets loged to "rman.log".
furthermore you can now delete your "backup.rcv" file as its no longer being used.