OS:Oracle Linux 5.8 64bit
DB:11.2.0.4
原生产主机上数据库运行在归档模式上,备份脚本如下:
点击( 此处)折叠或打开
-
run
{
-
allocate channel c1 device
type disk
;
-
allocate channel c2 device
type disk
;
-
backup
database plus archivelog
;
-
delete noprompt archivelog
all
;
-
release channel c1
;
-
release channel c2
;
- }
RMAN已默认开启自动备份控制文件。
将备份(包括备份片和自动备份)传输到备用主机上(与源主机的路径相同)。
编辑RMAN脚本rman.cmd
点击( 此处)折叠或打开
- connect target /
-
run {
-
restore controlfile from
'/oracledata/fra/APR/autobackup/2015_06_04/o1_mf_s_881495141_bpzlh6kd_.bkp'
;
-
alter database mount;
-
}
-
-
run {
-
SET NEWNAME FOR DATABASE TO
'/oracledata/APR/datafile/%b'
;
-
allocate channel c1 device type disk;
-
allocate channel c2 device type disk;
-
restore database;
-
release channel c1;
-
release channel c2;
-
switch datafile all;
-
}
-
-
run {
-
set until sequence
540 thread 1;
-
recover database;
-
alter database open resetlogs;
- }
注:
set newname for database:能直接更改数据库数据文件的目录路径,其中%b是变量,表示仅保留原来数据文件不包含路径的文件名,如C:\a\b.dbf就只有b.dbf。
set until sequence:在归档模式下备份不会备份活动状态下的redo log,但控制文件会记下最新活动状态下的redo log,因此需要设置备份的截止点(日志序列号)。
可以通过list backup by file找到sequence
点击( 此处)折叠或打开
-
List
of Archived
Log Backups
-
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
=
-
-
Thrd Seq Low SCN Low Time BS
Key S #Pieces #Copies Compressed Tag
-
---- ------- ---------- ------------------- ------- - ------- ------- ---------- ---
-
1 535 1443889 2015
-06
-04 10
:39
:24 12 X 1 1 NO TAG20150604T110757
-
1 536 1445437 2015
-06
-04 11
:04
:21 13 X 1 1 NO TAG20150604T110757
-
1 537 1445440 2015
-06
-04 11
:04
:24 13 X 1 1 NO TAG20150604T110757
-
1 538 1445443 2015
-06
-04 11
:04
:28 14 X 1 1 NO TAG20150604T110757
- 1 539 1445588 2015 -06 -04 11 :07 :57 17 A 1 1 NO TAG20150604T114539
最大的sequence+1,可在原主机上确认,或者在备用主机上restore controlfile之后查找确认。
注:如果没有set until sequence,recover也许能够完成,但在open数据库时会报错
ORA-01152: file
string
was not restored from a sufficiently old backup
编辑完脚本后,运行
点击( 此处)折叠或打开
- nohup rman cmdfile =rman .cmd log =rman . log &