rman全备恢复迁移数据库

1.安装oracle软体

A服务器为数据库所在服务器,B服务器为要将数据库迁移到上面的服务器

B服务器安装oracle软体

2.全备数据库

run {
ALLOCATE channel rman_1 TYPE disk;
ALLOCATE channel rman_2 TYPE disk;
ALLOCATE channel rman_3 TYPE disk;
SQL 'alter SYSTEM switch logfile';
BACKUP database format '/data/rman/df_%T_%U.dbf';               
BACKUP current controlfile format '/Data/rman/cf_%T_%U.ctf';     
BACKUP spfile format '/Data/rman/sp_%T_%U.sp';                 
SQL 'alter SYSTEM archive LOG current';               
release channel rman_1;
release channel rman_2;
release channel rman_3;
}

3.将全备传送至B服务器

scp ./* 192.168.2.100:/data/rman/

4.恢复参数文件

B服务器恢复参数文件

rman target /
# 虽然此时没有参数文件,rman也可以使用dummy打开实例
RMAN> startup nomount;
RMAN> restore spfile from '/data/rman/sp_20180801_1gt9gcau_1_1.sp';

5.创建参数文件目录

参数文件中包含的目录要事先创建,否则无法打开实例

  • audit_file_dest
  • control_files
  • db_recovery_file_dest
  • log_archive_dest_1
  • adump,udump,cdump

6.打开实例

-- 先关闭dummy实例
sqlplus / as sysdba
shutdown immediate
-- 此时已有spfile,可以打开实例
startup nomount

7.恢复控制文件

rman target /
RMAN> restore controlfile from '/Data/rman/cf_20180801_1ft9gcas_1_1.ctf';
RMAN> alter database mount;

8.恢复数据文件

-- 如果A和B服务器数据文件目录相同,则直接恢复,可以用如下命令看数据文件都在哪个目录中
SELECT distinct SUBSTR(FILE_NAME,0,INSTR(FILE_NAME,'/',-1)) FROM DBA_DATA_FILES;

-- 如果要把所有数据文件重定向到特定目录,使用如下命令
SELECT 'set newname for datafile '||FILE_ID||' TO ''/data/monkey/'||SUBSTR(file_name, INSTR(file_name, '/', -1) + 1)||''';' FROM DBA_DATA_FILES;
# 备份信息保存在controlfile中,如果A和B备份文件不在同一个目录,需要catalog一下
rman target /
RMAN> catalog start with '/data/rman';
run {
ALLOCATE channel rman_1 TYPE disk;
ALLOCATE channel rman_2 TYPE disk;
ALLOCATE channel rman_3 TYPE disk;
set newname for datafile 4 TO "/data/monkey/users01.dbf";
set newname for datafile 3 TO "/data/monkey/undotbs01.dbf";
restore database;
switch datafile all;
release channel rman_1;
release channel rman_2;
release channel rman_3;
}

9.关闭源库并传送归档过来

关闭数据库

sqlplus / as sysdba
shutdown immediate;

传送归档

scp /data/archivelog/* 192.168.2.100:/data/archivelog

rman识别归档

rman target /
catalog start with '/data/archivelog'

恢复数据库

rman target /
RMAN> recover database;

10.修改online redo和temp信息

alter database rename file '/data/dfhdb/redo03.log' to '/data/monkey/redo03.log';
alter database rename file '/data/dfhdb/temp01.dbf' to '/data/dfhdb/temp01.dbf';

11.打开数据库

alter database open resetlogs;

12.创建监听

cd $ORACLE_HOME/network/admin
vi listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = monkeydb)
      (ORACLE_HOME = /oracle/dbhome)
      (SID_NAME = monkeydb)
    )
  )


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.2.100)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /oracle
posted @ 2019-03-12 11:33  monkey6  阅读(4)  评论(0编辑  收藏  举报