• rman 示例


    背景

          rman,听这名字,好像有点真的男人意思。这玩意其实也简单,只是老忘,作为一个oracle dba爱好者,怎么少了rman呢,这个好像是oracle体系的最后一环,把它掌握了,就完成oracle的闭环了。我是这么认为的。下面是我整理的知识点,其实主要是就是备份,一个文件,定时执行;一个是恢复,两个命令而已。

    内容

    • 每周日1点数据库全备
    • 每天8点备份归档

     [ora11204@OEL-ASM scripts]$ crontab -l 0 1 * * 0 /u01/orabak/scripts/backup.sh /u01/orabak 0 8 * * * /u01/orabak/scripts/backuparch.sh /u01/oraba

    • 全备脚本:vi backup.sh
    #!/bin/bash
    #ENV
    export ORACLE_SID=orcl
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    export PATH=$ORACLE_HOME/bin:$PATH
    
    #backup RMAN 
    if [ ! -d "$1" ]; then
            echo "You have input no dir for $1"
            exit 1
    fi
    
    echo "=================================================================================" >>${1}/backup_full.log
    echo "Begin backup at : `date`" >> ${1}/backup_full.log
    rman target / <<EOF >> ${1}/backup_full.log
    run {
    CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
    CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    backup as compressed backupset database format '${1}/FULLBAK_%d_%T_%s_%p.DBFILE'; 
    backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
    backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
    crosscheck backup;
    crosscheck copy;
    sql "alter system archive log current";
    backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
    crosscheck archivelog all;
    delete noprompt archivelog all completed before 'sysdate-10';
    delete noprompt expired backup;
    delete noprompt obsolete;
    }
    exit
    EOF
    echo "End backup at : `date`" >>${1}/backup_full.log
    
    echo "Begin scp at : `date`" >>${1}/backup_full.log
    scp ${1}/*`date +%Y%m%d`* oracle@192.168.1.61:/tmp/
    echo "End scp at : `date`" >>${1}/backup_full.log
    echo "=================================================================================" >>${1}/backup_full.log
    
    exit 0
    • 归档备份脚本:vi backuparch.sh
      这里只是去掉全备的命令,其他保留。
    #!/bin/bash
    #ENV
    export ORACLE_SID=orcl
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
    export PATH=$ORACLE_HOME/bin:$PATH
    
    #backup RMAN 
    if [ ! -d "$1" ]; then
            echo "You have input no dir for $1"
            exit 1
    fi
    
    echo "=================================================================================" >>${1}/backup_arch.log
    echo "Begin backup at : `date`" >> ${1}/backup_arch.log
    rman target / <<EOF >> ${1}/backup_arch.log
    run {
    CONFIGURE RETENTION POLICY TO REDUNDANCY = 2;
    CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
    CONFIGURE DEFAULT DEVICE TYPE TO DISK;
    backup current controlfile format '${1}/%d.%s.%p.%T.CTL';
    backup spfile format '${1}/%d.%s.%p.%T.SPFILE';
    crosscheck backup;
    crosscheck copy;
    sql "alter system archive log current";
    backup as COMPRESSED backupset archivelog all not backed up format '${1}/%d.%s.%p.%T.ARC';
    crosscheck archivelog all;
    delete noprompt archivelog all completed before 'sysdate-10';
    delete noprompt expired backup;
    delete noprompt obsolete;
    }
    exit
    EOF
    echo "End backup at : `date`" >>${1}/backup_arch.log
    
    echo "Begin scp at : `date`" >>${1}/backup_arch.log
    scp ${1}/*`date +%Y%m%d`*.{CTL,SPFILE,ARC} oracle@192.168.1.61:/tmp/
    echo "End scp at : `date`" >>${1}/backup_arch.log
    echo "=================================================================================" >>${1}/backup_arch.log
    
    exit 0

    参数文件:

    $ strings ORCL.24.1.20180619.SPFILE
    
    [oracle@jystdrac1 orcl]$ pwd
    /u01/oradata/orcl
    [oracle@jystdrac1 orcl]$ vi pfile.ora
    *.audit_file_dest='/u01/app/oracle/admin/orcl/adump'
    *.audit_trail='db'
    *.compatible='11.2.0.4.0'
    *.control_files='/u01/oradata/orcl/control01.ctl','/u01/oradata/orcl/control02.ctl'
    *.db_block_size=8192
    *.db_domain=''
    *.db_name='orcl'
    *.diagnostic_dest='/u01/app/oracle'
    *.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
    *.log_archive_dest_1='LOCATION=/u01/arch'
    *.memory_target=1234173952
    *.open_cursors=300
    *.processes=150
    *.remote_login_passwordfile='EXCLUSIVE'
    *.undo_tablespace='UNDOTBS1'
    
    
    SQL> startup nomount pfile='/u01/oradata/orcl/pfile.ora';
    ORACLE instance started.

     控制文件:

    RMAN> restore controlfile from '/tmp/ORCL.23.1.20180619.CTL';
    RMAN> alter database mount;
    RMAN> catalog start with '/tmp/';
    RMAN> crosscheck backup;


    转储文件并恢复到指定时间点:

    RMAN> restore database;
    RMAN> sql "alter session set nls_date_format=''yyyy-mm-dd hh24:mi:ss''";
    RMAN> recover database until time '2018-06-19 17:50:00';
    
    --先只读打开确认数据是否符合要求
    SQL> alter database open read only; 
    
    --确认没问题后重新以resetlogs方式打开
    SQL> create spfile from pfile='/u01/oradata/orcl/pfile.ora';
    SQL> startup mount
    SQL> alter database open resetlogs; 


  • 相关阅读:
    C# 编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出
    nopCommerce 3.9 大波浪系列 之 使用部署在Docker中的Redis缓存主从服务
    Docker 学习笔记
    nopCommerce 3.9 大波浪系列 之 微信公众平台登录插件
    nopCommerce 3.9 大波浪系列 之 可退款的支付宝插件(下)
    nopCommerce 3.9 大波浪系列 之 可退款的支付宝插件(上)
    nopCommerce 3.9 接口笔记
    nopCommerce 3.9 大波浪系列 之 开发支持多店的插件
    nopCommerce 3.9 大波浪系列 之 网页加载Widgets插件原理
    nopCommerce 3.9 大波浪系列 之 事件机制(生产者、消费者)
  • 原文地址:https://www.cnblogs.com/sddychj/p/9202106.html
Copyright © 2020-2023  润新知