欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Oracle expdp备份计划任务设计

程序员文章站 2024-03-13 16:34:39
...

一、使用expdp备份,首先要做的准备:
1.登录Oracle之后建立备份文件夹并赋权限:

create or replace directory dmp as '/home/OracleBackup/expdpbak';
grant  read,write on directory dmp to SYSTEM;

2.测试备份脚本
oracle_backup_expdp.sh放到/home/oracle/scripts 文件夹下,并赋权

# chmod +x oracle_backup_expdp.sh
#!/bin/sh
#create or replace directory dmp as '/home/OracleBackup/expdpbak';
#grant read,write on directory dmp to system;
#echo "Test /oradata is mounted ..."
export DateStr=`date "+%Y%m%d"`
export DateStr2=`date "+%Y%m%d_%H%M%S"`

su - oracle <<EON
if test -d /home/OracleBakup/expdpbak
then
:
else
 mkdir -p /home/OracleBackup/expdpbak
fi

expdp \'/ as sysdba\' directory=dmp dumpfile=expdp_$DateStr2.dmp logfile=expdp_$DateStr2.log schemas=easytong

exit
EON

if test -d /home/oracle/expdpbak
then
:
else
 mkdir -p /home/oracle/expdpbak
fi

#cp /home/OracleBackup/expdpbak/expdp_$DateStr2.* /home/oracle/expdpbak
export DateStr=`date -d "7 days ago" "+%Y%m%d"`
cd /home/OracleBackup/expdpbak/
tar zcf expdp_$DateStr2.tar.gz expdp_$DateStr2.dmp expdp_$DateStr2.log
ftp -n -v 172.26.129.19 <<EOF    **//此处是FTP服务器的地址,异地备份存放位置**
user expdp expdp
bin
put expdp_$DateStr2.tar.gz 
prompt
mdelete expdp_$DateStr*.tar.gz
bye
EOF
mv expdp_$DateStr2.tar.gz /home/oracle/expdpbak/

str=expdp_$DateStr
find /home/OracleBackup/expdpbak/ -name "$str*" -exec rm {} \;
find /home/oracle/expdpbak/ -name "$str*" -exec rm {} \;

unset DateStr
unset DateStr2

3.时间服务器客户端配置

# yum install -y ntpdate    //安装ntp服务
[[email protected] zytk]# ntpdate 120.25.108.11   //测试ntpdate可用,此处是阿里云提供的服务IP
11 Mar 17:59:16 ntpdate[4607]: adjust time server 120.25.108.11 offset -0.039831 sec

4.创建计划任务

# crontab -l   //查看计划任务
# crontab -e   //编辑计划任务
00 22 * * * /home/oracle/scripts/oracle_backup_expdp.sh        #22点备份
10 * * * * /usr/sbin/ntpdate 120.25.108.11                   #每小时的10分去同步时间