【EXP】在备份文件上留下“时间烙印”

使用EXP工具备份备份用户数据时,在备份文件上打上时间标记是一个非常好的习惯,简单记录一下如何在不同的操作系统平台上完成这个任务,供参考。

1.UNIX或Linux操作系统
1)可以使用date操作系统命令辅助完成这个小任务
secooler@secDB /exp$ exp sec/sec file=`date +"%Y%m%d"`_sec.dmp log=`date +"%Y%m%d"`_sec.log

Export: Release 11.2.0.1.0 - Production on Thu Mar 25 22:51:12 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing option
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC
About to export SEC's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC's tables via Conventional Path ...
. . exporting table                              T    1155520 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.

2)查看生成的备份文件
secooler@secDB /exp$ ls -ltr
total 128M
-rw-r--r-- 1 oracle oinstall 1.4K Mar 25 22:51 20100325_sec.log
-rw-r--r-- 1 oracle oinstall 128M Mar 25 22:51 20100325_sec.dmp

OK,生成的备份文件和日志文件均打上了时间的烙印!

2.Windows操作系统
1)看一下在Windows系统中date命令的使用方法
(1)date命令显示格式
D:\>echo %date%
2010-03-25 周四

(2)只选择前10位的日期内容
D:\>echo %date:~0,10%
2010-03-25

注意,我们需要选择日期形式以中横杠为分隔的形式(如果是“/”分隔的话在生成备份文件时会报错)。
修改日期显示格式的步骤如下:
控制面板 --> “Clock, Language, and Region”--> “Set the time and date” --> “Change calendar settings” --> “Date formats” --> 在“Short date”右侧下拉框中选择“yyyy-M-d”格式。

2)使用Windows操作系统的date命令达到我们的“时间烙印”目的
D:\>exp sec/sec@sec file=%date:~0,10%_sec.dmp log=%date:~0,10%_sec.log

Export: Release 10.2.0.3.0 - Production on Thu Mar 25 23:23:44 2010

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP, Data Mining,
Oracle Database Vault and Real Application Testing option
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set

About to export specified users ...
. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user SEC
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user SEC
About to export SEC's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions
. about to export SEC's tables via Conventional Path ...
. . exporting table                              T    1155520 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.


3)确认在Windows上生成的备份文件和日志文件的格式
D:\>dir %date:~0,10%_sec*
 Volume in drive D has no label.
 Volume Serial Number is 4CC5-8E99

 Directory of D:\

2010-03-25  23:24       133,310,464 2010-03-25_sec.dmp
2010-03-25  23:24             1,378 2010-03-25_sec.log
               2 File(s)    133,311,842 bytes
               0 Dir(s)  11,578,949,632 bytes free

OK,任务完成。

3.小结
备份命令EXP和操作系统命令date相结合可以很好的实现留下“时间烙印”的目的,当然也可以编写一段脚本实现同样的效果,不过我们最求的是一种简便易行的方法。

Good luck.

secooler
10.03.25

-- The End --

请使用浏览器的分享功能分享到微信等