迁移: (10g 64老机器,老存储) ------》(11g 64新机器,新存储)
注意要点:新老服务的时间,字符集,sid
升级顺序:10.2.0.1------>10.2.0.4或10.2.0.5---->11.2.0.1

新机器上安装2套oracle 目标11G数据库软件 和10g oracle软件
操作步骤完全一样,当 新库10g能打开时,关库,让新库11g 以 升级模式打开,升级库,即可

old:
1.关闭监听,和业务连接。先做全库备份:
lsnrctl stop
sqlplus as sysdba
alter system switch logfile;
alter system switch logfile;
$ rman target / log=/home/oracle/rman/log/dqianyi_rman.log
RMAN> backup database format '/home/oracle/backup/full_%d_%T_%s_%p.bak';

2.确定位置名称:
SQL> select file#,ts#,name from v$datafile;

FILE# TS# NAME
---------- ---------- ---------------------------------------------
1 0 /u01/app/ora10g/oradata/ora10g/system01.dbf
2 1 /u01/app/ora10g/oradata/ora10g/undotbs01.dbf
3 2 /u01/app/ora10g/oradata/ora10g/sysaux01.dbf
4 4 /u01/app/ora10g/oradata/ora10g/users01.dbf

3.备份数据文件,参数文件,控制文件
写成脚本:
[oracle@k214 log]$ cat x.sh
#!/bin/bash
rman target / log=/home/oracle/rman/log/1qianyi_rman.log << EOF
run
{allocate channel c1 type disk;
allocate channel c2 type disk;
copy
datafile '/u01/app/ora10g/oradata/ora10g/system01.dbf' to '/u01/new/system01.dbf',
datafile '/u01/app/ora10g/oradata/ora10g/undotbs01.dbf' to '/u01/new/undotbs01.dbf',
datafile '/u01/app/ora10g/oradata/ora10g/sysaux01.dbf' to '/u01/new/sysaux01.dbf',
datafile '/u01/app/ora10g/oradata/ora10g/users01.dbf' to '/u01/new/users01.dbf';
}
EOF

============================
备份控制文件
sqlplus / as sysdba
alter database backup controlfile to trace as '/home/oracle/new_ctl.sql';
RMAN> BACKUP CURRENT CONTROLFILE format '/home/oracle/arch/con_%d_%T_%s_%p.ctl'; --这步不需要
=============================

4. 打包数据文件并远程拷贝:
cd /u01
zip -qr new.zip new
scp -P22 /u01/new.zip 192.168.0.215:/u01/

下面5.6都是中断时间
5.备份归档 然后关机(关机开始中断)
#!/bin/bash
rman target / nocatalog log /home/oracle/rman/log/rman_arch.log append<<EOF
run
{allocate channel c1 type disk;
backup archivelog all format '/home/oracle/arch/arch_%d_%T_%s_%p';
}
shutdown immediate //备份归档可以分多次去做,但是最后一次做完要关机
EOF

6.打包和远程拷贝:
cd /home/oracle/
zip -qr arch.zip arch
scp -P22 /home/oracle/arch.zip 192.168.0.215:/u02/backup/

#7.拷贝redo 到new机器存储上
scp /u01/app/ora10g/oradata/ora10g/red* 192.168.0.215:/u01/new/
可以拷贝多次,最关键的就是最后一次。

===================================================================

new:
安装完11g 64 oracle软件,还没有建库,但是已经有监听了。
1.解压数据文件包和归档文件包
su - oracle
cd /u01 ;unzip new.zip
cd /u02/backup/ ;unzip arch.zip

2.修改参数文件并建立目录:
cat /u01/app/oracle/dbs/new.ora
orcl.__db_cache_size=67108864
orcl.__java_pool_size=4194304
orcl.__large_pool_size=4194304
orcl.__oracle_base='/u01/app'#ORACLE_BASE set from environment
orcl.__pga_aggregate_target=146800640
orcl.__sga_target=276824064
orcl.__shared_io_pool_size=0
orcl.__shared_pool_size=130023424
orcl.__streams_pool_size=8388608
*.audit_file_dest='/u01/app/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/new/control01.ctl','/u01/new/control02.ctl','/u01/new/control03.ctl'
*.db_2k_cache_size=52428800
*.db_block_size=8192
*.db_domain=''
*.db_name='ora10g'
*.db_recovery_file_dest='/u01/app/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/u01/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_dest_1='location=/u01/backup/arch'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=422576128
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'

建立目录:
mkdir -p /u01/backup/arch
mkdir -p /u01/app/admin/orcl/adump
mkdir -p /u01/app/flash_recovery_area

3.启动oracle 到mount
SQL> startup nomount pfile=/u01/app/oracle/dbs/new.ora;

====================================

主库备份:
全部备份文件放在一个路径,顺序是 数据文件,归档,控制文件。
1.库全备:
backup database format='/home/oracle/rman/%U_%s.bak';
alter system archive log current
alter system switch logfile

