## 자동 백업 및 복구
##
1. /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
30 22 * * * root /home/oracle/sh/OraBackup.sh
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
2. /home/oracle/sh/OraBackup.sh
#!/bin/bash
ORACLE_HOME=/home/oracle/product/8.1.7
export NLS_LANG=AMERICAN_AMERICA.KO16KSC5601
ORACLE_SID=orcl
export ORACLE_HOME ORACLE_SID
CDATE=`date +%Y%m%d`
UDMP_PATH=/home/oracle/admin/orcl/udump
CDMP_PATH=/home/oracle/admin/orcl/cdump
BDMP_PATH=/home/oracle/admin/orcl/bdump
find $UDMP -type f -name "*.trc" -mtime +7 -exec rm -rf {} \;
find $CDMP -type f -name "*.trc" -mtime +7 -exec rm -rf {} \;
find $BDMP -type f -name "*.trc" -mtime +7 -exec rm -rf {} \;
TDIR=/home/backup
find $TDIR -type f -mtime +2 -exec rm -rf {} \;
date > $TDIR/latest_update.log
/home/oracle/product/8.1.7/bin/exp userid=oraid/passwd@easy file=$TDIR/$CDATE.DMP
./OraUser.sh
/home/oracle/product/8.1.7/bin/imp userid=oraid/xxxxx file=$TDIR/$CDATE.DMP full=y log=$TDIR/$CDATE.LOG
date >> $TDIR/latest_update.log
./OraJobs.sh
3. OraUser.sh
#!/bin/bashORACLE_HOME=/home/oracle/product/8.1.7
export NLS_LANG=AMERICAN_AMERICA.KO16KSC5601
ORACLE_SID=orcl
export ORACLE_HOME ORACLE_SID
su - oracle -c /home/oracle/product/8.1.7/bin/svrmgrl<</
connect internal;
drop user oraid cascade;
create user oraid identified by xxxx default tablespace users temporary tablespace temp;
grant dba,resource,connect to oraid;
exit 0;
4. OraJobs.sh
#!/bin/bash
ORACLE_HOME=/home/oracle/product/8.1.7
export NLS_LANG=AMERICAN_AMERICA.KO16KSC5601
ORACLE_SID=orcl
export ORACLE_HOME ORACLE_SID
/home/oracle/product/8.1.7/bin/sqlplus -S oraid/passwd<< EOF
declare
cursor cs is
select job from dba_jobs;
begin
for c in cs loop
dbms_job.remove(c.job);
end loop;
end;
/
EOF
댓글 없음:
댓글 쓰기