dbms_file_transfer使用简介

dbms_file_transfer这个包可以在两个位置传输文件,分别可以有以下位置:

a 从一个asm diskgroup传输到另外一个asm diskgroup

b 从一个asm diskgroup传输到本地磁盘文件

c 从本地磁盘文件传输到asm

d 从一个计算机传输到另外一台计算机

分别有三种方法:

a copy_file 文件从一个目录拷贝到另外一个目录,只能本地传输

b get_file 把远程的文件拷贝到本地的目录中

c put_file 把本地文件拷贝到远程的目录中

1、 创建一个测试表空间

[plain]  view plain  copy
  1. SQL> create tablespace kel;  
  2.   
  3. Tablespace created.  
  4.   
  5. SQL> select file_name from dba_data_files where tablespace_name='KEL';  
  6.   
  7. FILE_NAME  
  8. --------------------------------------------------------------------------------  
  9. +RECOVER/omf/datafile/kel.272.852423821  

2、创建测试表

[plain]  view plain  copy
  1. SQL> create table a (id int,name char(10)) tablespace kel;  
  2.   
  3. Table created.  

3、 插入测试数据

[plain]  view plain  copy
  1. SQL> insert into a values (1,'aa');  
  2.   
  3. 1 row created.  

4、 用analyze进行分析

[plain]  view plain  copy
  1. SQL> analyze table a compute statistics;--对表进行分析  
  2.   
  3.   
  4. Table analyzed.  
[plain]  view plain  copy
  1. SQL> select blocks from user_tables where table_name='A';--数据表占用5个块  
  2.   
  3.     BLOCKS  
  4. ----------  
  5.      5  
  6.   
  7. SQL> select dbms_rowid.rowid_relative_fno(rowid) r_fno,--这个表的数据存放在数据文件5的12块上  
  8.   2  dbms_rowid.rowid_block_number(rowid) b_no,id  
  9.   3  from a order by 1,2;  
  10.   
  11.      R_FNO   B_NO         ID  
  12. ---------- ---------- ----------  
  13.      5     12          1  
  14.      5     12          1  
  15.      5     12          1  
  16.      5     12          1  
  17.      5     12          1  
  18.      5     12          1  
  19.      5     12          1  
  20.      5     12          1  
  21.      5     12          1  
  22.      5     12          1  
  23.      5     12          1  
  24.   
  25.      R_FNO   B_NO         ID  
  26. ---------- ---------- ----------  
  27.      5     12          1  
  28.      5     12          1  
  29.      5     12          1  
  30.      5     12          1  
  31.      5     12          1  
  32.   
  33. 16 rows selected.  
5、查看数据文件5的位置
[plain]  view plain  copy
  1. SQL> select name from v$datafile where file#=5;  
  2.   
  3. NAME  
  4. --------------------------------------------------------------------------------  
  5. +RECOVER/omf/datafile/kel.272.852423821  

6、创建两个目录

[plain]  view plain  copy
  1. SQL> create directory sd as '+recover/omf/datafile';--创建的时候,目录是必须存在的,否则会出现错误  
  2.   
  3. Directory created.  
  4.   
  5. SQL> create directory dd as '/home/oracle/backuptest';--删除目录的语法是drop directory name  
  6.   
  7. Directory created.  
7、 将数据文件offline

[plain]  view plain  copy
  1. SQL> alter database datafile 5 offline;  
  2.   
  3. Database altered.  

8、 把文件从ASM拷贝到本地文件系统中

[plain]  view plain  copy
  1. SQL> begin  
  2.   2  dbms_file_transfer.copy_file('sd','KEL.272.852423821','dd','kel.dbf');  
  3.   3  end;  
  4.   4  /  
  5.   
  6. PL/SQL procedure successfully completed.  
9、确认拷贝成功

[plain]  view plain  copy
  1. [oracle@kel backuptest]$ ls -l kel.dbf   
  2. -rw-r----- 1 oracle oinstall 104865792 Jul  9 00:40 kel.dbf  

