资源描述
用户管理的恢复实验操作:(实验要求假使数据文件所在的磁盘发生损坏)
1 cd /u01/oracle/oradata
2 mkdir backup --- chown -R oracle:oinstall /u01/oracle/oradata/ivan
3 cd backup
4 cp /u01/oracle/oradata/devin/ *.(如果同时copy参数文件跟口令文件也行)
5mkdir /u01/oracle/oradata/ivan –这里是数据文件的新生磁盘,在这里非得要解释一下磁盘跟目录不同,而linux下硬件也是由目录构成的,而新建一个磁盘你必须得格式化,要不裸设备是无法存储数据的。
增加与格式化磁盘步骤如下:
编辑虚拟机
Add disk
对应增加disk
为新disk设置空间大小与空间分配类型
定义disk file,vmdk为后缀,前缀字符可以自定义。自此磁盘增加以完成,重启操作系统。
[root@devin ~]# cd /dev
[root@devin dev]# ls
agpgart fd0u720 loop5 ptmx ramdisk tty1 tty27 tty44 tty61 vcsa
autofs fd0u800 loop6 pts random tty10 tty28 tty45 tty62 vcsa1
cdrom fd0u820 loop7 ram rawctl tty11 tty29 tty46 tty63 vcsa2
cdrom-hdc fd0u830 lp0 ram0 root tty12 tty3 tty47 tty7 vcsa3
console floppy MAKEDEV ram1 rtc tty13 tty30 tty48 tty8 vcsa4
core floppy-fd0 mapper ram10 sda tty14 tty31 tty49 tty9 vcsa5
disk full md0 ram11 sda1 tty15 tty32 tty5 ttyS0 vcsa6
fd gpmctl mem ram12 sda2 tty16 tty33 tty50 ttyS1 vcsa7
fd0 hdc net ram13 sdb tty17 tty34 tty51 ttyS2 VolGroup00
fd0u1040 hpet null ram14 sg0 tty18 tty35 tty52 ttyS3 X0R
fd0u1120 initctl nvram ram15 sg1 tty19 tty36 tty53 urandom zero
fd0u1440 input oldmem ram2 shm tty2 tty37 tty54 vcs
fd0u1680 kmsg par0 ram3 snapshot tty20 tty38 tty55 vcs1
fd0u1722 log parport0 ram4 stderr tty21 tty39 tty56 vcs2
fd0u1743 loop0 parport1 ram5 stdin tty22 tty4 tty57 vcs3
fd0u1760 loop1 parport2 ram6 stdout tty23 tty40 tty58 vcs4
fd0u1840 loop2 parport3 ram7 systty tty24 tty41 tty59 vcs5
fd0u1920 loop3 port ram8 tty tty25 tty42 tty6 vcs6
fd0u360 loop4 ppp ram9 tty0 tty26 tty43 tty60 vcs7
从以上信息我们看到两个磁盘一个是sda,一个是sdb,而sda已经分为两个区:sda1,sda2.
首先我们对新磁盘要进行分区选择,其二是对其进行格式化,然而再对指定mount的目录、
[root@devin dev]# fdisk sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
由上述提示指令对新磁盘进行分区:
Command (m for help): p
Disk sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
查看分区情况
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 261
选择P基本分区,我对整个磁盘就划分为一个分区。
Command (m for help): p ----查询新建分区的信息
Disk sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
sdb1 1 261 2096451 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
把新建磁盘写进系统
[root@devin dev]# mkfs.ext3 sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524112 blocks
26205 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
mkfs.ext3 sdb1表示对sdb1磁盘进行格式化,对其设置为ext3的文件系统。
[root@devin /]# cd /u01/oracle/oradata
[root@devin oradata]# mount /dev/sdb1 ivan
最后一步则是mount新增磁盘到ivan目录
6 cd /u01/oracle/oradata/ivan
7 cp /u01/backup/cold/ *. ---把备份文件拷至ivan目录下
8 我们知道因为数据文件路径变了,所以我们得重新配置参数文件跟控制文件,要不此时数据库依旧无法启动。
以上是SPFILE原信息,但是控制文件路径已经变了,所以必须修改。
[oracle@devin ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Feb 25 10:20:32 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
SQL> create pfile from spfile;
[oracle@devin dbs]$ mv spfiledevin.ora spfiledevin.ora.org
此时对SPFILE进行改名,让oracle无法侦测到spfile,而此时pfile就会被侦测使用。
SQL> create spfile from pfile;
在这里我必须得重新温习一下,因为conn之后数据库进入了nomount的状态,此时只是读参数文件,而旧的spfile依然存在,所以启动到nomount状态是没问题的,而读取参数文件,创建pfile也是没问题的。
Vi initdevin.ora
devin.__java_pool_size=4194304
devin.__large_pool_size=4194304
devin.__shared_pool_size=71303168
devin.__streams_pool_size=0
*.audit_file_dest='/u01/oracle/admin/devin/adump'
*.background_dump_dest='/u01/oracle/admin/devin/bdump'
*.compatible='10.2.0.1.0'
*.control_files='/u01/oracle/oradata/devin/control01.ctl','/u01/oracle/oradata/devin/control02.ctl','/u01/oracle/oradata/devin/control03.ctl'
*.core_dump_dest='/u01/oracle/admin/devin/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='devin'
*.db_recovery_file_dest='/u01/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=3225419776
*.dispatchers='(PROTOCOL=TCP) (SERVICE=devinXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=16777216
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=167772160
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
"initdevin.ora" 26L, 973C
在这里我们只需要对control_files的路径进行修改为:
control_files='/u01/oracle/oradata/ivan/control01.ctl','/u01/oracle/oradata/ivan/control02.ctl','/u01/oracle/oradata/ivan/control03.ctl'
此时数据库能启动了吗?对不起,依然不能,为什么呢?请看下面信息:
[oracle@devin devin]$ strings control01.ctl | more
/u01/oracle/oradata/devin/redo03.log
/u01/oracle/oradata/devin/redo02.log
/u01/oracle/oradata/devin/redo01.log
/u01/oracle/oradata/devin/users01.dbf
/u01/oracle/oradata/devin/sysaux01.dbf
/u01/oracle/oradata/devin/undotbs01.dbf
/u01/oracle/oradata/devin/system01.dbf
/u01/oracle/oradata/devin/temp01.dbf
/u01/oracle/oradata/devin/redo03.log
/u01/oracle/oradata/devin/redo02.log
/u01/oracle/oradata/devin/redo01.log
/u01/oracle/oradata/devin/users01.dbf
/u01/oracle/oradata/devin/sysaux01.dbf
/u01/oracle/oradata/devin/undotbs01.dbf
/u01/oracle/oradata/devin/system01.dbf
/u01/oracle/oradata/devin/temp01.dbf
以上的数据文件,重做日志文件信息依然是旧路径
Startup mount;
SQL> select file#,name from v$datafile;
FILE# NAME
---------- ------------------------------
1 /u01/oracle/oradata/devin/syst
em01.dbf
2 /u01/oracle/oradata/devin/undo
tbs01.dbf
3 /u01/oracle/oradata/devin/sysa
ux01.dbf
4 /u01/oracle/oradata/devin/user
s01.dbf
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/oracle/oradata/devin/redo03.log
/u01/oracle/oradata/devin/redo02.log
/u01/oracle/oradata/devin/redo01.log
alter database rename file ‘/u01/oracle/oradata/devin/system01.dbf’ to ‘/u01/oracle/oradata/ivan/system01.dbf’
如法炮制,对每个数据文件,重做日志文件进行修改。
Alter database open;
假如上述实验没有备份联机重做日志,而原磁盘已经损坏,这就要重建联机重做日志文件。那么此时我们可以模拟不完全恢复,数据库生命周期回归为1,此时会ORACLE会自建联机重做日志文件。
Startup mount;
Recover database until cancel using backup controlfile;
Altet database open resetlogs;
展开阅读全文