最近在学习oracle11g的expdp逻辑备份数据库,遇到以下问题:
bash-4.1$ expdp yjj/123456 dumpfile=dir:yjj.dmp logfile=dir:yjj.log
Export: Release 12.1.0.2.0 - Production on Tue Apr 21 09:49:21 2015
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
在讲解错误原因以及 解决办法之前,先说一下expdp备份需要做的工作:
- 首先创建目录对象
SQL> create or replace directory dir as '/home/yjj/oraclebackup';
Directory created.
- 给目录对象赋予权限
SQL> grant read,write on directory dir to yjj;
Grant succeeded.
- 导出(直接在终端中运行)
bash-4.1$ expdp yjj/123456 dumpfile=dir:yjj.dmp logfile=dir:yjj.log
Export: Release 12.1.0.2.0 - Production on Tue Apr 21 09:51:01 2015
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Starting "YJJ"."SYS_EXPORT_SCHEMA_01": yjj/******** dumpfile=dir:yjj.dmp logfile=dir:yjj.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 13.31 MB
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
Processing object type SCHEMA_EXPORT/PROCEDURE/PROCEDURE
Processing object type SCHEMA_EXPORT/PROCEDURE/ALTER_PROCEDURE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
. . exported "YJJ"."LIST" 2.935 MB 11758 rows
. . exported "YJJ"."SE_FOODPRO" 914.1 KB 3898 rows
. . exported "YJJ"."SE_MEDICINE" 906.1 KB 6895 rows
. . exported "YJJ"."SE_TOOLBUSINESS" 1.495 MB 7273 rows
. . exported "YJJ"."SE_GSP" 726.4 KB 3988 rows
. . exported "YJJ"."SE_BUSINESS_COM" 170.6 KB 518 rows
. . exported "YJJ"."SE_HEALTH_CARE" 103.6 KB 348 rows
. . exported "YJJ"."SE_GMP" 87.76 KB 611 rows
. . exported "YJJ"."SE_MEDICINETOOL" 89.53 KB 455 rows
. . exported "YJJ"."SE_PRODUCT_COMP" 79.08 KB 243 rows
. . exported "YJJ"."SE_TABLECHANGE" 46.05 KB 68 rows
. . exported "YJJ"."SE_TOOLPRODUCT" 80.82 KB 239 rows
. . exported "YJJ"."APARTMENT" 6.031 KB 19 rows
. . exported "YJJ"."MAILBOX" 13.97 KB 34 rows
. . exported "YJJ"."PAGEVIEW" 5.875 KB 26 rows
. . exported "YJJ"."PERMISSION" 5.812 KB 7 rows
. . exported "YJJ"."PICTURE" 7.648 KB 5 rows
. . exported "YJJ"."SE_CONTRACTPRO" 24.66 KB 62 rows
. . exported "YJJ"."SE_COSMETIC" 17.39 KB 26 rows
. . exported "YJJ"."SE_INJECTGMP" 14.5 KB 22 rows
. . exported "YJJ"."SE_MED_PREPARA_CONTRACT" 9.382 KB 1 rows
. . exported "YJJ"."SE_MED_PREPARA_INSTI" 37.48 KB 120 rows
. . exported "YJJ"."SE_NOINJECTGMP" 34.88 KB 98 rows
. . exported "YJJ"."SE_ONECATAGORY" 8.960 KB 18 rows
. . exported "YJJ"."SE_SECOND" 17.75 KB 59 rows
. . exported "YJJ"."SE_TABLENUM" 6.281 KB 22 rows
. . exported "YJJ"."SE_VACCIN_COM" 10.72 KB 2 rows
. . exported "YJJ"."SE_YINGSU" 27.31 KB 146 rows
. . exported "YJJ"."SQGK" 12.99 KB 5 rows
. . exported "YJJ"."SUGGESTION" 8.976 KB 3 rows
. . exported "YJJ"."USER_COLUMN" 5.562 KB 9 rows
. . exported "YJJ"."USER_PERMISSION" 5.828 KB 8 rows
. . exported "YJJ"."USER_T" 8.351 KB 11 rows
. . exported "YJJ"."YCOLUMN" 11.14 KB 106 rows
Master table "YJJ"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for YJJ.SYS_EXPORT_SCHEMA_01 is:
/home/yjj/oraclebackup/yjj.dmp
Job "YJJ"."SYS_EXPORT_SCHEMA_01" successfully completed at Tue Apr 21 09:51:36 2015 elapsed 0 00:00:35
说明:
- 其实上面的创建目录对象sql语句不会实际创建目录,可以理解只是在sql环境中声明一个名为dir的目录,赋权限目录也不会实际赋予用户yjj权限。所以需要手动创建目录,手动赋予权限(赋予给谁,赋予要导出数据的你login的那个用户,例子中的是yjj用户);
- 笔者就是没有手动赋予yjj权限导致出现本文最开始出现的错误;
chmod 777 oraclebackup
后记:
- 笔者在网上搜寻错误的时候找到的一些解决办法都是在说
SQL> create or replace directory dir as '/home/yjj/oraclebackup/';
Directory created.
与
SQL> create or replace directory dir as '/home/yjj/oraclebackup';
Directory created.
的区别,笔者亲自测试没有这个区别的,导致错误之处也不在这儿;
- 相关的博文如下:
http://www.2cto.com/database/201303/195589.html
http://blog.163.com/jet_it_life/blog/static/205097083201262431444951/ - 最后在这片博文中找到错误之处,自己的疏忽
http://www.linuxidc.com/Linux/2013-12/94524.htm - 最后要说的一点是赋予权限那一步,赋予的是你要登入进去数据库的用户(就是要备份的那个用户),所以否则的话,即使在root下运行expdp备份语句也会出错,切记。
下面是我自己开的一个微信公众号 [瞬息之间],除了写技术的文章、还有产品的、行业和人生的思考,希望能和更多走在这条路上同行者交流,有兴趣可关注一下,谢谢。