1.全库备份
run {
allocate channel ch1 type disk maxpiecesize=50g;
backup format 'E:\backup1\datafile\full_%U' tag 'fullbak_' full database;
sql 'alter system archive log current';
backup format 'E:\backup1\datafile\arclog_%U' archivelog all delete all input;
backup format 'E:\backup1\controlfile\cntrl_%U' current controlfile;
release channel ch1;
}
2.零级增量备份
run {
allocate channel ch1 type disk maxpiecesize=50g;
backup incremental level=0 format 'E:\backup1\datafile\incr0_%U' tag 'fullbak_level_0' database;
sql 'alter system archive log current';
backup format 'E:\backup1\datafile\arclog_%U' archivelog all delete all input;
backup format 'E:\backup1\controlfile\cntrl_%U' current controlfile;
release channel ch1;
}
3.一级增量备份
run {
allocate channel ch1 type disk maxpiecesize=50g;
backup incremental level=1 format 'E:\backup1\datafile\incr0_%U' tag 'incrbak_level_1' database;
sql 'alter system archive log current';
backup format 'E:\backup1\datafile\arclog_%U' archivelog all delete all input;
backup format 'E:\backup1\controlfile\cntrl_%U' current controlfile;
release channel ch1;
}
注意:在迁移时,最后一次增量需要停机,使用shutdown immediate让数据库一致关闭,增量备份技术后,使用backup current controlfile format 'E:\bak\control_%U’备份控制文件,一定要用停机后备份的控制文件进行数据库的还原,停库的原因是因为Windows端的归档日志不能在Linux端跑!!!
恢复示例:
在目标服务器上用rman连接至数据库
export ORACLE_SID=xx
rman target /
恢复参数文件(可用这个方法恢复参数文件)
RMAN> restore spfile to pfile "/app/oracle/11.2.0/dbs/pfileorcl.ora" from "备份的参数文件的位置";
4.将pfile.ora和RMAN备份的数据文件和控制文件传到linux上.
5.修改传送过去的pfile.ora文件,将一系列目录改为linux上的对应目录,注意SGA和PGA的修改
startup nomount pfile=‘备份的参数文件位置’
假如报错,根据报错排查对应错误
6. 恢复控制文件并且mount数据库
rman target /
RMAN>restore controlfile from '备份的控制文件存放位置';
RMAN>sql 'alter database mount';
7.清理RMAN记录的catalog的失效记录
RMAN>crosscheck backup;
RMAN>delete expired backup;
8.将RMAN备份文件加入到catalog
catalog backuppiece '/tmp/FULL_01RMSH1N_1_1','/tmp/FULL_02RMSH3P_1_1';
有几个加几个,或者假如备份文件很多,那么用下面的命令
catalog start with '备份集存放的位置';
注意假如是直接指定了一个目录,那么最后必须接/表示这是一个目录,否则会被认为是一个前缀
9.开始在RMAN中从catalog中恢复数据库,并且set newname来指定新的路径,switch来将新的路径写到控制文件
run{
set newname for database to '/u01/app/oracle/oradata/orcl/datafile/%N';
restore database;
switch database to copy;
switch datafile all;
recover database;
}
10.开启数据库,使用resetlogs upgrade参数来重建redo文件
SQL> alter database open resetlogs upgrade;
顺便生成一下spfile
SQL> create spfile from pfile='备份的参数文件存放位置';
重新编译一下无效对象
@?/rdbms/admin/utlrp.sql;