Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ravi .

Asked: May 02, 2000 - 1:20 pm UTC

Last updated: November 06, 2007 - 3:18 pm UTC

Version:

Viewed 1000+ times

You Asked

When I take Export on NT How do I embed date for the file.

Example.
exp file=exp_prod_xxxxxxxx

xxxxxxxx should be the system date(12012000).

On Unix I can use shell variable like $A How do I do the same On NT.


and Tom said...

I'll cheat. I'll show you a way to do this that works in Unix and NT. Instead of trying to force the NT .cmd script language into unnatural acts or tell you to buy a 3'rd party "Unix" shell -- we'll use SQLPlus as our general purpose scripting tool.

Say you have a file, export.cmd, that looks like this:

--------------- export.cmd -----------------
echo off

sqlplus scott/tiger @doexport
---------------- eof ---------------------

the line sqlplus scott/tiger @doexport is in place of

exp userid=scott/tiger ......

the script doexport.sql looks like:

-------------- doexport.sql ----------------------------
column today new_val dt

select to_char( sysdate, 'ddmmyyyy' ) today from dual;

host exp userid=scott/tiger tables=emp file=exp_prod_&dt..exp

exit
-------------- eof -------------------------------------


That should work on all platforms.


Rating

  (16 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Martin Haltmayer, July 04, 2001 - 9:08 am UTC


A reader, July 21, 2001 - 3:47 am UTC

Finally got the solution for my problem

date embed in export file name

Onkar, February 22, 2005 - 10:52 pm UTC

hi Tom,

I have got another option for the same. To add date in the export dump file name we use a script like this:
*************************************
@echo off
for /f "tokens=1,2,3,4 delims=/ " %%a in ('date /t') do set fdate=%%a%%b%%c%%d
exp user/pass@string file=export_%fdate%.dmp
*************************************
I use this script daily to take export backup with date embedded file name.



Tom Kyte
February 23, 2005 - 2:04 am UTC

make it work on unix now, or OS/390, or the Mac :)

there are many OS specific ways to accomplish this, that is true.

Prefect!

patrick, February 23, 2005 - 2:25 pm UTC

Thank you! Excellent! Been looking for that one

14th Nov, 2005

Nitin Gupta, November 14, 2005 - 1:51 am UTC

Yes, it was indeed helpful

Tom Fox, February 16, 2006 - 12:12 pm UTC

Ahhh, any way to do this in OEM via a scheduled job?

I'm trying to utilize OEM's preferred credentials, so that eliminates hard coding the username/password in the script.

I can't seem to make Google my friend on this one.

Set file name to include todays date

Ned, May 05, 2006 - 8:29 pm UTC

Great, was looking for this all week. First time I found a nice simple line to include in a batch file to do what should be this easy a task. Thanks

Export to a named file on NT

M.S.Murugupandiyan, July 06, 2006 - 2:50 am UTC

This is what i want...thanks a lot...

How to go about this ?

Parikshit Paul, September 16, 2006 - 8:32 am UTC

Hi Tom,

The following problem is causing me to scratch my head vigoursly.(^_^)

I am exporting a schema of a database (in Solaris), whose size is quite huge.I use the "pipe and compress" strategy to achieve the same. here is the code i use
=====================================================
mknod exp_schema.dmp p
compress < exp_schema.dmp > exp_schema.dmp.Z &
exp uid/pwd owner=xxx file=exp_schema.dmp ......
=====================================================
The problem is, still, the file size of the compressed file is 11 GB.
So i want to break the (compressed) dump file intp two or more.How will i acheive this keeping the above startegy constant?
I think the exp parameter filesize won't work because the of the fact that the .dmp file is actually a pipe.

Tom Kyte
September 16, 2006 - 2:57 pm UTC

wow

Parikshit Paul, September 18, 2006 - 7:26 am UTC

Excellent tom !
thanks so much

exp example

Zahid Lakhani, September 19, 2006 - 1:08 am UTC

excellent demonstration

Export doesn't like AS SYSDBA

Phil, February 05, 2007 - 5:50 pm UTC

Tom,

Great information as usual, but when I try to run a full database export as:
exp sys/password@mydb as sysdba full=y statistics=none file=somename.dmp log=somename.log

It complains about the AS of the AS SYSDBA phrase. How can I specify that in a command line to automate this?
Tom Kyte
February 05, 2007 - 6:44 pm UTC

one way is to let it prompt you - however, you do know that "as sysdba" or "sys" in general cannot do consistent exports right - just won't work.

I do not recommend doing this.

Reader, February 06, 2007 - 4:23 am UTC

Wish I had seen this 3 years back...

export.cmd/doexport.sql is great...

Thanks a lot Tom

So which user for a consistent full database export?

Phil, February 06, 2007 - 4:33 pm UTC

Tom, I took your advice, since I do want a consistent full database export and did not use the SYS user. I used SYSTEM, but received an EXP-00079 from the OE schema's Purchase Order table. The OE Schema is an Oracle Sample Schema that I don't use, but I'd like the Full export to terminate without errors. Any suggestions?
Tom Kyte
February 06, 2007 - 4:44 pm UTC

grant EXEMPT ACCESS POLICY

to your OWN dba account and use that. Don't use sys, don't use system - consider them off limits for stuff.

how to do the original answer using EXPDP

LJ, November 03, 2007 - 3:25 pm UTC

Hi Tom -

I've been using the original answer to this question with exp and it's been nice. But now would like to switch to using EXPDP instead, but haven't been able to make it work.

Can you show a good example of how to retool this for EXPDP?

Thanks,

LJ
Tom Kyte
November 05, 2007 - 11:23 am UTC

you'll have to wait till 11g when expdp supports compress=data

prior to that, expdp would not write to an existing file. and the pipe would be an existing file

How to implement "grant EXEMPT ACCESS POLICY" on 8.1.7

Sinan Topuz, November 06, 2007 - 1:49 pm UTC


Tom,

Is this an Oracle 10g feature? I could not grant this to an account in 8.1.7. Is there an alternative way of granting the same thing to a DBA account in a 8.1.7 system (Standard Edition), so that it can take full consistent exports of the database?

Thank you.

Tom Kyte
November 06, 2007 - 3:18 pm UTC

that was a 9i Release 1 feature that was not available prior to that.

prior to that, you'd have to incorporate the logic into the vpd function.

but - I hope you are not using export as a backup tool - because it isn't one. there is only one backup, that is a proper, real backup