3.2 备份相关数据文件副本:
编写脚本:
vi copy_datafile.sh
echo "=======Begin at : `date`=======" >>/tmp/copy_datafile_`date +%Y%m%d`.log
rman target / <<EOF >>/tmp/copy_datafile_`date +%Y%m%d`.log
run {
allocate channel c1 device type disk;
allocate channel c2 device type disk;
allocate channel c3 device type disk;
backup as copy datafile 9 format '/oradata/jy/datafile/dbs_data9.dbf';
backup as copy datafile 10 format '/oradata/jy/datafile/dbs_data10.dbf';
backup as copy datafile 11 format '/oradata/jy/datafile/dbs_data11.dbf';
release channel c1;
release channel c2;
release channel c3;
}
EOF
echo "=======End at : `date`=======" >>/tmp/copy_datafile_`date +%Y%m%d`.log
后台执行脚本:
nohup sh copy_datafile.sh &
记录的日志如下:
=======Begin at : Sat May 5 10:51:24 CST 2018=======
Recovery Manager: Release 10.2.0.5.0 - Production on Sat May 5 10:51:24 2018
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: JY (DBID=857123342, not open)
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13>
using target database control file instead of recovery catalog
allocated channel: c1
channel c1: sid=152 devtype=DISK
allocated channel: c2
channel c2: sid=159 devtype=DISK
allocated channel: c3
channel c3: sid=144 devtype=DISK
Starting backup at 05-MAY-18
channel c1: starting datafile copy
input datafile fno=00009 name=/datafile/dbs_data9.dbf
output filename=/oradata/jy/datafile/dbs_data9.dbf tag=TAG20180505T105125 recid=22 stamp=975322288
channel c1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 05-MAY-18
Starting backup at 05-MAY-18
channel c1: starting datafile copy
input datafile fno=00010 name=/datafile/dbs_data10.dbf
output filename=/oradata/jy/datafile/dbs_data10.dbf tag=TAG20180505T105129 recid=23 stamp=975322292
channel c1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 05-MAY-18
Starting backup at 05-MAY-18
channel c1: starting datafile copy
input datafile fno=00011 name=/datafile/dbs_data11.dbf
output filename=/oradata/jy/datafile/dbs_data11.dbf tag=TAG20180505T105136 recid=24 stamp=975322315
channel c1: datafile copy complete, elapsed time: 00:00:25
Finished backup at 05-MAY-18
released channel: c1
released channel: c2
released channel: c3
RMAN>
Recovery Manager complete.
=======End at : Sat May 5 10:52:02 CST 2018=======
3.3 切换数据文件到copy副本:
RMAN> list copy of database;
using target database control file instead of recovery catalog
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
10 9 A 05-MAY-18 35303533 05-MAY-18 /oradata/jy/datafile/dbs_data9.dbf
11 10 A 05-MAY-18 35303533 05-MAY-18 /oradata/jy/datafile/dbs_data10.dbf
12 11 A 05-MAY-18 35303533 05-MAY-18 /oradata/jy/datafile/dbs_data11.dbf
RMAN> switch datafile 9,10,11 to copy;
datafile 9 switched to datafile copy "/oradata/jy/datafile/dbs_data9.dbf"
datafile 10 switched to datafile copy "/oradata/jy/datafile/dbs_data10.dbf"
datafile 11 switched to datafile copy "/oradata/jy/datafile/dbs_data11.dbf"
4.删除之前的目录并开启应用
4.1 删除之前的文件:
RMAN> list copy of database;
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
13 9 A 05-MAY-18 35309314 05-MAY-18 /datafile/data9.dbf
14 10 A 05-MAY-18 35309314 05-MAY-18 /datafile/data10.dbf
15 11 A 05-MAY-18 35309314 05-MAY-18 /datafile/datafile11.dbf
RMAN> delete copy of datafile 9,10,11;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=146 devtype=DISK
List of Datafile Copies
Key File S Completion Time Ckp SCN Ckp Time Name
------- ---- - --------------- ---------- --------------- ----
13 9 A 05-MAY-18 35309314 05-MAY-18 /datafile/data9.dbf
14 10 A 05-MAY-18 35309314 05-MAY-18 /datafile/data10.dbf
15 11 A 05-MAY-18 35309314 05-MAY-18 /datafile/datafile11.dbf