zoukankan      html  css  js  c++  java
  • ORACLE热备复制数据库全记录(可以修改数据库名和数据文件路径)

    oralce热备是最简单,速度最快的数据库复制方法,以下是我的全部记录:
    ---------------------------------------------------------------------------------------------------------------------------------
    计划通过热备的方式,把*.*.*.240上SGPMDB,复制到*.*.201.180上去,新库的SID为SGTESTB

    首先在180上用oracle创建一样的目录,用来存放240的全库备份文件

    创建一个密码文件
    orapwd FILE=/oracle/base/product/10.2.0/db_1/dbs/orapwdSGTESTB PASSWORD=oracle ENTRIES=30

    准备一个pfileSGTESTB.ora
    DB_NAME=SGTESTB
    db_block_size=8192
    compatible=10.2.0.3.0
    shared_pool_size=500M
    db_file_name_convert=('/app/oracle/base/oradata/SGPMDB','/oracle/base/oradata/SGTESTB') ;
    log_file_name_convert=('/app/oracle/base/admin/SGPMDB/arch','/oracle/base/admin/SGTESTB/arch') ;


    在源库上执行
    alter database begin backup;

    select 'get '||substr(name,instr(name,'/',-1)+1),
    'put '||name||' /oracle/base/oradata/SGTESTB/'||substr(name,instr(name,'/',-1)+1),bytes
    from v$datafile;

    --ftp数据文件
    put /app/oracle/base/oradata/SGPMDB/system01.dbf /oracle/base/oradata/SGTESTB/system01.dbf
    put /app/oracle/base/oradata/SGPMDB/undotbs01.dbf /oracle/base/oradata/SGTESTB/undotbs01.dbf
    put /app/oracle/base/oradata/SGPMDB/sysaux01.dbf /oracle/base/oradata/SGTESTB/sysaux01.dbf
    put /app/oracle/base/oradata/SGPMDB/users01.dbf /oracle/base/oradata/SGTESTB/users01.dbf
    put /app/oracle/base/oradata/SGPMDB/DATA_A001.DBF /oracle/base/oradata/SGTESTB/DATA_A001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_C001.DBF /oracle/base/oradata/SGTESTB/DATA_C001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_D001.DBF /oracle/base/oradata/SGTESTB/DATA_D001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_M001.DBF /oracle/base/oradata/SGTESTB/DATA_M001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_R001.DBF /oracle/base/oradata/SGTESTB/DATA_R001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_O001.DBF /oracle/base/oradata/SGTESTB/DATA_O001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_E001.DBF /oracle/base/oradata/SGTESTB/DATA_E001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_G001.DBF /oracle/base/oradata/SGTESTB/DATA_G001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_P001.DBF /oracle/base/oradata/SGTESTB/DATA_P001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_S001.DBF /oracle/base/oradata/SGTESTB/DATA_S001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_A001.DBF /oracle/base/oradata/SGTESTB/IDX_A001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_C001.DBF /oracle/base/oradata/SGTESTB/IDX_C001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_D001.DBF /oracle/base/oradata/SGTESTB/IDX_D001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_M001.DBF /oracle/base/oradata/SGTESTB/IDX_M001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_R001.DBF /oracle/base/oradata/SGTESTB/IDX_R001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_O001.DBF /oracle/base/oradata/SGTESTB/IDX_O001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_E001.DBF /oracle/base/oradata/SGTESTB/IDX_E001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_G001.DBF /oracle/base/oradata/SGTESTB/IDX_G001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_P001.DBF /oracle/base/oradata/SGTESTB/IDX_P001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_S001.DBF /oracle/base/oradata/SGTESTB/IDX_S001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_MAN001.DBF /oracle/base/oradata/SGTESTB/DATA_MAN001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_MAN001.DBF /oracle/base/oradata/SGTESTB/IDX_MAN001.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_SGPM.DBF /oracle/base/oradata/SGTESTB/DATA_SGPM.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_Y.DBF /oracle/base/oradata/SGTESTB/DATA_Y.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_Y.DBF /oracle/base/oradata/SGTESTB/IDX_Y.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_OUT.DBF /oracle/base/oradata/SGTESTB/DATA_OUT.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_OUT.DBF /oracle/base/oradata/SGTESTB/IDX_OUT.DBF
    put /app/oracle/base/oradata/SGPMDB/DATA_ARC001.DBF /oracle/base/oradata/SGTESTB/DATA_ARC001.DBF
    put /app/oracle/base/oradata/SGPMDB/IDX_ARC001.DBF /oracle/base/oradata/SGTESTB/IDX_ARC001.DBF
    put /app/oracle/base/oradata/SGPMDB/pa_data01.dbf /oracle/base/oradata/SGTESTB/pa_data01.dbf
    put /app/oracle/base/oradata/SGPMDB/pa_index01.dbf /oracle/base/oradata/SGTESTB/pa_index01.dbf

    alter database end backup;

    通过在sqlplus上执行archive log list命令获取当前的日志顺序号,
    从oldest online log sequence开始到current log sequence的联机redo日志应该是热备份的一部分。
    SQL> archive log list ;
    Database log mode              Archive Mode
    Automatic archival             Enabled
    Archive destination            /app/oracle/base/admin/SGPMDB/arch
    Oldest online log sequence     10131
    Next log sequence to archive   10133
    Current log sequence           10133


    在sqlplus上执行 alter system switch logfile;     命令来强迫日志切换,以便所有的日志都被归档。

    使用alter database backup controlfile to trace;命令获得控制文件的一个备份,
    可以到%oracle_base%\admin\%oracle_sid%\udump目录中寻找最新的跟踪文件,其中有重建控制文件的全部命令。

    alter database backup controlfile to trace resetlogs;

    select value||'/'||
    (select instance_name from v$instance)
    ||'_ora_'||spid||'.trc' from v$process,v$parameter where
    name='user_dump_dest' and addr=(select paddr from v$session where sid=(select sid
    from v$mystat where rownum=1));

    获取trace文件查看控制文件创建信息     /app/oracle/base/admin/SGPMDB/udump/SGPMDB_ora_30797.trc

    拷贝归档的日志文件到目标库相应目录。
    select * from v$archived_log;
    sgpmdb_10132_1_652109004.arch  sgpmdb_10133_1_652109004.arch

    put /app/oracle/base/admin/SGPMDB/arch/sgpmdb_10132_1_652109004.arch /oracle/base/admin/SGTESTB/arch/sgpmdb_10132_1_652109004.arch
    put /app/oracle/base/admin/SGPMDB/arch/sgpmdb_10133_1_652109004.arch /oracle/base/admin/SGTESTB/arch/sgpmdb_10133_1_652109004.arch


    在目标库上启动辅助实例
    export ORACLE_SID=SGTESTB
    sqlplus / as sysdba
    STARTUP NOMOUNT PFILE='/oracle/base/admin/SGTESTB/pfile/pfileSGTESTB.ora'


    在控制文件备份中,有创建控制文件的脚本
    CREATE CONTROLFILE set DATABASE "SGTESTB" RESETLOGS  ARCHIVELOG
        MAXLOGFILES 16
        MAXLOGMEMBERS 3
        MAXDATAFILES 100
        MAXINSTANCES 8
        MAXLOGHISTORY 4672
    LOGFILE
      GROUP 1 '/oracle/base/oradata/SGTESTB/redo01.log'  SIZE 50M,
      GROUP 2 '/oracle/base/oradata/SGTESTB/redo02.log'  SIZE 50M,
      GROUP 3 '/oracle/base/oradata/SGTESTB/redo03.log'  SIZE 50M
    -- STANDBY LOGFILE
    DATAFILE
    '/oracle/base/oradata/SGTESTB/system01.dbf',
    '/oracle/base/oradata/SGTESTB/undotbs01.dbf',
    '/oracle/base/oradata/SGTESTB/sysaux01.dbf',
    '/oracle/base/oradata/SGTESTB/users01.dbf',
    '/oracle/base/oradata/SGTESTB/DATA_A001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_C001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_D001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_M001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_R001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_O001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_E001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_G001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_P001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_S001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_A001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_C001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_D001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_M001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_R001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_O001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_E001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_G001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_P001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_S001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_MAN001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_MAN001.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_SGPM.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_Y.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_Y.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_OUT.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_OUT.DBF',
    '/oracle/base/oradata/SGTESTB/DATA_ARC001.DBF',
    '/oracle/base/oradata/SGTESTB/IDX_ARC001.DBF',
    '/oracle/base/oradata/SGTESTB/pa_data01.dbf',
    '/oracle/base/oradata/SGTESTB/pa_index01.dbf'
    CHARACTER SET UTF8
    ;

    在目标机上指明归档日志的位置
    SQL> alter system set log_archive_dest='/oracle/base/admin/SGTESTB/arch' ;

    登录RMAN,让RMAN识别到归档日志
    RMAN> catalog start with '/oracle/base/admin/SGTESTB/arch';

    RMAN> recover database;
    Starting recover at 17-AUG-09
    using channel ORA_DISK_1

    starting media recovery

    archive log thread 1 sequence 10133 is already on disk as file /oracle/base/admin/SGTESTB/arch/sgpmdb_10133_1_652109004.arch
    archive log filename=/oracle/base/admin/SGTESTB/arch/sgpmdb_10133_1_652109004.arch thread=1 sequence=10133
    unable to find archive log
    archive log thread=1 sequence=10134
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of recover command at 08/17/2009 11:26:56
    RMAN-06054: media recovery requesting unknown log: thread 1 seq 10134 lowscn 10110329200744

    没有更新的日志,到此就恢复完成,可以打开库了

    重设日志打开
    RMAN> alter database open resetlogs;


    增加临时表空间
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oracle/base/oradata/SGTESTB/temp01.dbf'
         SIZE 50M  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;

    复制控制文件,并且在pfile里面指定
    然后重新根据pfile生成spfile,并且修改/etc/oratab
    *.audit_file_dest='/oracle/base/admin/SGTESTB/adump'
    *.background_dump_dest='/oracle/base/admin/SGTESTB/bdump'
    *.compatible='10.2.0.3.0'
    *.control_files='/oracle/base/oradata/SGTESTB/control01.ctl','/oracle/base/oradata/SGTESTB/control02.ctl','/oracle/base/oradata/SGTESTB/control03.ctl'
    *.core_dump_dest='/oracle/base/admin/SGTESTB/cdump'
    *.db_block_size=8192
    *.db_domain=''
    *.db_file_multiblock_read_count=16
    *.db_name='SGTESTB'
    *.db_recovery_file_dest_size=2147483648
    *.db_recovery_file_dest=''
    *.log_archive_dest='/oracle/base/admin/SGTESTB/arch'
    *.nls_language='SIMPLIFIED CHINESE'
    *.processes=300
    *.undo_management='AUTO'
    *.undo_tablespace='UNDOTBS1'
    *.user_dump_dest='/oracle/base/admin/SGTESTB/udump'
    *.sga_max_size=1048576000
    *.sga_target=1048576000

    STARTUP PFILE='/oracle/base/admin/SGTESTB/pfile/pfileSGTESTB.ora' ;

    创建SPFILE:
    CREATE SPFILE FROM PFILE='/oracle/base/admin/SGTESTB/pfile/pfileSGTESTB.ora';

  • 相关阅读:
    JAVA中的SimpleDateFormat yyyy和YYYY的区别
    Mysql的MVCC
    SELECT语句中的for update的用法(锁的运用)
    今天简单说一下cdc 的使用
    sqlserver cdc用法
    JAVA | Java对象的内存分配过程是如何保证线程安全的?
    物联网(莹石云)WIFI一键配置原理分析(zz)
    Dell xps 13 9350待机时总是关机的处理方法
    Vue系列:在vux的popup组件中使用百度地图遇到显示不全的问题
    如何通过百度地图将经纬度转换为地址信息
  • 原文地址:https://www.cnblogs.com/caibird2005/p/1548246.html
Copyright © 2011-2022 走看看