数据泵expdp定时备份
1、创建用户所需的永久表空间和临时表空间
create tablespace tbs_hankey_dat datafile '/opt/oracle/oradata/tbs_hankey.dbf' size 2G; create temporary tablespace tbs_hankey_tmp datafile '/opt/oracle/oradata/tbs_hankey_tmp.dbf' size 2G;
2、创建用户和授权
create user hankey identified by "hankey" default tablespace tbs_hankey_dat temporary tablespace tbs_hankey_tmp;
grant dba to hankey;
3、设置备份文件存放路径:
root用户登录终端
mkdir /opt/oracle/bak chown oracle:oinstall /opt/oracle/bak
4、创建逻辑目录
sqlplus / as sysdba create directory expdp_dir as '/opt/oracle/bak';
5、创建脚本目录
mkdir /home/oracle/scripts
6、编辑脚本
vi /home/oracle/scripts/backupdmp.sh
脚本内容如下:
定时清理5天前的备份,保留最近5天的备份的全备
##################begin###################### #/bin/sh . /home/oracle/.profile now=`date +%Y%m%d` olddays=`date +%Y%m%d -d "-5days"` dmpfile=hankey_$now.dmp logfile=hankey_$now.log old_dmpfile=hankey_$olddays.dmp old_logfile=hankey_$olddays.log echo start exp $dmpfile ... #企业版 expdp "'/ as sysdba'" DIRECTORY=expdp_dir DUMPFILE=$dmpfile logfile=$logfile schemas=hankey compression=all parallel=4 cluster=N # compression=all 压缩 (标准版不支持)
# parallel=4 并行(标准版不支持)
# cluster=N 适用于RAC
#标准版
expdp "'/ as sysdba'" DIRECTORY=expdp_dir DUMPFILE=$dmpfile logfile=$logfile schemas=hankey cluster=N
cd /opt/oracle/bak
#传送文件到其他服务器 #scp $dmpfile $logfile 10.10.10.10:/bak rm -rf $old_dmpfile rm -rf $old_logfile ##################end######################
7、设置定时调度
每天凌晨调用脚本
00 01 * * * /home/oracle/scripts/backupdmp.sh bak.log 2>&1 </dev/null &