利用RMAN备份复制数据库

时间:2021-03-23 20:39:55

一、在oracle数据open状态下,用rman备份

rman备份必须在归档模式下

查看是否是归档模式

SQL> archivelog list;

修改为归档模式

shutdown immediate

startup mount

alter database archivelog;(alter database noarchivelog)

 

  1、在第三台机器上用rman连接源数据库

 rman target sys/sysdba@demo1

2、启动自动备份

RMAN> configure controlfile autobackup on;

3、备份

RMAN> backup database plus archivelog delete input format '/u01/rmanbackup/dup_%U';

4、查看备份情况

RMAN> list backup;

5、拷贝spfile和口令文件到dbs下,并建立init+实例名.ora

输入

db_name=实例名

例如:db_name='demo1'

6.把生成的rman备份拷贝到相应的目录

7.启动目标数据库到nomount状态

startup nomount

8.在连接主机上建立dup.txt

输入

run {
    allocate auxiliary channel dup1 type disk;
    duplicate database to demo1 spfile backup location '/u01/rmanbackup' nofilenamecheck
    logfile
      group 1 ('/u01/app/oracle/oradata/redo01_1.rdo','/u01/app/oracle/oradata/redo01_2.rdo') size 52428800,
      group 2 ('/u01/app/oracle/oradata/redo02_1.rdo','/u01/app/oracle/oradata/redo02_2.rdo') size 52428800,
      group 3 ('/u01/app/oracle/oradata/redo03_1.rdo','/u01/app/oracle/oradata/redo03_2.rdo') size 52428800;
}

 

9.用rman连接数据库

RMAN> connect auxiliary sys/sysdba@linux4demo1

10.执行脚本

RMAN>@dup.txt

 

11.当执行出错时及某个进程不能启动时,执行

[oracle@localhost u01]$ ipcs

[oracle@localhost u01]$ ipcrm -s semid

 

12.第三方连接目标数据库时,需静态注册

listener.ora中

追加

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME=demo1)
      (ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1)
      (SID_NAME=demo1)
    )
  )

第三方客户端

tnsnames.ora中

追加:

LINUX4DEMO1=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.100)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = demo1)
    )
  )