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

相关推荐
乖巧的妹子8 小时前
SQL知识点
数据库·sql·oracle
Zww08919 小时前
erp系统常见优化点
数据库·oracle
—Miss. Z—12 小时前
计算机二级MySQL——基本操作题
数据库·mysql·oracle
G.O.G.O.G1 天前
《LeetCode SQL 从入门到进阶(MySQL)》06(下)
数据库·sql·oracle
Leon-Ning Liu2 天前
【真实经验分享】Oracle RAC 修改 db_file_name_convert / log_file_name_convert 参数实践
数据库·oracle
Leon-Ning Liu2 天前
【真实经验分享】Oracle RAC + ASM 下 db_recovery_file_dest 路径格式导致 ORA-01261 无法 NOMOUNT
数据库·oracle
踏月的造梦星球2 天前
DMHS同步原理与DM8到DM8基础搭建
数据库·oracle
微三云 - 廖会灵 (私域系统开发)2 天前
电商系统监控告警体系从0到1:Prometheus+Grafana+AlertManager的全链路可观测性实践
oracle·grafana·prometheus
G.O.G.O.G2 天前
LeetCode SQL 从入门到精通(MySQL)05(下)
数据库·sql·oracle
alxraves2 天前
医院远程会诊系统:数据库模块设计与实现
数据库·oracle