1、环境检查
2、源库开启块跟踪
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '/u02/changetracking.chg';
3、挂载nfs存储
4、确认scn记录
作为后续增量备份的开始scn,起始点
alter system checkpoint;
select current_scn from v$database;
1040684
5、通过rman生成数据文件备份
将rman备份生成的数据文件存放到nfs目录
rman target / <<EOF
run{
allocate channel c1 type disk;
allocate channel c2 type disk;
backup as copy datafile 5 format '/u02/copy/admin.dbf';
release channel c1;
release channel c2;
}
EOF
6、源库生成增量数据
create table admin.test2 as select * from dba_users;
7、增量备份阶段
最后一次增量备份前确定当前scn,并且将表空间read only,根据全备时期记录的scn作为增量备份的起点开始备份,并存放到nfs目录
将表空间置为read only
alter tablespace admin read only;
rman target / <<EOF
run{
set until scn=1040906; -->增量备份前的scn
backup incremental from scn 1040684 datafile 5 format '/u02/copy/incr_%d_%T_%U.bak'; -->上次rman备份表空间数据文件时的scn
}
EOF
8、源数据库导出元数据
在源数据库中将对应的表空间置为read only,排除系统表空间
源数据库:
expdp system/oracle directory=dump dumpfile=ora11g_metadata.dmp TRANSPORT_TABLESPACES=admin logfile=xtts.log
9、目标数据库还原数据文件
cp /u02/copy/admin.dbf /u02/app/oracle/oradata/orcl/admin.dbf
10、目标数据库增量备份进行还原
`增量还原脚本`
set serveroutput on;
DECLARE
outhandle varchar2(512) ;
outtag varchar2(30) ;
done boolean ;
failover boolean ;
devtype VARCHAR2(512);
BEGIN
DBMS_OUTPUT.put_line('Entering RollForward');
-- Now the rolling forward.
devtype := sys.dbms_backup_restore.deviceAllocate;
sys.dbms_backup_restore.applySetDatafile(check_logical => FALSE, cleanup => FALSE) ;
DBMS_OUTPUT.put_line('After applySetDataFile');
sys.dbms_backup_restore.applyDatafileTo(dfnumber => 5 ,toname => '/u02/app/oracle/oradata/orcl/admin.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
DBMS_OUTPUT.put_line('Done: applyDataFileTo');
DBMS_OUTPUT.put_line('Done: applyDataFileTo');
-- Restore Set Piece
sys.dbms_backup_restore.restoreSetPiece(handle => '/u02/copy/incr_ORA11G_20190304_02trj7d5_1_1.bak',tag => null, fromdisk => true, recid => 0, stamp => 0) ;
DBMS_OUTPUT.put_line('Done: RestoreSetPiece');
-- Restore Backup Piece
sys.dbms_backup_restore.restoreBackupPiece(done => done, params => null, outhandle => outhandle,outtag => outtag, failover => failover);
DBMS_OUTPUT.put_line('Done: RestoreBackupPiece');
sys.dbms_backup_restore.restoreCancel(TRUE);
sys.dbms_backup_restore.deviceDeallocate;
END;
/
应用增量备份
SQL> @apply_incr.sql
Entering RollForward
After applySetDataFile
Done: applyDataFileTo
Done: applyDataFileTo
Done: RestoreSetPiece
Done: RestoreBackupPiece
PL/SQL procedure successfully completed.
11、目标数据库元数据导入
目标数据库
在导入之前需要在目标数据库创建源库的用户对象
create user admin identified by oracle;
grant dba to admin;
开始导入元数据
impdp system/oracle directory=dump dumpfile=ora11g_metadata.dmp transport_datafiles=/u02/app/oracle/oradata/orcl/admin.dbf logfile=xtts.log
Import: Release 11.2.0.4.0 - Production on Tue Mar 5 09:50:18 2019
Copyright © 1982, 2011, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01": system/******** directory=dump dumpfile=ora11g_metadata.dmp transport_datafiles=/u02/app/oracle/oradata/orcl/admin.dbf logfile=xtts.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at Tue Mar 5 09:50:25 2019 elapsed 0 00:00:04
12、更改用户对应默认表空间
SQL> alter user admin default tablespace admin;
13、无效对象编译检查
sqlplus / as sysdba <<EOF
DECLARE
threads pls_integer := 150;
BEGIN
utl_recomp.recomp_parallel(threads);
END;
/
EOF
14、检验目标数据库数据一致性
增量数据验证
SQL> select count(*) from admin.test2;
COUNT(*)
----------
31
对象数量验证
select owner,object_type,count (*) from dba_objects where owner group by owner,object_type order by owner,object_type;
表数据库行数验证
select table_name,num_rows from all_tables where owner=‘ADMIN' group by table_name,num_rows having num_rows>500 order by table_name;
表数据大小验证
select owner, segment_name, bytes/1024/1024 from dba_segments where segment_type = 'TABLE' and owner =’ADMIN';
CATALOG DATAFILECOPY ‘/u02/copy/admin.dbf’;
RUN {
SET NEWNAME FOR DATAFILE 5 TO ‘/u02/app/oracle/oradata/orcl/admin.dbf’;
SWITCH DATAFILE 5;
}
转化
RUN
{
CONVERT
FROM PLATFORM ‘Linux x86 64-bit’
DATAFILE ‘/u02/copy/ora11g_data_D-ORA11G_I-103208071_TS-ADMIN_FNO-5_01trj781’
FORMAT
‘/u02/app/oracle/oradata/orcl/admin.dbf’;
}