windows 系统下,小数据量Oracle用户物理备份

环境:windows Server 2003 oracle 10g,系统间备份

目标系统创建共享文件,原系统挂载共享目录

写批处理脚本,用任务计划定时调用

Rem * 由于系统实时性要求不是很高,数据量不大,且只有一块磁盘,考虑异地备份     *
Rem * 异地备份的时候使用expdp 出schema THUNIITSMUSER                           * 
Rem * 使用windows命令的共享文件模式,将dump出来的文件copy到192.168.1.47上      * 
Rem * create or replace directory dump_dir as 'E:\itsm_backup\dump_dir';       * 
Rem * 'copy /y E:\itsm_backup\dump_dir*.* \\Shouhou47\itms_databak\';          *
Rem * 此脚本通过windows计划任务每个工作日23:05调用,                            *
Rem * 保留7天的备份,七天之前的备份删除掉                                      *
Rem ****************************************************************************
Rem Characterset
Rem SQL> select * from v$nls_parameters;
Rem  
Rem PARAMETER                                                        VALUE
Rem ---------------------------------------------------------------- ---------------------------------
Rem NLS_LANGUAGE                                                     SIMPLIFIED CHINESE
Rem NLS_TERRITORY                                                    CHINA
Rem NLS_CURRENCY                                                     ¥
Rem NLS_ISO_CURRENCY                                                 CHINA
Rem NLS_NUMERIC_CHARACTERS                                           .,
Rem NLS_CALENDAR                                                     GREGORIAN
Rem NLS_DATE_FORMAT                                                  DD-MON-RR
Rem NLS_DATE_LANGUAGE                                                SIMPLIFIED CHINESE
Rem NLS_CHARACTERSET                                                 ZHS16GBK
Rem NLS_SORT                                                         BINARY
Rem NLS_TIME_FORMAT                                                  HH.MI.SSXFF AM
Rem NLS_TIMESTAMP_FORMAT                                             DD-MON-RR HH.MI.SSXFF AM
Rem NLS_TIME_TZ_FORMAT                                               HH.MI.SSXFF AM TZR
Rem NLS_TIMESTAMP_TZ_FORMAT                                          DD-MON-RR HH.MI.SSXFF AM TZR
Rem NLS_DUAL_CURRENCY                                                ¥
Rem NLS_NCHAR_CHARACTERSET                                           AL16UTF16
Rem NLS_COMP                                                         BINARY
Rem NLS_LENGTH_SEMANTICS                                             BYTE
Rem NLS_NCHAR_CONV_EXCP                                              FALSE
Rem  
Rem 19 rows selected
Rem 
Rem tablespace
Rem SQL> select username,default_tablespace from dba_users t where t.username='THUNIITSMUSER';
Rem 
Rem USERNAME                                                     DEFAULT_TABLESPACE
Rem ------------------------------------------------------------ -------------------------------
Rem THUNIITSMUSER                                                TBS_ITSM
Rem 
Rem ************************************************************************************************

echo begin time : %date%%time%
E:
cd E:\itsm_backup\dump_dir

set ORACLE_HOME=D:\oracle\product\10.2.0\db_1

set ORACLE_SID=itsmdb

set Today=%date:~0,4%%date:~5,2%%date:~8,2%

Rem 设置dump目录
set dumpdir=E:\itsm_backup\dump_dir\

Rem 设置具体文件
set dumpf=THUNIITSMUSER%Today%

Rem 如果文件已经存在删除
if exist %dumpdir%%dumpf%.log del %dumpdir%%dumpf%.log

if exist %dumpdir%%dumpf%.dmp del %dumpdir%%dumpf%.dmp

echo expdp begin : %date%%time%
Rem 导出schema

expdp \"/ as sysdba\" DUMPFILE=%dumpf%.dmp DIRECTORY=dump_dir SCHEMAS=THUNIITSMUSER logfile=THUNIITSMUSER%Today%.log

echo expdp end : %date%%time%
Rem ******************************************************************

Rem 挂载远程目录
if exist Z: net use Z: /delete
Rem (net use Z: \\192.168.1.47\itms_databak /user:"Administrator" "esenSHZ2014A")该目录被修改
net use Z: \\192.168.1.47\shouhuo47-L盘\itms_databak /user:"Administrator" "esenSHZ2014A"

Rem 设置备份目录
set backup_dir=Z:\
set dumpf=THUNIITSMUSER%Today%

Rem 判断文件在目标目录是否存在
if exist %backup_dir%%dumpf%.log del %backup_dir%%dumpf%.log
if exist %backup_dir%%dumpf%.dmp del %backup_dir%%dumpf%.dmp

Rem 转移到备份的地方
copy /y %dumpdir%%dumpf%.log %backup_dir%%dumpf%.log
copy /y %dumpdir%%dumpf%.dmp %backup_dir%%dumpf%.dmp

Rem 删除导出的数据文件及其日志
del %dumpdir%%dumpf%.dmp

del %dumpdir%%dumpf%.log

Rem ******************************************************************
Rem 删除七天前的备份

rem 计算指定天数之前的日期
set DaysAgo=7
rem 假设系统日期的格式为yyyy-mm-dd
call :DateToDays %date:~0,4% %date:~5,2% %date:~8,2% PassDays
set /a PassDays-=%DaysAgo%
call :DaysToDate %PassDays% DstYear DstMonth DstDay
set DstDate=%DstYear%%DstMonth%%DstDay%
echo %DaysAgo%天之前的日期是%DstDate%

REM set /a PassDays=%Today%-7
set dumpf=%backup_dir%THUNIITSMUSER%DstDate%

Rem IF [NOT] EXIST filename command
IF exist %dumpf%.log del %dumpf%.log

Rem del %dumpf%.log
IF exist %dumpf%.dmp del %dumpf%.dmp

Rem 删除远程目录
if exist Z: net use Z: /delete 

echo bat end : %date%%time%

goto :eof

:DateToDays %yy% %mm% %dd% days
setlocal ENABLEEXTENSIONS
set yy=%1&set mm=%2&set dd=%3
if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
set /a dd=100%dd%%%100,mm=100%mm%%%100
set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
endlocal&set %4=%j%&goto :EOF

:DaysToDate %days% yy mm dd
setlocal ENABLEEXTENSIONS
set /a a=%1+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
(if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
endlocal&set %2=%yy%&set %3=%mm%&set %4=%dd%&goto :EOF

 

posted @ 2014-10-22 18:03  Alex-Zeng  阅读(326)  评论(0编辑  收藏  举报