zoukankan      html  css  js  c++  java
  • Linux中Oracle数据库备份还原

    一、备份Oracle数据库

    1.使用数据库管理员账户登录

    sqlplus system/system@orcl as sysdba;

    2.创建备份目录,并指定备份目录(bak_dir)的物理路径

    create or replace directory bak_dir as '/Oracle/OraBackupFile/Data';

    3.将“bak_dir”的读、写和执行权限赋给数据库用户(lpattendance)

    grant all on directory bak_dir to lpattendance;

    commit;

    4.执行备份脚本

    expdp lpattendance/lpattendance@orcl directory=bak_dir dumpfile=bak.dmp logfile=bak.log;

    二、还原Oracle数据库

    1.还原数据库

    impdp lpattendance/lpattendance@orcl directory=bak_dir table_exists_action=truncate dumpfile=bak.dmp

    2.还原数据库到指定用户

    impdp mytest/mytest@orcl directory=bak_dir table_exists_action=truncate dumpfile=bak.dmp remap_schema=lpattendance:mytest

    三、自动备份Oracle数据库

    1.新建备份脚本

    export ORACLE_BASE=/Oracle/OraDataBase/oracle
    export ORACLE_HOME=/Oracle/OraDataBase/oracle/product/10201
    export ORACLE_SID=orcl  
    export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin  
    
    export DATA_DIR=/Oracle/OraBackupFile/Data
    export BAKUPTIME=`date +%Y%m%d%H%M%S`
    export DELTIME=`date -d "7 days ago" +%Y%m%d` 
      
    expdp lpattendance/lpattendance@orcl directory=bak_dir dumpfile=$BAKUPTIME.dmp logfile=$BAKUPTIME.log
      
    #删除7天前的备份文件
    rm -rf $DATA_DIR/$DELTIME*.dmp
    rm -rf $DAta_DIR/$DELTIME*.log 
    

    注:如报“expdp command not found”错误,则将expdp命令加上对应的路径“$ORACLE_HOME/bin/expdp”

    2.添加到定时任务

    每天22点执行备份

    crontab -e
    
    * 22 * * * /Oracle/OraBackupFile/Lpattendance/bakup.sh 
  • 相关阅读:
    SpringBoot整合阿里云OSS
    UVALive
    HDU 5794 A Simple Chess dp+Lucas
    数论
    UVALive
    UVALive
    HDU 5792 World is Exploding 树状数组+枚举
    UVALive
    UVALive
    UVALive
  • 原文地址:https://www.cnblogs.com/BigeTouch/p/4911253.html
Copyright © 2011-2022 走看看