Home >Database >Mysql Tutorial >Oracle技术之用RMAN克隆数据库

Oracle技术之用RMAN克隆数据库

WBOY
WBOYOriginal
2016-06-07 17:30:221040browse

源库RHEL4.5:192.168.137.199 GLOBAL_NAME=WENDING.LK Oracle_SID=WENDING 克隆库RHEL4.5:192.168.137.200 GLOBAL_NAME=STRM.L

源库RHEL4.5:192.168.137.199 GLOBAL_NAME=WENDING.LK Oracle_SID=WENDING

克隆库RHEL4.5:192.168.137.200 GLOBAL_NAME=STRM.LK ORACLE_SID=STRM

1. 全备份源库

$ sqlplus '/as sysdba'

记下备份前的SCN,规复的时间就规复到这个点。

SQL> select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

181557

SQL> exit

$ mkdir -p /orahome/backup

$ cd /orahome

$ vi backup.rcv

run{

allocate channel c1 type disk;

backup full database format '/orahome/backup/db_t%t_s%s_p%p.bak';

backup archivelog all format '/orahome/backup/arch_u%u.bak';

backup current controlfile format '/orahome/backup/cf_u%u.bak';

release channel c1;

}

$ nohup rman target / @backup.rcv log backup.log &

$ tail -50f backup.log

参照源库参数文件新建一个克隆库参数文件:

SQL> create pfile = '/orahome/backup/initSTRM.ora' from spfile;

得到源库数据文件的编号和寄放职位 信息,是为了预备克隆库参数db_file_name_convert或rman规复时set newname的设置:

$ sqlplus '/as sysdba'

SQL> col name format a60

SQL> set lines 1024

SQL> select file#,name from v$datafile union all select file#,name from v$tempfile;

FILE# NAME

---------- ------------------------------------------------------------

1 /orahome/oradata/WENDING/system.dbf

2 /orahome/oradata/WENDING/undotbs1.dbf

3 /orahome/oradata/WENDING/sysaux.dbf

4 /orahome/oradata/WENDING/users01.dbf

1 /orahome/oradata/WENDING/temp01.dbf

SQL> exit

拷贝备份文件到克隆库主机的同一职位 ,确保克隆库主机也有目次 /orahome/backup。

$ cd /orahome/backup

$ scp *.bak 192.168.137.200:/orahome/backup

$ scp initSTRM.ora 192.168.137.200:/orahome/backup

2. 克隆库预备事变

克隆库上设置干系 的环境 变量:

$ vi .bash_profile (思量 从源库主机拷贝一份,,然后批改ORACLE_SID参数值)

export ORACLE_BASE=/u01/app/oracle;

export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1;

export ORACLE_SID=STRM;

export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"

export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

$ . .bash_profile

3. 批改克隆库参数文件

$ vi /orahome/backup/initSTRM.ora

:%s/WENDING/STRM/g

一样平常批改以下参数:

audit_file_dest,background_dump_dest,core_dump_dest,user_dump_dest,db_name,db_unique_name,log_archive_dest_1,control_files.

并确保以下参数:

*.remote_login_passwordfile = exclusive

*.DB_FILE_NAME_CONVERT = '/orahome/oradata/WENDING/', '/orahome/oradata/STRM/'

4. 按照步调 3批改的路径信息在克隆库主机新建须要的目次

$ mkdir -p /orahome/flash_recovery_area

$ mkdir -p /orahome/arch/STRM

$ mkdir -p /orahome/oradata/STRM/

$ mkdir -p /u01/app/oracle/admin/STRM/adump

mkdir -p /u01/app/oracle/admin/STRM/bdump

mkdir -p /u01/app/oracle/admin/STRM/cdump

mkdir -p /u01/app/oracle/admin/STRM/dpdump

mkdir -p /u01/app/oracle/admin/STRM/udump

5. 在克隆库创建 一个新的password文件

(unix/Linux下暗码文件技俩必需是orapw

$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=iamwangnc force=y

6. 克隆库startup nomount

$ sqlplus '/as sysdba'

SQL> create spfile from pfile='/orahome/backup/initSTRM.ora';

SQL> startup nomount;

SQL> exit

7. 克隆库用rman规复

$ cd /orahome

$ vi recover.rcv (由于源库在全备后还也许发生归档文件,以是规复的时间要设置set until值,不然会发生过错 RMAN-06025)

run{

allocate auxiliary channel c1 type disk;

# set until time '2008-11-21.11:33:31';

# set until sequence 21254 thread 1;

set until scn 181557;

duplicate target database to STRM

LOGFILE

group 1 ('/orahome/oradata/STRM/REDO01.DBF') SIZE 50M,

group 2 ('/orahome/oradata/STRM/REDO02.DBF') SIZE 50M,

group 3 ('/orahome/oradata/STRM/REDO03.DBF') SIZE 50M;

}

其它set newname和LOGFILE后头的文件职位 信息可以按照本身必要 设定。

起头规复:(wending.lk是源库做事名,确保源库的监听已经启动)

$ nohup rman target sys/iamwangnc@192.168.137.199:1521/wending.lk auxiliary / @recover.rcv log recover.log &

$ tail -50f recover.log

database opened

Finished Duplicate Db at 2008-11-21 13:02:39

规复数据库时发生如下过错:RMAN-06025: no backup of log thread 1 seq 21255 scn 4144283685 found to restore

多次执行备份﹐然后克隆﹐发现有时候出错﹐有时候不出错。非常费解。后来在仔细观察发现,在短缺末了一个归档日记文件会出错。而这个日记文件是在备份之后产

生的﹐目标数据的备份中没有。把这个文件传递到目标主机就可以了。而假如产生备份之后﹐短时间之内克隆﹐原数据库没有归档文件﹐则不会出现错误。这个在很多

操纵文档中﹐没有讲到。

8. 测试克隆库

$ sqlplus '/as sysdba'

SQL> select status from v$instance;

SQL> archive log list;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn