您的位置:首页 > 数据库 > Oracle

oracle11g 从云上迁移落到本地

2016-04-06 22:15 281 查看




1,在azure上开始备份

以前因为测试环境服务器不够,所以在云上临时分配了几台oracle服务器,现在从idc退回了几台性能好的db服务器,所以要将云上临时分片的oracle迁移到退回的这几台服务器上。

先在云上进行rman全备份:
[root@yueworldoracle ~]# bash -x /oracle/backup/scripts/rman_full_backup.sh
++ date +%F
+ export DATE=2016-04-05
+ DATE=2016-04-05
+ export BACK_DIR=/data/backup/data
+ BACK_DIR=/data/backup/data
+ su - oracle -c '
mkdir -p /data/backup/data/2016-04-05
rman log=/data/backup/data/2016-04-05/rman_backup.log target / <<EOF
run{
backup as compressed backupset database
format '\''/data/backup/data/2016-04-05/full_%d_%T_%s.bak'\''
plus archivelog
format '\''/data/backup/data/2016-04-05/arch_%d_%T_%s.bak'\'' delete input;
sql '\''alter system archive log current'\'';
}
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
exit
EOF
'
RMAN> 2> 3> 4> 5> 6> 7> RMAN> RMAN> RMAN> RMAN> RMAN> RMAN> + su - oracle -c '
chmod 775 /data/backup/data/2016-04-05/*
'
+ echo 'begin to copy the backup to pd servers.'
+ echo 'end to copy the backup to pd server.'
[root@yueworldoracle ~]#

2,重新备份控制文件

查看备份控制文件,发现在backup集合中没有找到:
RMAN> list backup of spfile;

using target database control file instead of recovery catalog
specification does not match any backup in the repository

RMAN>

原blog地址:/article/7189729.html ,原作者mchdba(黄杉)谢绝转载。

所以自己手动备份一个:
RMAN> backup current controlfile;

Starting backup at 05-APR-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=45 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 05-APR-16
channel ORA_DISK_1: finished piece 1 at 05-APR-16
piece handle=/oracle/app/oracle/flash_recovery_area/PDUNQ/backupset/2016_04_05/o1_mf_ncnnf_TAG20160405T225847_cj7noc77_.bkp tag=TAG20160405T225847 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 05-APR-16

Starting Control File and SPFILE Autobackup at 05-APR-16
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03009: failure of Control File and SPFILE Autobackup command on ORA_DISK_1 channel at 04/05/2016 22:58:57
ORA-19504: failed to create file "/pddata2/oracle/backup/data/ctl_auto/c-3391761643-20160405-01"
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 9

RMAN>
再去插看备份文件,就可以找到了:
RMAN> list backup of controlfile;

List of Backup Sets
===================

BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
5243 Full 18.33M DISK 00:00:06 05-APR-16
BP Key: 5247 Status: AVAILABLE Compressed: NO Tag: TAG20160405T225847
Piece Name: /oracle/app/oracle/flash_recovery_area/PDUNQ/backupset/2016_04_05/o1_mf_ncnnf_TAG20160405T225847_cj7noc77_.bkp
Control File Included: Ckp SCN: 11981165464 Ckp time: 05-APR-16

RMAN>

3,备份参数文件

SQL> create pfile='/oracle/pfile_20160405.ora' from spfile;

File created.

SQL>

4,进行备份文件传输

因为是azure云环境传输到自己机房,所以未来防止网络传输过程中小文件被丢失的情况,先把所有的备份文件都统一copy到2016-04-05文件夹里面去,然后进行压缩:tar -zcvf 2016-04-05.tar.gz 2016-04-05,然后进行传输一个大大的压缩包即可,这样能保证传输过程的安全和稳定,如下所示:
[root@yueworldoracle data]# tar -zcvf 2016-04-05.tar.gz 2016-04-05
2016-04-05/
2016-04-05/arch_POWERDES_20160405_5593.bak
2016-04-05/full_POWERDES_20160405_5595.bak
2016-04-05/arch_POWERDES_20160405_5594.bak
2016-04-05/rman_backup.log
2016-04-05/arch_POWERDES_20160405_5591.bak
2016-04-05/arch_POWERDES_20160405_5596.bak
2016-04-05/arch_POWERDES_20160405_5592.bak
2016-04-05/arch_POWERDES_20160405_5590.bak
[root@yueworldoracle data]#
[root@yueworldoracle data]# time scp /data/backup/data/2016-04-05.tar.gz oracle@192.168.121.61:/oracle/
oracle@192.168.121.61's password:
2016-04-05.tar.gz 100% 10GB 6.1MB/s 28:55

real 28m57.412s
user 1m1.240s
sys 0m27.539s
You have new mail in /var/spool/mail/root
[root@yueworldoracle data]#
以下都在待恢复的oracle服务器上操作:

5,在恢复的oracle服务器上以nomount方式启动数据库

先进行解压缩:
[root@chhj_test_121_61 oradata]# tar -xvf 2016-04-05.tar.gz
2016-04-05/
2016-04-05/arch_POWERDES_20160405_5593.bak
2016-04-05/full_POWERDES_20160405_5595.bak
2016-04-05/arch_POWERDES_20160405_5594.bak
2016-04-05/rman_backup.log
2016-04-05/arch_POWERDES_20160405_5591.bak
2016-04-05/arch_POWERDES_20160405_5596.bak
2016-04-05/arch_POWERDES_20160405_5592.bak
2016-04-05/arch_POWERDES_20160405_5590.bak
[root@chhj_test_121_61 oradata]#
然后开始利用备份的参数文件启动oracle到nomount:
SQL> startup nomount pfile='/oracle/pfile_20160405.ora';
ORACLE instance started.

Total System Global Area 1.1358E+10 bytes
Fixed Size 2216744 bytes
Variable Size 7650413784 bytes
Database Buffers 3690987520 bytes
Redo Buffers 13946880 bytes
SQL>

6,恢复控制文件

RMAN> restore controlfile to '/home/oradata/powerdes/control01.ctl' from '/oracle/o1_mf_ncnnf_TAG20160405T225847_cj7noc77_.bkp' ;

Starting restore at 06-APR-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 06-APR-16

RMAN>

7,将数据库改成mount

RMAN> alter database mount;

database mounted
released channel: ORA_DISK_1

RMAN>

8,注册备份文件集

RMAN> catalog start with '/home/oradata/2016-04-05';

Starting implicit crosscheck backup at 06-APR-16
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1153 device type=DISK
Crosschecked 7 objects
Finished implicit crosscheck backup at 06-APR-16

Starting implicit crosscheck copy at 06-APR-16
using channel ORA_DISK_1
Crosschecked 2 objects
Finished implicit crosscheck copy at 06-APR-16

searching for all files in the recovery area
cataloging files...
no files cataloged

searching for all files that match the pattern /home/oradata/2016-04-05

List of Files Unknown to the Database
=====================================
File Name: /home/oradata/2016-04-05.tar.gz
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5592.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5596.bak
File Name: /home/oradata/2016-04-05/rman_backup.log
File Name: /home/oradata/2016-04-05/full_POWERDES_20160405_5595.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5590.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5594.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5593.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5591.bak

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5592.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5596.bak
File Name: /home/oradata/2016-04-05/full_POWERDES_20160405_5595.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5590.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5594.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5593.bak
File Name: /home/oradata/2016-04-05/arch_POWERDES_20160405_5591.bak

List of Files Which Where Not Cataloged
=======================================
File Name: /home/oradata/2016-04-05.tar.gz
RMAN-07517: Reason: The file header is corrupted
File Name: /home/oradata/2016-04-05/rman_backup.log
RMAN-07517: Reason: The file header is corrupted

RMAN>

9,开始执行restore恢复操作,将数据从备份集写入到磁盘上的数据文件里面,还原已经备份的数据文件

RMAN> restore database;

Starting restore at 06-APR-16
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /home/oradata/powerdes/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /home/oradata/powerdes/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /home/oradata/powerdes/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /home/oradata/powerdes/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /home/oradata/powerdes/powerdesk01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /home/oradata/powerdes/plas01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /home/oradata/powerdes/pl01.dbf
channel ORA_DISK_1: restoring datafile 00008 to /home/oradata/powerdes/help01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /home/oradata/powerdes/adobelc01.dbf
channel ORA_DISK_1: restoring datafile 00010 to /home/oradata/powerdes/sms01.dbf
channel ORA_DISK_1: restoring datafile 00011 to /home/oradata/powerdes/plcrm01.dbf
channel ORA_DISK_1: restoring datafile 00012 to /home/oradata/powerdes/powerdesk02.dbf
channel ORA_DISK_1: restoring datafile 00013 to /home/oradata/powerdes/datagm01.dbf
channel ORA_DISK_1: reading from backup piece /home/oradata/2016-04-05/full_POWERDES_20160405_5595.bak
channel ORA_DISK_1: piece handle=/home/oradata/2016-04-05/full_POWERDES_20160405_5595.bak tag=TAG20160405T204221
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:18:35
Finished restore at 06-APR-16

RMAN>

10,recover database应用归档日志恢复数据文件

开始recoverdatabase恢复:
RMAN> recover database;

Starting recover at 06-APR-16
using channel ORA_DISK_1

starting media recovery

channel ORA_DISK_1: starting archived log restore to default destination
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=301
channel ORA_DISK_1: restoring archived log
archived log thread=1 sequence=302
channel ORA_DISK_1: reading from backup piece /home/oradata/2016-04-05/arch_POWERDES_20160405_5596.bak
channel ORA_DISK_1: piece handle=/home/oradata/2016-04-05/arch_POWERDES_20160405_5596.bak tag=TAG20160405T222327
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
archived log file name=/oracle/app/oracle/flash_recovery_area/PDUNQ/archivelog/2016_04_06/o1_mf_1_301_cj7w0c0c_.arc thread=1 sequence=301
channel default: deleting archived log(s)
archived log file name=/oracle/app/oracle/flash_recovery_area/PDUNQ/archivelog/2016_04_06/o1_mf_1_301_cj7w0c0c_.arc RECID=85662 STAMP=908413453
archived log file name=/oracle/app/oracle/flash_recovery_area/PDUNQ/archivelog/2016_04_06/o1_mf_1_302_cj7w0c33_.arc thread=1 sequence=302
channel default: deleting archived log(s)
archived log file name=/oracle/app/oracle/flash_recovery_area/PDUNQ/archivelog/2016_04_06/o1_mf_1_302_cj7w0c33_.arc RECID=85661 STAMP=908413453
unable to find archived log
archived log thread=1 sequence=303
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 04/06/2016 01:04:18
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 303 and starting SCN of 11981163537

RMAN>
需要将缺失的归档日志从云上的原始备份库copy到本地自己机房的oracle服务器上,或者直接恢复到SCN点上:
RMAN> recover database until scn 11981163537;

Starting recover at 06-APR-16
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:01

Finished recover at 06-APR-16

RMAN>

11,开始打开数据库

RMAN> alter database open resetlogs;

database opened

RMAN>

12,验证测试数据库

做tnsname配置:
[oracle@chhj_test_121_61 admin]$ more tnsnames.ora
# tnsnames.ora Network Configuration File: /oracle/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

EARTH61 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.121.61)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = powerdes)
)
)

[oracle@chhj_test_121_61 admin]$
开始登录建表验证:
[oracle@chhj_test_121_61 admin]$ rlwrap sqlplus powerdesk/earthyueworld0311@EARTH61;

SQL*Plus: Release 11.2.0.1.0 Production on Wed Apr 6 01:24:28 2016

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>
SQL>
SQL> create table z_te(id number);

Table created.

SQL> insert into z_te(id)values(1);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from z_te;

ID
----------
1

SQL> drop table z_te;

Table dropped.

SQL> select * from z_te;
select * from z_te
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL>
看到ddl、dml操作正常,此致使用rman备份进行数据库迁移顺利完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: