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

相关推荐
杨云龙UP9 小时前
Oracle 19c 单机到单机 Active Data Guard 搭建与巡检操作手册
数据库·oracle·adg·操作指南·data guard·dg搭建
我科绝伦(Huanhuan Zhou)12 小时前
oracle坏块导致备份不了
数据库·oracle·ffmpeg
杨云龙UP14 小时前
Oracle 19c RAC到RAC Active Data Guard标准搭建与巡检指南
运维·服务器·数据库·oracle·adg·data guard·rac到rac
许彰午14 小时前
06-Oracle卸载与重装完整流程
数据库·oracle
我的xiaodoujiao14 小时前
Django 基础知识详细图文教程 13-Django 模型定义与使用 3
数据库·后端·python·测试工具·oracle·django
我科绝伦(Huanhuan Zhou)15 小时前
oracle RAC共享存储换盘操作指南
数据库·oracle
wangbing112515 小时前
重建oracle服务
数据库·oracle
shaibdoio15 小时前
瞬维AI落地经验:AI Agent工具调用准确率怎么提
数据库·人工智能·oracle
jnrjian2 天前
Oracle Inlist 和exists的最佳执行计划
oracle
许彰午2 天前
01-Oracle数据库简介与版本选择
数据库·oracle