2.归档全备:
BACKUP ARCHIVELOG ALL format='/home/oracle/rman/%U_%s.arc';
BACKUP ARCHIVELOG 命令比较灵活, ALL 是指备份当前所有可访问到的归档文件,你还可以通过 UNTIL 、 SCN 、 TIME 、 SEQUENCE 等参数灵活指定要备份的归档区间,这里不再一一演示,感兴趣的朋友可以自行尝试。

3.控制文件备份:
BACKUP CURRENT CONTROLFILE format='/home/oracle/rman/%U_%s.ctl';

cd /home/oracle
zip -qr rman.zip rman
scp rman.zip k101:/home/oracle/

备库:
存放rman备份集合的地方和主库一致(因为在修复控制文件后,修复数据库(restore)和恢复数据库(recover,需要归档的)这个时候通过控制文件找到响应的路径(主库所在的路径)
su- oracle
[oracle@k101 ~]$unzip rman.zip
[oracle@k101 rman]$ cd /home/oracle/rman
[oracle@k101 rman]$ ll
total 310428
-rw-r----- 1 oracle oinstall 291266560 Oct 9 02:13 01pkjad1_1_1_1.bak
-rw-r----- 1 oracle oinstall 7143424 Oct 9 02:13 02pkjadq_1_1_2.bak
-rw-r----- 1 oracle oinstall 12023296 Oct 9 02:32 03pkjbhr_1_1_3.arc
-rw-r----- 1 oracle oinstall 7110656 Oct 9 02:35 04pkjboa_1_1_4.ctl
rman>restore controlfile from '/home/oracle/rman/04pkjboa_1_1_4.ctl';
SQL>alter database mount;
rman>restore database from '/home/oracle/rman/04pkjboa_1_1_4.ctl';
RMAN> restore database; //修复数据库文件
RMAN> recover database; //先自动修复归档,然后恢复数据库文件,这里将报错
看报错信息,能看到rman归档追加到多少号了

=====================================

4.手动建立控制文件(由于之前远程拷贝redo,因此可以顺利打开):
SQL>CREATE CONTROLFILE REUSE DATABASE "ORA10G" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/new/redo01.log' SIZE 50M,
GROUP 2 '/u01/new/redo02.log' SIZE 50M,
GROUP 3 '/u01/new/redo03.log' SIZE 50M
DATAFILE
'/u01/new/system01.dbf',
'/u01/new/undotbs01.dbf',
'/u01/new/sysaux01.dbf',
'/u01/new/users01.dbf'
CHARACTER SET ZHS16GBK
;

确定数据库是否为mount状态:
SQL> select status from v$instance;

STATUS
------------
STARTED

SQL> alter database mount;
Database altered.

5.建立spfile
SQL> create spfile from pfile='/u01/app/oracle/dbs/new.ora';
SQL>shutdown abort
SQL> startup;
Database mounted.
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/u01/new/system01.dbf'

6.让数据库识别新的rman备份集位置:
[oracle@k215 arch]$ rman target / log=/home/oracle/rman/log/know_qianyi_rman.log
RMAN> catalog start with '/u02/backup/arch/';

7.解压归档:
RMAN>recover database; //会报错,但是会自动解压归档

8.有了归档,就可以进行常规介质恢复:
SQL> recover database using backup controlfile until cancel;
/u01/backup/arch/1_16_860079637.dbf
SQL> recover database using backup controlfile until cancel;
/u01/new/redo01.log
SQL> recover database using backup controlfile until cancel;
/u01/new/redo02.log
SQL> recover database using backup controlfile until cancel;
/u01/new/redo03.log

Log applied.
Media recovery complete.

9.升级数据库(10.2.0.1------>10.2.0.4或10.2.0.5---->11.2.0.1):
SQL> alter database open resetlogs upgrade;
SQL> shutdown immediate;
SQL> startup upgrade;
SQL> spool /home/oracle/patch.log
SQL> @?/rdbms/admin/catupgrd.sql
SQL> spool off

SQL> startup(数据库可以正常启动) 在运行下面的脚本(重新编译PL/SQL包,使其能够被使用)
SQL> @ /rdbms/admin/utlrp.sql

10.全备

=============
alter database rename file '/u02/app/PROD/oradata/PROD/redo01.log' to '/u01/app/PROD/oradata/PROD/redo01.log';
alter database rename file '/u02/app/PROD/oradata/PROD/redo02.log' to '/u01/app/PROD/oradata/PROD/redo02.log';
alter database rename file '/u02/app/PROD/oradata/PROD/redo03.log' to '/u01/app/PROD/oradata/PROD/redo03.log';

alter database rename file '/u02/app/PROD/oradata/PROD/users01.dbf'to '/home/oracle/datafile/users01.dbf';
alter database rename file '/u02/app/PROD/oradata/PROD/sysaux01.dbf' to '/home/oracle/datafile/sysaux01.dbf';
alter database rename file '/u02/app/PROD/oradata/PROD/undotbs01.dbf'to '/home/oracle/datafile/undotbs01.dbf';
alter database rename file '/u02/app/PROD/oradata/PROD/system01.dbf'to '/home/oracle/datafile/system01.dbf';
alter database rename file '/u02/app/PROD/oradata/PROD/example01.dbf'to '/home/oracle/datafile/example01.dbf';

04-13 09:52