10、对文件进行检查
[plain]  view plain  copy
  1. [oracle@kel backuptest]$ dbv file=kel.dbf   
  2.   
  3. DBVERIFY: Release 10.2.0.1.0 - Production on Wed Jul 9 00:42:10 2014  
  4.   
  5. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  6.   
  7. DBVERIFY - Verification starting : FILE = kel.dbf  
  8.   
  9.   
  10. DBVERIFY - Verification complete  
  11.   
  12. Total Pages Examined         : 12800  
  13. Total Pages Processed (Data) : 5  
  14. Total Pages Failing   (Data) : 0  
  15. Total Pages Processed (Index): 0  
  16. Total Pages Failing   (Index): 0  
  17. Total Pages Processed (Other): 11  
  18. Total Pages Processed (Seg)  : 0  
  19. Total Pages Failing   (Seg)  : 0  
  20. Total Pages Empty            : 12784  
  21. Total Pages Marked Corrupt   : 0  ---表示文件没有坏块  
  22. Total Pages Influx           : 0  
  23. Highest block SCN            : 587508 (0.587508)  

11、使用bbed破坏数据文件

查看bbed的两个参数文件:

[plain]  view plain  copy
  1. [oracle@kel backuptest]$ cat bbed.par --自己编辑生成的参数文件  
  2. blocksize=8192  
  3. listfile=list  
  4. mode=edit  
  5. [oracle@kel backuptest]$ cat list   
  6. 5 /home/oracle/backuptest/kel.dbf 104865792  --表示的含义为文件号、文件名、文件大小  

[plain]  view plain  copy
  1. [oracle@kel backuptest]$ bbed parfile=bbed.par  --BBED的密码为blockedit  
  2. Password:   
  3.   
  4. BBED: Release 2.0.0.0.0 - Limited Production on Wed Jul 9 00:46:52 2014  
  5.   
  6. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  7.   
  8. ************* !!! For Oracle Internal Use only !!! ***************  
  9.   
  10. BBED> set dba 5,12 --注意5,12的由来,注意上面分析的结果  
  11.     DBA             0x0140000c (20971532 5,12)  
  12.   
  13. BBED> find /c a  
  14.  File: /home/oracle/backuptest/kel.dbf (5)  
  15.  Block: 12               Offsets: 7923 to 8191           Dba:0x0140000c  
  16. ------------------------------------------------------------------------  
  17.  61612020 20202020 20202c01 0202c102 0a616120 20202020 2020202c 010202c1   
  18.  020a6161 20202020 20202020 2c010202 c1020a61 61202020 20202020 202c0102   
  19.  02c1020a 61612020 20202020 20202c01 0202c102 0a616120 20202020 2020202c   
  20.  010202c1 020a6161 20202020 20202020 2c010202 c1020a61 61202020 20202020   
  21.  202c0102 02c1020a 61612020 20202020 20202c01 0202c102 0a616120 20202020   
  22.  2020202c 010202c1 020a6161 20202020 20202020 2c010202 c1020a61 61202020   
  23.  20202020 202c0102 02c1020a 61612020 20202020 20202c01 0202c102 0a616120   
  24.  20202020 2020202c 010202c1 020a6161 20202020 20202020 2c010202 c1020a61   
  25.  61202020 20202020 200106f4 f6   
  26.   
  27.  <32 bytes per line>  
  28.   
  29. BBED> dump /v dba 5,12 offset 2170 count 16  
  30.  File: /home/oracle/backuptest/kel.dbf (5)  
  31.  Block: 12      Offsets: 2170 to 2185  Dba:0x0140000c  
  32. -------------------------------------------------------  
  33.  00000000 00000000 00000000 00000000 l ................  
  34.   
  35.  <16 bytes per line>  
  36.   
  37. BBED> modify 100 dba 5,12  
  38.  File: /home/oracle/backuptest/kel.dbf (5)  
  39.  Block: 12               Offsets: 2170 to 2185           Dba:0x0140000c  
  40. ------------------------------------------------------------------------  
  41.  64000000 00000000 00000000 00000000   
  42.   
  43.  <32 bytes per line>  
  44.   
  45. BBED> exit  

12、再次检查数据文件

