Centos7下 Oracle11G自动备份

1、创建备份目录:

[[email protected] ~]# mkdir -p /home/oracle/backup

2、设置目录权限:

[[email protected] ~]# chown -R oracle:oinstall /home/oracle/backup

3、登录 Oracle:

[[email protected] ~]# su - oracle        # 切换到 Oracle 用户下
上一次登录:三 12月  4 00:58:48 CST 2019pts/1 上
[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on 星期四 12月 5 00:01:20 2019

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


连接到: 
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 

4、指定 expdp 输出目录:

create directory expdata as '/home/oracle/backup';

5、授予 system 权限:

grant create any directory to system;

6、退出 sqlplus:

exit;

或者按 CTRL + d。

7、编写备份脚本:

[[email protected] ~]$ vim /home/oracle/oracle_back.sh

脚本内容如下:

#!/bin/bash
# oracle 全库备份脚本,只保留最近7天的备份

# export ORACLE_BASE=/u01/app/oracle
# export ORACLE_SID=centos
# export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
# export PATH=$PATH:$ORACLE_HOME/bin
# 以上环境变量如果在 .bash_profile 已配置过,则无需添加

DATA_DIR="/home/oracle/backup"
BAKUP_TIME=`date +%Y-%m-%d`
DAYS=7
echo "Starting backup..."
echo "Bakup file path $DATA_DIR/$BAKUP_TIME.dmp"
expdp system/'oracle' directory=expdata dumpfile=$BAKUP_TIME.dmp full=y logfile=$BAKUP_TIME.log
echo "Successfully."
# 删除 7 天之前的备份脚本
find $DATA_DIR -type f -mtime +$DAYS -exec rm -f {} \;

8、设置定时任务:

[[email protected] ~]$ crontab -e

0 1 * * * /home/oracle/oracle_back.sh # 每天凌晨一点执行
 

 最后保存退出。可通过 crontab -l 查看任务是否设置成功。

 

 

参考链接:https://blog.csdn.net/Byppfeng/article/details/90376780

猜你喜欢

转载自www.cnblogs.com/d0usr/p/11986594.html