oracle差异增量异地备份(Differential incremental and remote backup)

  1. 挂载nfs,并设置开机自动挂载。

2,编写level0备份脚本并chmod执行权限。

[oracle@oracle170 job]$ vim bak0.sh 
#~/.bashrc中有定义环境变量,脚本中就不需要重复定义。
export ORACLE_SID=OCR
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export TMP=/tmp
export TMPDIR=$TMP
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$HOME/.local/bin:$HOME/bin:$PATH
export EDITOR=vim
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_PATH=.:$ORACLE_BASE/dba_scripts/sql:$ORACLE_HOME/rdbms/admin
export SQLPATH=$ORACLE_HOME/sqlplus/admin
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias asmcmd='rlwrap asmcmd'
/u01/app/oracle/product/12.2.0/db_1/bin/rman target / log=/orabaskup/data/bak0.log append <<EOF
run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    crosscheck archivelog all;#先crosscheck一下减少archivelog备份集大小
    delete noprompt expired archivelog all;
    backup incremental level 0 tag 'bak0' format '/orabaskup/data/bak0_%u_%d_%s' database ;
    sql 'alter system archive log current';#归档level0备份日志
    backup archivelog all tag='arch_bak' format '/orabaskup/data/archbak_%u_%d_%s' delete input;#控制文件和参数文件会自动备份。
    crosscheck backup;
    delete noprompt expired backup;
    delete noprompt obsolete;#删除废弃的备份。
    release channel c1;
    release channel c2;
    release channel c3;
    }
EOF

  

3,编写差异增量level1备份脚本并chmod执行权限。

[oracle@oracle170 job]$ vim bak1.sh 

export ORACLE_SID=OCR
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
export TMP=/tmp
export TMPDIR=$TMP
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$HOME/.local/bin:$HOME/bin:$PATH
export EDITOR=vim
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORACLE_PATH=.:$ORACLE_BASE/dba_scripts/sql:$ORACLE_HOME/rdbms/admin
export SQLPATH=$ORACLE_HOME/sqlplus/admin
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias asmcmd='rlwrap asmcmd'
/u01/app/oracle/product/12.2.0/db_1/bin/rman target / log=/orabaskup/data/bak1.log append <<EOF
run{
    allocate channel c1 type disk;
    allocate channel c2 type disk;
    allocate channel c3 type disk;
    crosscheck archivelog all;
    delete noprompt expired archivelog all;
    backup incremental level 1 tag 'bak1' format '/orabaskup/data/bak1_%u_%d_%s' database ;
    sql 'alter system archive log current';
    backup archivelog all tag='arch_bak' format '/orabaskup/data/archbak_%u_%d_%s' delete input;
    crosscheck backup;
    delete noprompt expired backup;
    delete noprompt obsolete;
    release channel c1;
    release channel c2;
    release channel c3;
    }
EOF

  

4,oracle用户创建任务计划crontab

[oracle@oracle170 data]$ crontab -e

1 0 * * sat /orabaskup/job/bak0.sh#周六level0级备份
1 0 * * sun,mon,tue,wed,thu,fri /orabaskup/job/bak1.sh#其他level1级备份

 

posted @ 2021-07-23 13:24  zjj556  阅读(211)  评论(0编辑  收藏  举报