使用EXPDP自动备份数据
1.创建ORACLE
Directory对象,如:
scott目录=/home/oracle/
create directory scott as '/home/oracle/';
Grant
read,write on directory scott to scott;
2.创建备份脚本-
#cd /home/oracle/
#touch expdp.sh
#chmod 775 expdp.sh
#vi expdp.sh
3.编辑expdp.sh文件内容如下:
[oracle@wg1 ~]$ vi
expdp.sh
#/bin/sh
export
ORACLE_SID=prod
export
ORACLE_HOME=/home/u01/app/oracle/product/11.2.0/db_1
export
NLS_LANG=american_america.zhs16gbk
now=`date +%Y%m%d`
dmpfile=db$now.dmp
echo start exp
$dmpfile ...
/home/u01/app/oracle/product/11.2.0/db_1/bin/expdp
scott/tiger@prod DUMPFILE=$dmpfile DIRECTORY=SCOTT
(expdp
system/sys@dev DUMPFILE=$dmpfile DIRECTORY=full full=y)
mv-f $dmpfile
/home/zengxb/share
#删除以前过期的备份
DUMP=/home/zengxb/share
#DUMP_HIS=/u01/oracle/backup_his
find $DUMP -name "*.dmp" -mtime +2 -exec rm {} \; ------删除超过两天的dmp文件
#find $DUMP_HIS
-name "*.dmp" -mtime +10 -exec mv {} /oradata/bak/dmpbaks/ \;
4.编辑crontab文件如下:
[root@wg1 oracle]#
crontab -e -u oracle
51
16 * * * /home/oracle/expdp.sh
>>/home/oracle/bak.log 2>&1
备份出来的是 scott20141027.dmp
5.重启crond 不重启也行的
#service crond
restart