{"id":286,"date":"2012-05-08T10:56:33","date_gmt":"2012-05-08T07:56:33","guid":{"rendered":"http:\/\/fatihacar.com\/blog\/?p=286"},"modified":"2012-05-17T00:15:11","modified_gmt":"2012-05-16T21:15:11","slug":"how-to-take-export-backup-in-oracle-on-windows-servers","status":"publish","type":"post","link":"http:\/\/www.fatihacar.com\/blog\/how-to-take-export-backup-in-oracle-on-windows-servers\/","title":{"rendered":"How to Take Export Backup in Oracle on Windows Servers"},"content":{"rendered":"<p>If you want to take export backup on windows servers, you can take with batch scripts and windows schedule tasks. You can create backup directory for this scripts and backups. We will use EXPORTDIR directory and below data, scripts, daily directories. You have to create three scripts file below scripts directory for this issue. <\/p>\n<p>Firstly, you have to create export script file. The extension can be &#8220;.txt&#8221; for this file.<\/p>\n<p><strong>Export Script File : SchemaName.txt<\/strong><\/p>\n<blockquote><p>\nUSERID=sysbackup\/password<br \/>\nLOG=D:\\EXPORTDIR\\data\\data_SchemaName_exp.log<br \/>\nFILE=D:\\EXPORTDIR\\data\\data_SchemaName_expdat.dmp<br \/>\nGRANTS=y<br \/>\nINDEXES=y<br \/>\nROWS=y<br \/>\nCONSTRAINTS=y<br \/>\nOWNER=SchemaName\n<\/p><\/blockquote>\n<p>Secondly, you have to create execute script file. The extension can be &#8220;.bat&#8221; for this file. This file will execute SchemaName.txt file.  <\/p>\n<p><strong>Execute Export Script File : Export_SchemaName.bat<\/strong><\/p>\n<blockquote><p>\nset SHELL_DIR=D:\\EXPORTDIR\\scripts\\<br \/>\nset BACKUP_DIR=D:\\EXPORTDIR\\data\\<br \/>\nset BACKUP_DAY=%date:~10,4%%date:~4,2%%date:~7,2%<br \/>\nset BACKUP_DAILY=D:\\EXPORTDIR\\daily\\<br \/>\nset ORACLE_SID=YOURDBSID<\/p>\n<p>exp parfile=%SHELL_DIR%SchemaName.txt<br \/>\ndate \/T >> %BACKUP_DIR%log_SchemaName_exp.log\n<\/p><\/blockquote>\n<p>Thirdly, you have to create general executable batch file to execute export scripts of all schemas. This file will add windows schedule tasks. The extension can be &#8220;.bat&#8221; for this file. Also this script make zip file this backups. <\/p>\n<p><strong>Export File : Execute_Exports.bat<\/strong><\/p>\n<blockquote><p>\nset SHELL_DIR=D:\\EXPORTDIR\\scripts\\<br \/>\nset BACKUP_DIR=D:\\EXPORTDIR\\data\\<br \/>\nset BACKUP_DAY=%date:~10,4%%date:~4,2%%date:~7,2%<br \/>\nset BACKUP_DAILY=D:\\EXPORTDIR\\daily\\<br \/>\nset ORACLE_SID=YOURDBSID<\/p>\n<p>REM Deletin Old Files<\/p>\n<p>del %BACKUP_DAILY%* \/Q<\/p>\n<p>exp parfile=%SHELL_DIR%SchemaName.txt<br \/>\ndate \/T >> %BACKUP_DIR%log_SchemaName_exp.log<\/p>\n<p>copy %BACKUP_DIR%data_SchemaName_expdat.dmp %BACKUP_DIR%data_SchemaName_expdat_%BACKUP_DAY%.dmp<br \/>\n&#8220;C:\\Program Files (x86)\\WinRAR\\winrar.exe&#8221; a -p&#8221;yourwinrarpassword_.MKY&#8221; %BACKUP_DIR%data_SchemaName_expdat_%BACKUP_DAY%.rar %BACKUP_DIR%data_SchemaName_expdat_%BACKUP_DAY%.dmp<br \/>\ndel %BACKUP_DIR%data_SchemaName_expdat_%BACKUP_DAY%.dmp<br \/>\nmove %BACKUP_DIR%log_SchemaName_exp.log %BACKUP_DIR%log_SchemaName_exp_%BACKUP_DAY%.log<br \/>\ncopy %BACKUP_DIR%data_SchemaName_expdat_%BACKUP_DAY%.rar %BACKUP_DAILY%\n<\/p><\/blockquote>\n<p>Finally, you have to add windows schedule tasks for Execute_Exports.bat as daily, weekly&#8230;<br \/>\n<!--more--><br \/>\nLastly, if you want to delete old backups, you can create batch file and add windows schedule tasks.<\/p>\n<p><strong>Delete Old Backups File : Delete_Old_Backups.bat<\/strong><\/p>\n<blockquote><p>\n@ECHO OFF<br \/>\nECHO.<\/p>\n<p>:: Check the Windows version<br \/>\nIF NOT &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; GOTO Syntax<br \/>\nSETLOCAL<\/p>\n<p>:: Initialize variable<br \/>\nSET Error=0<br \/>\nSET cDays=-4<br \/>\nSET cDate=%date:~4,2%\/%date:~7,2%\/%date:~10,4%<br \/>\nSET sfold=D:\\BACKUPDIR\\data\\<br \/>\nSET dfold=D:\\BACKUPDIR\\temp\\<\/p>\n<p>:: Read the Date format from the registry<br \/>\nCALL :ReadDateFormat<\/p>\n<p>:: Check if a valid date was specified<br \/>\n(ECHO.%cDate%) | FINDSTR \/R \/B \/C:&#8221;[0-9]*\\%sDate%[0-9]*\\%sDate%[0-9]*&#8221; >NUL<br \/>\nIF ERRORLEVEL 1 (<br \/>\n        ECHO Error: %cDate% is not a valid date<br \/>\n        ECHO.<br \/>\n        GOTO Syntax<br \/>\n)<\/p>\n<p>:: Check if the second argument is a valid number<br \/>\n(ECHO.%cDays%) | FINDSTR \/R \/B \/C:&#8221;-*[0-9]*&#8221; >NUL<br \/>\nIF ERRORLEVEL 1 (<br \/>\n        ECHO Error: %cDays% is not an integer<br \/>\n        ECHO.<br \/>\n        GOTO Syntax<br \/>\n)<\/p>\n<p>:: Parse the date specified<br \/>\nCALL :ParseDate %cDate%<\/p>\n<p>:: Check for errors<br \/>\nIF %Error% NEQ 0 GOTO Syntax<\/p>\n<p>:: Convert the parsed Gregorian date to Julian<br \/>\nCALL :JDate %GYear% %GMonth% %GDay%<\/p>\n<p>:: Display original input<br \/>\nECHO Starting date   : %cDate%<\/p>\n<p>:: Add or subtract the specified number of days<br \/>\nIF &#8220;%cDays:~0,1%&#8221;==&#8221;-&#8221; (<br \/>\n        SET \/A NewJDate = %JDate% &#8211; %cDays:~1%<br \/>\n        ECHO Days subtracted : %cDays:~1%<br \/>\n) ELSE (<br \/>\n        SET \/A NewJDate = %JDate% + %cDays%<br \/>\n        ECHO Days added      : %cDays%<br \/>\n)<\/p>\n<p>:: Convert the new Julian date back to Gregorian again<br \/>\nCALL :GDate %NewJDate%<\/p>\n<p>:: Reformat the date to local format<br \/>\nCALL :ReformatDate %GDate%<\/p>\n<p>:: Display the result<br \/>\nECHO Resulting date  : %LDate%<\/p>\n<p>:: Action<br \/>\nCALL :DeleteOlder<\/p>\n<p>:: Return the result in a variable named after this batch file<br \/>\nENDLOCAL &#038; SET %~n0=%LDate%<br \/>\nGOTO:EOF<\/p>\n<p>:GDate<br \/>\n::<br \/>\nSET \/A P      = %1 + 68569<br \/>\nSET \/A Q      = 4 * %P% \/ 146097<br \/>\nSET \/A R      = %P% &#8211; ( 146097 * %Q% +3 ) \/ 4<br \/>\nSET \/A S      = 4000 * ( %R% + 1 ) \/ 1461001<br \/>\nSET \/A T      = %R% &#8211; 1461 * %S% \/ 4 + 31<br \/>\nSET \/A U      = 80 * %T% \/ 2447<br \/>\nSET \/A V      = %U% \/ 11<br \/>\nSET \/A GYear  = 100 * ( %Q% &#8211; 49 ) + %S% + %V%<br \/>\nSET \/A GMonth = %U% + 2 &#8211; 12 * %V%<br \/>\nSET \/A GDay   = %T% &#8211; 2447 * %U% \/ 80<br \/>\n:: Clean up the mess<br \/>\nFOR %%A IN (P Q R S T U V) DO SET %%A=<br \/>\n:: Add leading zeroes<br \/>\nIF 1%GMonth% LSS 20 SET GMonth=0%GMonth%<br \/>\nIF 1%GDay%   LSS 20 SET GDay=0%GDay%<br \/>\n:: Return value<br \/>\nSET GDate=%GYear% %GMonth% %GDay%<br \/>\nGOTO:EOF<\/p>\n<p>:JDate<br \/>\n:: Convert date to Julian<br \/>\n:: Arguments : YYYY MM DD<br \/>\n:: Returns   : Julian date<br \/>\n::<br \/>\n:: First strip leading zeroes<br \/>\nSET MM=%2<br \/>\nSET DD=%3<br \/>\nIF %MM:~0,1% EQU 0 SET MM=%MM:~1%<br \/>\nIF %DD:~0,1% EQU 0 SET DD=%DD:~1%<br \/>\n::<br \/>\n:: Algorithm based on Fliegel-Van Flandern<br \/>\n:: algorithm from the Astronomical Almanac,<br \/>\n:: provided by Doctor Fenton on the Math Forum<br \/>\n:: (http:\/\/mathforum.org\/library\/drmath\/view\/51907.html),<br \/>\n:: and converted to batch code by Ron Bakowski.<br \/>\nSET \/A Month1 = ( %MM% &#8211; 14 ) \/ 12<br \/>\nSET \/A Year1  = %1 + 4800<br \/>\nSET \/A JDate  = 1461 * ( %Year1% + %Month1% ) \/ 4 + 367 * ( %MM% &#8211; 2 -12 * %Month1% ) \/ 12 &#8211; ( 3 * ( ( %Year1% + %Month1% + 100 ) \/ 100 ) ) \/ 4 + %DD% &#8211; 32075<br \/>\nFOR %%A IN (Month1 Year1) DO SET %%A=<br \/>\nGOTO:EOF <\/p>\n<p>:ParseDate<br \/>\n:: Parse (Gregorian) date depending on registry&#8217;s date format settings<br \/>\n:: Argument : Gregorian date in local date format,<br \/>\n:: Requires : sDate (local date separator), iDate (local date format number)<br \/>\n:: Returns  : GYear (4-digit year), GMonth (2-digit month), GDay (2-digit day)<br \/>\n::<br \/>\nIF %iDate%==0 FOR \/F &#8220;TOKENS=1-3 DELIMS=%sDate%&#8221; %%A IN (&#8216;ECHO.%1&#8217;) DO (<br \/>\n        SET GYear=%%C<br \/>\n        SET GMonth=%%A<br \/>\n        SET GDay=%%B<br \/>\n)<br \/>\nIF %iDate%==1 FOR \/F &#8220;TOKENS=1-3 DELIMS=%sDate%&#8221; %%A IN (&#8216;ECHO.%1&#8217;) DO (<br \/>\n        SET GYear=%%C<br \/>\n        SET GMonth=%%B<br \/>\n        SET GDay=%%A<br \/>\n)<br \/>\nIF %iDate%==2 FOR \/F &#8220;TOKENS=1-3 DELIMS=%sDate%&#8221; %%A IN (&#8216;ECHO.%1&#8217;) DO (<br \/>\n        SET GYear=%%A<br \/>\n        SET GMonth=%%B<br \/>\n        SET GDay=%%C<br \/>\n)<br \/>\nIF %GDay%   GTR 31 SET Error=1<br \/>\nIF %GMonth% GTR 12 SET Error=1<br \/>\nGOTO:EOF<\/p>\n<p>:ReadDateFormat<br \/>\n:: Read the Date format from the registry.<br \/>\n:: Arguments : none<br \/>\n:: Returns   : sDate (separator), iDate (date format number)<br \/>\n::<br \/>\n:: First, export registry settings to a temporary file:<br \/>\nSTART \/W REGEDIT \/E &#8220;%TEMP%.\\_TEMP.REG&#8221; &#8220;HKEY_CURRENT_USER\\Control Panel\\International&#8221;<br \/>\n:: Now, read the exported data:<br \/>\nFOR \/F &#8220;tokens=1* delims==&#8221; %%A IN (&#8216;TYPE &#8220;%TEMP%.\\_TEMP.REG&#8221; ^| FIND \/I &#8220;iDate&#8221;&#8216;) DO SET iDate=%%B<br \/>\nFOR \/F &#8220;tokens=1* delims==&#8221; %%A IN (&#8216;TYPE &#8220;%TEMP%.\\_TEMP.REG&#8221; ^| FIND \/I &#8220;sDate&#8221;&#8216;) DO SET sDate=%%B<br \/>\n:: Remove the temporary file:<br \/>\nDEL &#8220;%TEMP%.\\_TEMP.REG&#8221;<br \/>\n:: Remove quotes from the data read:<br \/>\n:: SET iDate=%iDate:&#8221;=%<br \/>\nFOR %%A IN (%iDate%) DO SET iDate=%%~A<br \/>\n:: SET sDate=%sDate:&#8221;=%<br \/>\nFOR %%A IN (%sDate%) DO SET sDate=%%~A<br \/>\nGOTO:EOF<\/p>\n<p>:ReformatDate<br \/>\n:: Reformat the date back to the local format<br \/>\n:: Arguments : YYYY MM DD<br \/>\n:: Returns   : LDate (Gregorian date in local format)<br \/>\n::<br \/>\nIF %iDate%==0 SET LDate=%2%sDate%%3%sDate%%1<br \/>\nIF %iDate%==1 SET LDate=%3%sDate%%2%sDate%%1<br \/>\nIF %iDate%==2 SET LDate=%1%sDate%%2%sDate%%3<br \/>\nGOTO:EOF<\/p>\n<p>:DeleteOlder<br \/>\n:: Copy new files to another directory<br \/>\n:: Arguments : YYYY MM DD<br \/>\n:: Returns   : int<br \/>\n::<br \/>\nXCOPY %sfold%* %dfold%* \/d:%GMonth%-%GDay%-%GYear%<br \/>\nDEL %sfold%* \/Q<br \/>\nMOVE %dfold%* %sfold%<br \/>\nGOTO:EOF<\/p>\n<p>:Syntax<br \/>\nECHO DateAdd.bat,  Version 1.10 for Windows NT 4 \/ 2000 \/ XP \/ Server 2003 \/ Vista<br \/>\nECHO Add (or subtract) the specified number of days to (or from) the specified date<br \/>\nECHO.<br \/>\nECHO Usage:  DATEADD  [ date ]  days<br \/>\nECHO.<br \/>\nECHO Where:  &#8220;date&#8221;   is a &#8220;normal&#8221; Gregorian date in the local computer&#8217;s format<br \/>\nECHO                  (default value if no date is specified: today&#8217;s date)<br \/>\nECHO         &#8220;days&#8221;   is the number of days to add or subtract<br \/>\nECHO.<br \/>\nIF     &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; FOR %%A IN (%Date%) DO SET Today=%%A<br \/>\nIF     &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; ECHO E.g.    DATEADD %Today%  1 will return tomorrow&#8217;s date  (as will DATEADD  1)<br \/>\nIF     &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; ECHO         DATEADD %Today% -1 will return yesterday&#8217;s date (as will DATEADD -1)<br \/>\nIF     &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; ENDLOCAL<br \/>\nIF NOT &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; ECHO E.g.    DATEADD 01\/25\/2007  1 should return 01\/26\/2007<br \/>\nIF NOT &#8220;%OS%&#8221;==&#8221;Windows_NT&#8221; ECHO         DATEADD 01\/25\/2007 -1 should return 01\/24\/2007<br \/>\nECHO.<br \/>\nECHO Delete Completed.<br \/>\nECHO.<\/p><\/blockquote>\n<p>This solution can be provided that you can export backup of one and more schemas with changing three scipts. If you want to add the other schemas, you have to add newSchemanName.txt, Export_newSchemaName.bat and change Execute_Exports.bat script.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to take export backup on windows servers, you can take with batch scripts and windows schedule tasks. You can create backup directory for this scripts and backups. We will use EXPORTDIR directory and below data, scripts, daily directories. You have to create three scripts file below scripts directory for this issue. Firstly,&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[20],"tags":[23,14,90],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-oracle-backup-and-recovery","tag-backup-and-recovery-2","tag-database-administration","tag-oracle"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-4C","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=286"}],"version-history":[{"count":13,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":300,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions\/300"}],"wp:attachment":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}