1、root用户编写shell脚本OrclBackup.sh
#!/bin/bash export ORACLE_BASE=/home/oracle/app export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1 export ORACLE_SID=orcl export PATH=$ORACLE_HOME/bin:$PATH export DATA_DIR=/home/oracle/app/admin/orcl/dpdump export LOGS_DIR=/home/oracle/app/admin/orcl/dpdump export DELTIME=`date -d "10 days ago" +%Y%m%d` export BAKUPTIME=`date +%Y%m%d%H%M%S` export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK echo "Starting bakup..." echo "Bakup file path $DATA_DIR/$BAKUPTIME.dmp" expdp scott/tiger@172.168.1.10:1521/orcl dumpfile=$BAKUPTIME.dmp log=$BAKUPTIME.log directory=data_pump_dir echo "backup file success..." tar -zcvPf $DATA_DIR/scdzpj$BAKUPTIME.tar.gz $DATA_DIR/scdzpj$BAKUPTIME.dmp $DATA_DIR/scdzpj$BAKUPTIME.log --remove-files echo "tar the file bakup successfully. " rm -rf $DATA_DIR/scdzpj$DELTIME*.gz echo "Bakup completed."
2、将脚本添加到服务
chkconfig --add OrclBackup.sh
3、查验是否添加成功
chkconfig --list | grep OrclBackup.sh