[plain]  view plain  copy
  1. [oracle@kel backuptest]$ dbv file=kel.dbf   
  2.   
  3. DBVERIFY: Release 10.2.0.1.0 - Production on Wed Jul 9 00:49:44 2014  
  4.   
  5. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  6.   
  7. DBVERIFY - Verification starting : FILE = kel.dbf  
  8. Page 12 is marked corrupt  
  9. Corrupt block relative dba: 0x0140000c (file 5, block 12)  
  10. Bad check value found during dbv:   
  11. Data in bad block:  
  12.  type: 6 format: 2 rdba: 0x0140000c  
  13.  last change scn: 0x0000.0008f6f4 seq: 0x1 flg: 0x06  
  14.  spare1: 0x0 spare2: 0x0 spare3: 0x0  
  15.  consistency value in tail: 0xf6f40601  
  16.  check value in block header: 0xaa87  
  17.  computed block checksum: 0x64  
  18.   
  19.   
  20.   
  21. DBVERIFY - Verification complete  
  22.   
  23. Total Pages Examined         : 12800  
  24. Total Pages Processed (Data) : 4  
  25. Total Pages Failing   (Data) : 0  
  26. Total Pages Processed (Index): 0  
  27. Total Pages Failing   (Index): 0  
  28. Total Pages Processed (Other): 11  
  29. Total Pages Processed (Seg)  : 0  
  30. Total Pages Failing   (Seg)  : 0  
  31. Total Pages Empty            : 12784  
  32. Total Pages Marked Corrupt   : 1   --数据文件出现坏块  
  33. Total Pages Influx           : 0  
  34. Highest block SCN            : 587507 (0.587507)  

13、 把文件拷贝回ASM

[plain]  view plain  copy
  1. SQL> begin  
  2.   2  dbms_file_transfer.copy_file('dd','kel.dbf','sd','kel.dbf');  
  3.   3  end;  
  4.   4  /  
  5.   
  6. PL/SQL procedure successfully completed.  

14、对文件进行更名

[plain]  view plain  copy
  1. SQL> select name from v$datafile;  
  2.   
  3. NAME  
  4. --------------------------------------------------------------------------------  
  5. +RECOVER/omf/datafile/system.256.852236093  
  6. +RECOVER/omf/datafile/undotbs1.258.852236095  
  7. +RECOVER/omf/datafile/sysaux.257.852236095  
  8. +RECOVER/omf/datafile/users.259.852236095  
  9. +RECOVER/omf/datafile/kel.272.852423821  
  10.   
  11. SQL> alter tablespace kel rename datafile '+RECOVER/omf/datafile/kel.272.852423821'  
  12.   2  to '+recover/omf/datafile/kel.dbf';  
  13.   
  14. Tablespace altered.  
  15.   
  16. SQL> select name from v$datafile;  
  17.   
  18. NAME  
  19. --------------------------------------------------------------------------------  
  20. +RECOVER/omf/datafile/system.256.852236093  
  21. +RECOVER/omf/datafile/undotbs1.258.852236095  
  22. +RECOVER/omf/datafile/sysaux.257.852236095  
  23. +RECOVER/omf/datafile/users.259.852236095  
  24. +RECOVER/omf/datafile/kel.dbf  

15、 将数据文件online

[plain]  view plain  copy
  1. SQL> alter database datafile 5 online;  
  2. alter database datafile 5 online  
  3. *  
  4. ERROR at line 1:  
  5. ORA-01113: file 5 needs media recovery  
  6. ORA-01110: data file 5: '+RECOVER/omf/datafile/kel.dbf'  

16 、恢复坏块

[plain]  view plain  copy
  1. [oracle@kel backuptest]$ rman target /  
  2.   
  3. Recovery Manager: Release 10.2.0.1.0 - Production on Wed Jul 9 00:57:03 2014  
  4.   
  5. Copyright (c) 1982, 2005, Oracle.  All rights reserved.  
  6.   
  7. connected to target database: OMF (DBID=680034237)  
  8.   
  9. RMAN> recover datafile 5;  
  10.   
  11. Starting recover at 09-JUL-14  
  12. using target database control file instead of recovery catalog  
  13. allocated channel: ORA_DISK_1  
  14. channel ORA_DISK_1: sid=148 devtype=DISK  
  15.   
  16. starting media recovery  
  17. media recovery complete, elapsed time: 00:00:03  
  18.   
  19. Finished recover at 09-JUL-14  

17、 把数据文件online

[plain]  view plain  copy
  1. SQL> alter database datafile 5 online;  
  2.   
  3. Database altered.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值