• Oracle之备份一管理恢复目录


    一、管理恢复目录 #现实应用中一般都是专门新建一个rman 数据库,给所有的数据库做catalog
    1、建立恢复目录

    #建立恢复目录表空间
    SQL> create tablespace rman_ts datafile '/u01/app/oracle/oradata/ocmdb/dfile/rman.dbf' size 15m;

    #建立恢复目录所有者
    SQL> create user rman identified by rman;

    #授予恢复目录所有者角色
    SQL> grant connect,resource,recovery_catalog_owner to rman;

    #建立恢复目录
    [oracle@ocmdb1 ~]$ rman catalog rman/rman@ocmdb
    Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 13 14:06:18 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    connected to recovery catalog database
    RMAN> create catalog;

    #注册目标数据库
    [oracle@ocmdb1 ~]$ rman catalog rman/rman #连接到rman catalog 恢复目录
    Recovery Manager: Release 10.2.0.1.0 - Production on Thu Oct 13 14:23:08 2011
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    connected to recovery catalog database

    RMAN> connect target sys/oracle@ocmdb #连接到目标数据库
    connected to target database: OCMDB (DBID=4106451204)

    RMAN> register database; #在catalog 中,注册目标数据库
    starting full resync of recovery catalog
    full resync complete
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03009: failure of register command on default channel at 10/13/2011 14:23:36
    RMAN-20002: target database already registered in recovery catalog

    RMAN> report schema; #列出目标数据库当前的schema

    注意:当使用rman 连接目标数据库时报错如下:
    RMAN-06004: ORACLE error from recovery catalog database: RMAN-20001: target database not found in recovery catalog
    需要在 tnsnames.ora 文件里编辑增加 (SERVER = dedicated)

    如下:[oracle@ocmdb1 admin]$ cat tnsnames.ora
    OCMDB =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = tcp)(HOST = ocmdb1)(PORT = 1521))
    (CONNECT_DATA =
    (SERVICE_NAME = ocmdb)
    (SERVER = dedicated)
    )
    )

     

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    RMAN备份脚本测试


    RMAN备份只讲叙有恢复目录的情况,如果没有恢复目录,情形大致相似。以下是RMAN的热备份全备份的脚本:
    # script:bakup.sh
    # creater:chon
    # date:2011
    # desc:backup all database datafile in archive with rman

    # connect database
    rman <<EOF
    connect catalog rman/rman
    connect target sys/oracle@ocmdb

    # start backup database
    run{
    allocate channel c1 type disk;
    backup full tag 'dbfull' format '/backup/full%u_%s_%p' database
    include current controlfile;
    sql 'alter system archive log current';
    release channel c1;
    }
    EOF
    # end

    说明:
    1、 数据库必须运行在归档模式下
    2、 RMAN将自动备份数据文件,运行可靠
    3、 归档日志另外备份处理,但至少需要保存一次备份来的日志
    4、 没有必要用RMAN做冷备份,效果不好

     


    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    把最近刚改写完成的RMAN增量备份脚本贴上来,经过几天的测试基本运行良好,下一步可以在生产库上用了,测试过程中特别增加了尽量节约空间的考虑(磁盘空间不是很冗余),

     

    备份策略:
    crontab -l
    #每周日凌晨做0级备份,
    #每周一,四做一级备份,
    #每周二,三,五,六做二级备份,
    00 4 * * 0 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 0
    00 4 * * 1,4 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 1
    00 4 * * 2,3,5,6 /u01/app/oracle/rman_bak/scripts/rman_bak.sh 2
    备份脚本:
    #!/bin/bash
    #set env
    export ORACLE_BASE=/u01/app/oracle
    export ORACLE_HOME=$ORACLE_BASE/db10g
    export ORACLE_SID=emar
    export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
    export PATH=$ORACLE_HOME/bin:$PATH
    DATE=`date +%w`
    DATE_2=`date +%Y%m%d`
    BACKUP_PATH=/u01/app/oracle/rman_bak
    LEVEL=$@
    TARGET_SID=emar
    RMAN_SID=emar.emar
    BIN=/u01/app/oracle/db10g/bin
    # Delete the data backuped last time
    rm -rf $BACKUP_PATH/data/$DATE/*

    if [ $# != 1 ]; then
    echo "usage: rman_bak.sh n
    where n is the rman backup level(0,1,2 is permitted)."
    exit 1
    fi
    if [ $@ -ne 0 -a $@ -ne 1 -a $@ -ne 2 ]; then
    echo "usage: rman_bak.sh n
    where n is the rman backup level(Only 0,1,2 is permitted)."
    exit 2
    fi
    echo "-----------------------------start-----------------------------";date
    if [ $LEVEL = 0 ]; then
    $BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <<EOF
    connect target sys/sys202;
    connect catalog rman/rman@$RMAN_SID;
    resync catalog;
    run{
    allocate channel c1 type disk ;
    crosscheck backupset of archivelog all ;
    backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t'(archivelog from time 'sysdate-7' all delete input) ;
    delete noprompt expired backupset of archivelog all ;
    release channel c1 ;
    }

    run{
    allocate channel c2 type disk ;
    crosscheck backupset of database ;
    backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t'(database include current controlfile) ;
    delete noprompt expired backupset of database ;
    delete noprompt obsolete ;
    release channel c2 ;
    }
    exit;
    EOF

    else
    $BIN/rman log $BACKUP_PATH/log/level.$TARGET_SID.$LEVEL.$DATE_2.log <<EOF
    connect target sys/sys202;
    connect catalog rman/rman@$RMAN_SID;
    resync catalog;
    run{
    allocate channel c1 type disk ;
    crosscheck backupset of archivelog all ;
    backup filesperset 3 format '$BACKUP_PATH/data/$DATE/arch.%d.live.$LEVEL.%t' (archivelog from time 'sysdate-1' all) ;
    delete noprompt expired backupset of archivelog all ;
    release channel c1 ;
    }

    run{
    allocate channel c2 type disk ;
    crosscheck backupset of database ;
    backup incremental level $LEVEL filesperset 3 format '$BACKUP_PATH/data/$DATE/data.%d.live.$LEVEL.%t' (database include current controlfile) ;
    delete noprompt expired backupset of database ;
    delete noprompt obsolete ;
    release channel c2 ;
    }

    exit;
    EOF

    fi
    $BIN/exp rman/rman@$RMAN_SID file=$BACKUP_PATH/data/$DATE/live.rman.$DATE_2.dmp log=$BACKUP_PATH/log/$RMAN_SID.rman.$DATE_2.log
    echo "------------------------------end------------------------------";date

     

  • 相关阅读:
    聊聊Senior .net 面试,作为面试官你称职吗
    使用Microsoft BizTalk Adapter for mySAP Business Suite需要注意的一些限制点
    eos账号管理
    如何安装以太坊钱包Parity
    Infoq主办 Baidu Web 开发者大会记录
    http请求的详细过程转载
    php 下载保存文件保存到本地
    php section
    用javascript拼接html代码标签
    php使用sql数据库 取得字段问题
  • 原文地址:https://www.cnblogs.com/chinaops/p/13587700.html
Copyright © 2020-2023  润新知