dd常用命令总结

在数据文件修复的过程中可能经常会使用到dd这个命令,下面对常用的几个命令进行总结

dd 命令:

   if= 数据来源
   of= 数据存储目标
   bs=1  以一个字节为单位
   count=2  读2个block
   seek=blocks :创建数据文件时,跳过的块数   
   skip=blocks :读取数据文件是,跳过的块数
   conv=notrunc:不缩减输出文件
   

[oracle@node3 ~]$ dd if=/oradata/node3/control01.ctl  of=/home/oracle/controldd.ctl skip=2 bs=16384 count=1
1+0 records in
1+0 records out
16384 bytes (16 kB) copied, 0.011107 seconds, 1.5 MB/s

从control01.ctl文件 读取第三个block,一共读取1个


skip=2  :读取时跳过前两个block,也就是从第3个block开始读取
bs=16384: 一个block为16K
count=1 : 一共读取一个


[oracle@node3 ~]$ dd if=/oradata/node3/control01.ctl bs=16384 count=1 | od -x |head -5
1+0 records in
1+0 records out
16384 bytes (16 kB) copied, 5.3e-05 seconds, 309 MB/s
0000000 c200 0000 0000 ffc0 0000 0000 0000 0000
0000020 f834 0000 4000 0000 0252 0000 7c7d 7a7b
0000040 81a0 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000

bs=16384 : 一次读取数据大小为16K
count=1  : 读取1个block
od -x    : 显示成16进制
head -5  : 显示前5行

dd if=/home/oracle/controldd.ctl of=/oradata/node3/control01.ctl seek=2 bs=16384 count=1 conv=notrunc

dd 从/home/oracle/controldd.ctl  读取输入到 /oradata/node/control01.ctl 跳过2个blocks开始写入

conv=notrunc:不缩减输出文件,如果输出文件已经存在,只改变指定的字节,然后退出,并保留输出文件的剩余部分。没有这个选项,dd将创建一16384个字节长的文件。



下面是操作数据文件的例子

1. 备份 users01.dbf,从67个块开始,一个备份20个
[oracle@node3 node3]$  dd if=/oradata/node3/users01.dbf  of=/home/oracle/users01.bak skip=66 bs=8192 count=20
20+0 records in
20+0 records out
163840 bytes (164 kB) copied, 0.045229 seconds, 3.6 MB/s

2.损坏数据文件

[oracle@node3 ~]$ dd if=/dev/zero of=/oradata/node3/users01.dbf seek=66 bs=8192 count=20 conv=notrunc
20+0 records in
20+0 records out
163840 bytes (164 kB) copied, 0.000105 seconds, 1.6 GB/s



3.检查文件状态

[oracle@node3 node3]$ dbv file=/oradata/node3/users01.dbf blocksize=8192

DBVERIFY: Release 11.2.0.4.0 - Production on Tue Feb 2 21:51:33 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /oradata/node3/users01.dbf
Page 66 is marked corrupt
Corrupt block relative dba: 0x01000042 (file 4, block 66)
Completely zero block found during dbv: 

Page 67 is marked corrupt
Corrupt block relative dba: 0x01000043 (file 4, block 67)
Completely zero block found during dbv: 

Page 68 is marked corrupt
Corrupt block relative dba: 0x01000044 (file 4, block 68)
Completely zero block found during dbv: 

Page 69 is marked corrupt
Corrupt block relative dba: 0x01000045 (file 4, block 69)
Completely zero block found during dbv: 

Page 70 is marked corrupt
Corrupt block relative dba: 0x01000046 (file 4, block 70)
Completely zero block found during dbv: 

Page 71 is marked corrupt
Corrupt block relative dba: 0x01000047 (file 4, block 71)
Completely zero block found during dbv: 

Page 72 is marked corrupt
Corrupt block relative dba: 0x01000048 (file 4, block 72)
Completely zero block found during dbv: 

Page 73 is marked corrupt
Corrupt block relative dba: 0x01000049 (file 4, block 73)
Completely zero block found during dbv: 

Page 74 is marked corrupt
Corrupt block relative dba: 0x0100004a (file 4, block 74)
Completely zero block found during dbv: 

Page 75 is marked corrupt
Corrupt block relative dba: 0x0100004b (file 4, block 75)
Completely zero block found during dbv: 

Page 76 is marked corrupt
Corrupt block relative dba: 0x0100004c (file 4, block 76)
Completely zero block found during dbv: 

Page 77 is marked corrupt
Corrupt block relative dba: 0x0100004d (file 4, block 77)
Completely zero block found during dbv: 

Page 78 is marked corrupt
Corrupt block relative dba: 0x0100004e (file 4, block 78)
Completely zero block found during dbv: 

Page 79 is marked corrupt
Corrupt block relative dba: 0x0100004f (file 4, block 79)
Completely zero block found during dbv: 

Page 80 is marked corrupt
Corrupt block relative dba: 0x01000050 (file 4, block 80)
Completely zero block found during dbv: 

Page 81 is marked corrupt
Corrupt block relative dba: 0x01000051 (file 4, block 81)
Completely zero block found during dbv: 

Page 82 is marked corrupt
Corrupt block relative dba: 0x01000052 (file 4, block 82)
Completely zero block found during dbv: 

Page 83 is marked corrupt
Corrupt block relative dba: 0x01000053 (file 4, block 83)
Completely zero block found during dbv: 

Page 84 is marked corrupt
Corrupt block relative dba: 0x01000054 (file 4, block 84)
Completely zero block found during dbv: 

Page 85 is marked corrupt
Corrupt block relative dba: 0x01000055 (file 4, block 85)
Completely zero block found during dbv: 



DBVERIFY - Verification complete

Total Pages Examined         : 640
Total Pages Processed (Data) : 91
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 39
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 472
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 18
Total Pages Marked Corrupt   : 20
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 954693 (0.954693)
[oracle@node3 node3]$ 

可以看到66到85这20个块损坏


4.恢复

[oracle@node3 ~]$ dd if=/home/oracle/users01.bak of=/oradata/node3/users01.dbf seek=66 bs=8192 count=20 conv=notrunc
20+0 records in
20+0 records out
163840 bytes (164 kB) copied, 0.000155 seconds, 1.1 GB/s



5.检测文件状态,可以看到文件没有坏块

[oracle@node3 ~]$ dbv file=/oradata/node3/users01.dbf blocksize=8192

DBVERIFY: Release 11.2.0.4.0 - Production on Tue Feb 2 21:55:24 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
DBVERIFY - Verification starting : FILE = /oradata/node3/users01.dbf

DBVERIFY - Verification complete

Total Pages Examined         : 640
Total Pages Processed (Data) : 91
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 39
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 492
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 18
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 954693 (0.954693)



[oracle@node3 ~]$ dd if=/home/oracle/users01.bak of=/oradata/node3/users01.dbf seek=66 bs=8192 count=20 conv=notrunc

注意:conv=notrunc 这个参数必须带上,要不整个数据文件都会破坏,非常危险;操作前最好对数据文件进行备份。
conv=notrunc:   大体意思是:加了参数会修改66到85这20个数据块;如果没加将创建一个163840 byte大小的文件

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值