#!/bin/ksh
# function: backup database(cdmaetl) or archive with rman
# usage: crontab on AIX
#env
export ORACLE_SID=cdmaetl
#export SHELL=/usr/bin/ksh
export ORACLE_HOME=/ora9i/OraHome1
export NLS_LANG=american_america.zhs16gbk
export PATH=$PATH:$ORACLE_HOME/bin
#variable
RMAN=$ORACLE_HOME/bin/rman
SQLPLUS=$ORACLE_HOME/bin/sqlplus
TEE=/usr/bin/tee
LOGFILE=/ora9i/logs/rmanback.log
#dictionary structure
DBDEST=/oradata/backup/rmanbak/${ORACLE_SID}/datafiles
CTLFILE=/oradata/backup/rmanbak/${ORACLE_SID}/ctlfiles/${ORACLE_SID}_ctl_`date +%Y%m%d%H%M`.ctl
#start running RMAN to backup database and redo log, also have a log for those actions
echo "----------------backup start----------------------" > $LOGFILE
date
$RMAN <<EOF $TEE -a $LOGFILE
connect target
#allocate channel for backup, and only bak database
Run{
allocate channel c1 type disk format '$DBDEST/%U_%s.bak' maxpiecesize = 2000M;
backup database filesperset = 4;
backup archive log delete input;
#save just only one bak
delete noprompt obsolete redundancy = 1 device type disk;
exit;
EOF
#start bak control file
$SQLPLUS "/ as sysdba" <<EOF $TEE -a $LOGFILE
alter database backup controlfile to '$CTLFILE';
exit
EOF
date
echo "-----------------backup end-----------------------" >> $LOGFILE
No comments:
Post a Comment