python實現oracle資料泵匯出功能

kisslfcr發表於2016-08-03
指令碼如下:
[oracle@ycr python]$ more dump.py 
#/usr/bin/python
#coding:utf8

import sys
import os
import time

nowt=time.strftime('%Y%m%d%H',time.localtime())
excmd='expdp %s/%s@%s directory=YCRDUMP dumpfile=ycrdump%s.dmp' % (sys.argv[1],sys.argv[2],sys.argv[3],nowt)
result=os.system(excmd)

測試結果如下:

[oracle@ycr python]$ python dump.py test oracle ycr2              ---------三個引數分別為,使用者名稱test,密碼oracle和連線字串ycr2

Export: Release 12.1.0.2.0 - Production on Wed Aug 3 02:52:00 2016
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 "TEST"."SYS_EXPORT_SCHEMA_01":  test/********@ycr2 directory=YCRDUMP dumpfile=ycrdump2016080302.dmp 
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
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/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/STATISTICS/TABLE_STATISTICS
Processing object type SCHEMA_EXPORT/STATISTICS/MARKER
. . exported "TEST"."T2"                                 16.78 KB       4 rows
. . exported "TEST"."T3"                                 12.21 KB       3 rows
. . exported "TEST"."T1"                                     0 KB       0 rows
Master table "TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for TEST.SYS_EXPORT_SCHEMA_01 is:
  /u01/app/oracle/ycrdump2016080302.dmp
Job "TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Aug 3 02:52:46 2016 elapsed 0 00:00:44

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29135257/viewspace-2122885/,如需轉載,請註明出處,否則將追究法律責任。

相關文章