expdp file 带时间戳 date

Applies To

All Users

Summary

How to create dumpfile and logfile with timestamp in their names while using expdp?

This is required by users who have scheduled their daily export (using expdp) as a job and don't want their dumpfile or the logfiles to be overwritten.

Solution

There is no such option in expdp for giving timestamp in the names of the dumpfile or the logfile but it can be achieved using the following script. The suggestion is to generate an expdp command line using a shell/batch script by adding the timestamp in the names of dumpfile and logfile. For example, if a full export is taken, then the command would be:
#> expdp system/<PASSWORD> DIRECTORY=DATA_PUMP_DIR DUMPFILE=testdmp.dmp LOGFILE=testlog.log full=y

Now the above command will generate dumpfile and logfile with the names testdmp.dmp and testdmp.log respectively. But if you want to include the timestamp in their names then the above expdp command can be broken into parts in a shell script and the complete command can be generated dynamically.
-- On UNIX Platforms
vi expdpts.sh

cd $ORACLE_HOME/bin

cmd1="expdp system/<PASSWORD> DIRECTORY=DATA_PUMP_DIR DUMPFILE=testdmp"
dmpfile=`date +%Y-%m-%d-%H-%M-%S`
cmd2=".dmp LOGFILE=testlog"
cmd3=".log full=y"

totcmd=cmd1dmpfilecmd2dmpfilecmd3 totcmd

$ sh expdpts.sh

You can also use something similar to:
expdp .... dumpfile=expdp_'date +"%Y%b%d-%H%M%S"'.dmp logfile=log_expdp_'date +"%Y%b%d-%H%M%S"'.log job_name=job_'date +"%Y%b%d-%H%M%S"'

-- On Windows platforms
c:>edit expdpts.bat

set cmd1=expdp system/<PASSWORD> DIRECTORY=DATA_PUMP_DIR DUMPFILE=testdmp
set time_=%time: =0%
set dmpfile=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time_:~0,2%-%time_:~3,2%-%time_:~6,2%
set cmd2=.dmp LOGFILE=testlog
set cmd3=.log full=y
set totcmd=%cmd1%%dmpfile%%cmd2%%dmpfile%%cmd3%
%totcmd%

c:\>expdpts.bat

The following export will be started:
expdp system/<PASSWORD> DIRECTORY=DATA_PUMP_DIR DUMPFILE=testdmp2012-08-31-08-04-59.dmp LOGFILE=testlog2012-08-31-08-04-59.log full=y

Attachments :

Article Feedback

相关推荐
六月雨滴2 小时前
存储性能监控与优化及最佳实践总结
数据库·oracle·dba
学习论之费曼学习法2 小时前
Agent记忆系统:让AI拥有长期记忆能力
数据库·人工智能·oracle
arronKler4 小时前
数据库设计三大范式
数据库·oracle
oradh5 小时前
Oracle物理存储结构概述
数据库·oracle·物理结构·oracle基础·oracle入门·oracle物理存储结构概述
数据最前线6 小时前
亡羊补牢?Oracle 计划推出月度安全补丁
数据库·oracle
这个DBA有点耶7 小时前
某银行核心系统从Oracle迁移到国产数据库全程复盘(DBA视角)
数据库·经验分享·sql·oracle·dba·智能硬件
阿坤带你走近大数据7 小时前
DM达梦数据库的介绍
数据库·mysql·oracle·国产信创
我科绝伦(Huanhuan Zhou)8 小时前
oracle linux8.8一键部署oracle 11g
数据库·oracle
数据库小学妹8 小时前
企业级数据库迁移实践:从Oracle到国产数据库的兼容性与实施策略
数据库·mysql·oracle·dba