just do it
分类: Oracle
2013-10-14 21:36:41
建立相应目录:
$mkdir -p /u01/standby/oradata/cuug/
$mkdir -p /u01/standby/admin/cuug/adump
$mkdir -p /u01/standby/admin/cuug/bdump
$mkdir -p /u01/standby/admin/cuug/cdump
$mkdir -p /u01/standby/admin/cuug/udump
创建备库逻辑卷:
lvcreate -L 550 -n st_system01 vg02
lvcreate -L 550 -n st_sysaux01 vg02
lvcreate -L 550 -n st_undotbs01 vg02
lvcreate -L 200 -n st_example01 vg02
lvcreate -L 200 -n st_users01 vg02
lvcreate -L 300 -n st_temp01 vg02
lvcreate -L 150 -n st_redo01 vg02
lvcreate -L 150 -n st_redo02 vg02
lvcreate -L 150 -n st_redo03 vg02
lvcreate -L 150 -n st_redo04 vg02
lvcreate -L 150 -n st_control01 vg02
lvcreate -L 150 -n st_control02 vg02
lvcreate -L 150 -n st_control03 vg02
lvcreate -L 10 -n st_spfile vg02
修改权限
# chown oracle:dba /dev/vg02/*
创建文件链接: oracle用户执行
ln -s /dev/vg02/rst_system01 /u01/standby/oradata/cuug/system01.dbf
ln -s /dev/vg02/rst_sysaux01 /u01/standby/oradata/cuug/sysaux01.dbf
ln -s /dev/vg02/rst_undotbs01 /u01/standby/oradata/cuug/undotbs01.dbf
ln -s /dev/vg02/rst_example01 /u01/standby/oradata/cuug/example01.dbf
ln -s /dev/vg02/rst_users01 /u01/standby/oradata/cuug/users01.dbf
ln -s /dev/vg02/rst_temp01 /u01/standby/oradata/cuug/temp01.dbf
ln -s /dev/vg02/rst_redo01 /u01/standby/oradata/cuug/redo01.log
ln -s /dev/vg02/rst_redo02 /u01/standby/oradata/cuug/redo02.log
ln -s /dev/vg02/rst_redo03 /u01/standby/oradata/cuug/redo03.log
ln -s /dev/vg02/rst_redo04 /u01/standby/oradata/cuug/redo04.log
ln -s /dev/vg02/rst_control01 /u01/standby/oradata/cuug/control01.ctl
ln -s /dev/vg02/rst_control02 /u01/standby/oradata/cuug/control02.ctl
ln -s /dev/vg02/rst_control03 /u01/standby/oradata/cuug/control03.ctl
ln -s /dev/vg02/rst_spfile /u01/standby/oradata/cuug/spfile
将生产库spfile参数文件转储,修改为备库pfile:
#cuug.__db_cache_size=54525952
#cuug.__java_pool_size=4194304
#cuug.__large_pool_size=4194304
#cuug.__shared_pool_size=67108864
#cuug.__streams_pool_size=0
*.audit_file_dest='/u01/standby/admin/cuug/adump'
*.background_dump_dest='/u01/standby/admin/cuug/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/standby/oradata/cuug/control01.ctl','/u01/standby/oradata/cuug/control02.ctl','/u01/st
andby/oradata/cuug/control03.ctl'
*.core_dump_dest='/u01/standby/admin/cuug/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='cuug'
DB_UNIQUE_NAME='st_cuug'
#*.db_recovery_file_dest='/u01/oracle/flash_recovery_area'
#*.db_recovery_file_dest_size=2147483648
*.job_queue_processes=10
*.log_archive_dest_1='location=/arch'
*.log_archive_format='arch_%t_%s_%r.log'
*.open_cursors=300
*.pga_aggregate_target=96468992
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_max_size=134217728
*.sga_target=134217728
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/standby/admin/cuug/udump'
建立 initst_cuug.ora 参数文件,放到$ORACLE_HOME/dbs 目录下。
$vi initst_cuug.ora
SPFILE='/u01/standby/oradata/cuug/spfile'
生产库RMAN做全备:
backup database format='/backup/cuug_%U.bak';
利用修改后的pfile启动数据库到nomount状态:
$export ORACLE_SID=st_cuug
$sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Feb 23 13:22:40 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile='xxxxxxxxxxxxxxxxxx'
RMAN转储控制文件: 注意:转储控制文件前最好清理废旧备份,再重新备份数据库,然后转储数据文件。
$ export ORACLE_SID=st_cuug
$rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Feb 23 13:38:39 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: CUUG (DBID=1257186540)
RMAN> restore controlfile to '/home/oracle/aa/control01.ctl' from '/backup/cuug_0hn416vi_1_1.bak';
将控制文件转储入备库裸设备:
restore controlfile to '/dev/vg01/rmycontrol01' from '/backup/cuug_0hn416vi_1_1.bak';
restore controlfile to '/dev/vg01/rmycontrol02' from '/backup/cuug_0hn416vi_1_1.bak';
restore controlfile to '/dev/vg01/rmycontrol03' from '/backup/cuug_0hn416vi_1_1.bak';
将转储的控制文件dd进入备库裸设备:
# dd if='/home/oracle/aa/control01.ctl' of='/dev/vg02/rst_control01' bs=1024
6896+0 records in
6896+0 records out
# dd if='/home/oracle/aa/control01.ctl' of='/dev/vg02/rst_control02' bs=1024
6896+0 records in
6896+0 records out
# dd if='/home/oracle/aa/control01.ctl' of='/dev/vg02/rst_control03' bs=1024
6896+0 records in
6896+0 records out
启动数据库到mount状态
RMAN转储数据文件到新的位置:
run{
set newname for datafile 1 to '/dev/vg02/rst_system01';
set newname for datafile 2 to '/dev/vg02/rst_undotbs01';
set newname for datafile 3 to '/dev/vg02/rst_sysaux01';
set newname for datafile 4 to '/dev/vg02/rst_users01';
restore database;
switch datafile all;
recover database;
}
$ export ORACLE_SID=st_cuug
$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu Feb 23 07:54:34 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: CUUG (DBID=1257186540, not open)
RMAN> list backup;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14 Full 242.56M DISK 00:00:38 23-FEB-12
BP Key: 14 Status: AVAILABLE Compressed: NO Tag: TAG20120223T074155
Piece Name: /backup/cuug_0gn416u4_1_1.bak
List of Datafiles in backup set 14
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 220132 23-FEB-12 /u01/oracle/oradata/cuug/system01.dbf
2 Full 220132 23-FEB-12 /u01/oracle/oradata/cuug/undotbs01.dbf
3 Full 220132 23-FEB-12 /u01/oracle/oradata/cuug/sysaux01.dbf
4 Full 220132 23-FEB-12 /u01/oracle/oradata/cuug/users01.dbf
RMAN> run{
2> set newname for datafile 1 to '/dev/vg02/rst_system01';
3> set newname for datafile 2 to '/dev/vg02/rst_undotbs01';
4> set newname for datafile 3 to '/dev/vg02/rst_sysaux01';
5> set newname for datafile 4 to '/dev/vg02/rst_users01';
6> restore database;
7> switch datafile all;
8> recover database;
9> }
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 23-FEB-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00001 to /dev/vg02/rst_system01
restoring datafile 00002 to /dev/vg02/rst_undotbs01
restoring datafile 00003 to /dev/vg02/rst_sysaux01
restoring datafile 00004 to /dev/vg02/rst_users01
channel ORA_DISK_1: reading from backup piece /backup/cuug_0gn416u4_1_1.bak
channel ORA_DISK_1: restored backup piece 1
piece handle=/backup/cuug_0gn416u4_1_1.bak tag=TAG20120223T074155
channel ORA_DISK_1: restore complete, elapsed time: 00:01:45
Finished restore at 23-FEB-12
datafile 1 switched to datafile copy
input datafile copy recid=6 stamp=775987022 filename=/dev/vg02/rst_system01
datafile 2 switched to datafile copy
input datafile copy recid=7 stamp=775987022 filename=/dev/vg02/rst_undotbs01
datafile 3 switched to datafile copy
input datafile copy recid=8 stamp=775987023 filename=/dev/vg02/rst_sysaux01
datafile 4 switched to datafile copy
input datafile copy recid=9 stamp=775987023 filename=/dev/vg02/rst_users01
Starting recover at 23-FEB-12
using channel ORA_DISK_1
starting media recovery
archive log thread 1 sequence 21 is already on disk as file /u01/oracle/oradata/cuug/redo03.log
archive log filename=/u01/oracle/oradata/cuug/redo03.log thread=1 sequence=21
media recovery complete, elapsed time: 00:00:02
Finished recover at 23-FEB-12
RMAN>
多余的一步
将生产库redo日志文件导入备库裸设备:
# dd if='/dev/vg02/rredo01' of='/dev/vg02/rst_redo01' bs=1024kb
0+1 records in
0+1 records out
# dd if='/dev/vg02/rredo02' of='/dev/vg02/rst_redo02' bs=1024kb
0+1 records in
0+1 records out
# dd if='/dev/vg02/rredo03' of='/dev/vg02/rst_redo03' bs=1024kb
0+1 records in
0+1 records out
# dd if='/dev/vg02/rredo04' of='/dev/vg02/rst_redo04' bs=1024kb
0+1 records in
0+1 records out
在数据库mount状态重新命名redo日志文件:
alter database rename file '/u01/oracle/oradata/cuug/redo01.log' to '/u01/standby/oradata/cuug/redo01.log';
alter database rename file '/u01/oracle/oradata/cuug/redo02.log' to '/u01/standby/oradata/cuug/redo02.log';
alter database rename file '/u01/oracle/oradata/cuug/redo03.log' to '/u01/standby/oradata/cuug/redo03.log';
alter database rename file '/u01/oracle/oradata/cuug/redo04.log' to '/u01/standby/oradata/cuug/redo04.log';
打开数据库:
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.