• Oracle rman定时备份策略


    一、备份脚本

    <1>.0级备份

    vim level0_backup.sh

    1. #!/bin/bash
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/bin
    9. export PATH
    10. export ORACLE_SID=orcl
    11. export ORACLE_BASE=/u01/app/oracle
    12. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    13. export PATH=$PATH:$ORACLE_HOME/bin
    14. dateTime=`date +%Y-%m-%d`
    15. rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level0_${dateTime}.log

    vim level0_backup.rcv

    1. connect target sys/***@orcl
    2. run{
    3. crosscheck backup;
    4. crosscheck archivelog all;
    5. delete noprompt obsolete;
    6. delete noprompt expired backup;
    7. allocate channel d1 type disk;
    8. allocate channel d2 type disk;
    9. backup incremental level 0 as compressed backupset database format '/dbbak/backup/LEVEL0/level0_%d_%s_%p_%u.bak'
    10. tag='level 0' include current controlfile;
    11. sql'alter system archive log current';
    12. backup as compressed backupset archivelog all format '/dbbak/backup/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
    13. backup spfile tag='spfile' format='/dbbak/backup/LEVEL0/spfile_%U_%T';
    14. delete force noprompt archivelog all completed before 'sysdate-7';
    15. release channel d2;
    16. release channel d1;
    17. }

    <2>.1级备份

    vim level1_backup.sh

    1. #!/bin/bash
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/bin
    9. export PATH
    10. export ORACLE_SID=orcl
    11. export ORACLE_BASE=/u01/app/oracle
    12. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    13. export PATH=$PATH:$ORACLE_HOME/bin
    14. dateTime=`date +%Y-%m-%d`
    15. rman cmdfile=/u01/app/ora_backup/backup_scripts/level1_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level1_${dateTime}.log

    vim level1_backup.rcv

    1. connect target sys/***@orcl
    2. run{
    3. crosscheck backup;
    4. crosscheck archivelog all;
    5. delete noprompt obsolete;
    6. delete noprompt expired backup;
    7. allocate channel d1 type disk;
    8. backup incremental level 1 as compressed backupset database format '/ora_backup/backup_sets/LEVEL1/level1_%d_%s_%p_%u.bak'
    9. tag='level 1';
    10. sql'alter system archive log current';
    11. backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL1/log_%d_%s_%p_%u.bak' delete all input;
    12. delete force noprompt archivelog all completed before 'sysdate-7';
    13. release channel d1;
    14. }

    <3>.2级备份

    vim level2_backup.sh

    1. #!/bin/bash
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/bin
    9. export PATH
    10. export ORACLE_SID=orcl
    11. export ORACLE_BASE=/u01/app/oracle
    12. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    13. export PATH=$PATH:$ORACLE_HOME/bin
    14. dateTime=`date +%Y-%m-%d`
    15. rman cmdfile=/u01/app/ora_backup/backup_scripts/level2_backup.rcv msglog=/u01/app/ora_backup/backup_logs/level2_${dateTime}.log

    vim level2_backup.rcv

    1. connect target sys/***@orcl
    2. run{
    3. crosscheck backup;
    4. crosscheck archivelog all;
    5. delete noprompt obsolete;
    6. delete noprompt expired backup;
    7. allocate channel d1 type disk;
    8. backup incremental level 2 as compressed backupset database format '/ora_backup/backup_sets/LEVEL2/level2_%d_%s_%p_%u.bak'
    9. tag='level 2';
    10. sql'alter system archive log current';
    11. backup as compressed backupset archivelog all format '/ora_backup/backup_sets/LEVEL2/log_%d_%s_%p_%u.bak' delete all input;
    12. delete force noprompt archivelog all completed before 'sysdate-7';
    13. release channel d1;
    14. }

    二、每月1号备份脚本

    <1>.每月一号定时备份


    vim level0_backup_arch.sh

    1. #!/bin/bash
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/bin
    9. export PATH
    10. export ORACLE_SID=orcl
    11. export ORACLE_BASE=/u01/app/oracle
    12. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    13. export PATH=$PATH:$ORACLE_HOME/bin
    14. dateTime=`date +%Y-%m-%d`
    15. rm -f /ora_archive_bk/arch/LEVEL0/*
    16. rman cmdfile=/u01/app/ora_backup/backup_scripts/level0_backup_arch.rcv msglog=/u01/app/ora_backup/backup_logs/level0_arch_${dateTime}.log

    vim level0_backup_arch.rcv

    1. connect target sys/***@orcl
    2. run{
    3. crosscheck backup;
    4. crosscheck archivelog all;
    5. delete noprompt obsolete;
    6. delete noprompt expired backup;
    7. allocate channel d1 type disk;
    8. allocate channel d2 type disk;
    9. backup incremental level 0 as compressed backupset database format '/dbbak/LEVEL0/level0_%d_%s_%p_%u.bak'
    10. tag='level 0' include current controlfile;
    11. sql'alter system archive log current';
    12. backup as compressed backupset archivelog all format '/dbbak/LEVEL0/log_%d_%s_%p_%u.bak' delete all input;
    13. backup spfile tag='spfile' format='/dbbak/LEVEL0/spfile_%U_%T';
    14. delete force noprompt archivelog all completed before 'sysdate-7';
    15. release channel d2;
    16. release channel d1;
    17. }

    <2>.备份归档文件

    vim level0_bk_arch.sh

    1. #!/bin/bash
    2. # .bash_profile
    3. # Get the aliases and functions
    4. if [ -f ~/.bashrc ]; then
    5. . ~/.bashrc
    6. fi
    7. # User specific environment and startup programs
    8. PATH=$PATH:$HOME/bin
    9. export PATH
    10. export ORACLE_SID=orcl
    11. export ORACLE_BASE=/u01/app/oracle
    12. export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
    13. export PATH=$PATH:$ORACLE_HOME/bin
    14. dateTime=`date +%Y%m%d`
    15. cd /dbbak/arch_rar_file
    16. #加密打包拷贝
    17. /usr/local/bin/rar -p"****" a -agYYYYMMDD -ep -ta`date +%F` -r /dbbak/arch_rar_file/BkArc_ /dbbak/LEVEL0/*.* /u01/app/ora_backup/control_backup/*$dateTime*

    三、定时脚本

    <1>.使用crontab定时执行

    crontab -l

    1. 0 5 1 * * sh /u01/app/ora_backup/backup_scripts/level0_bk_arch.sh
    2. 10 1 * * 0 sh /u01/app/ora_backup/backup_scripts/level0_backup.sh
    3. 10 1 1 * * sh /u01/app/ora_backup/backup_scripts/level0_backup_arch.sh
    4. 10 1 * * 3,6 sh /u01/app/ora_backup/backup_scripts/level1_backup.sh
    5. 10 1 * * 1,2,4,5 sh /u01/app/ora_backup/backup_scripts/level2_backup.sh
    6. #DG备库定时清理应用过的日志
    7. 10 1 * * * sh /home/oracle/clear_archlog.sh

    四、定时清理DG归档脚本

    vim clear_archlog.sh

    1. #!/bin/sh
    2. BACK_DIR=/home/oracle/clear_archlog
    3. export DATE=`date +%F`
    4. mkdir $BACK_DIR/$DATE
    5. echo " " >> $BACK_DIR/$DATE/rman_backup.log
    6. echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
    7. su - oracle -c "
    8. rman log=$BACK_DIR/$DATE/rman_backup.log target / <
    9. # delete force archivelog all completed before 'sysdate - 1'; # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数
    10. delete force noprompt archivelog all completed before 'sysdate - 2';
    11. exit;
    12. EOF
    13. "
    14. echo " " >> $BACK_DIR/$DATE/rman_backup.log

  • 相关阅读:
    java基础巩固14
    无胁科技-TVD每日漏洞情报-2022-9-14
    B站8月第一周榜单丨飞瓜数据B站UP主排行榜发布!
    Day32——122.买卖股票的最佳时机II 55. 跳跃游戏 45.跳跃游戏II +第二天复习
    关于一个屏幕取词程序,AI给的创建思路及指导
    深度学习案例分享 | 房价预测 - PyTorch 实现
    dubbo源码解析之服务发布与注册
    1.CF240F TorCoder 线段树区间覆盖(区间排序回文构造)
    仕兰微、华为、汉王、凹凸科技、南山之桥、周立功等公司常见FPGA面试题整理
    Docker搭建redis集群
  • 原文地址:https://blog.csdn.net/demonson/article/details/128020878