Batch File For Taking Cold Backup And Expdp

In many case, we need to take the Cold backup. I am happy to share this batch file, which will take the full database backup and finally it will automatically start the database after the Cold backup.

  1. Create a file name backup.txt and save the following contents:
    1. REM   
    2. echo off   
    3. echo coldbackup started   
    4. for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (   
    5. set dayofweek=%%i   
    6. set month=%%j   
    7. set day=%%k   
    8. set year=%%l   
    9. set curtime=%time%   
    10. set fname=BOOST-%%i-%%j-%%k-%%l   
    11. )   
    12. md e:\dbbackup\%fname%   
    13. set oracle_sid=boost --> here change your database name   
    14. sqlplus -s "sys/maku as sysdba" @e:\coldbackup.sql   
    15. echo cold backup completed succesffully.   
    16. pause   
    After saving, rename it as backup.bat.

  2. Now, create coldbackup.sql, given below:
    1. set lines 1000   
    2. set head off   
    3. set term off   
    4. set feedback off   
    5. spool e:\coldbackup.bat   
    6. select 'copy '||name||' e:\dbbackup\%fname%' from v$datafile;   
    7. select 'copy '||name||' e:\dbbackup\%fname%' from v$controlfile;   
    8. select 'copy '||name||' e:\dbbackup\%fname%' from v$tempfile;   
    9. select 'copy '||member||' e:\dbbackup\%fname%' from v$logfile;   
    10. spool off   
    11. shutdown IMMEDIATE   
    12. host e:\coldbackup.bat   
    13. startup   
    14. host del e:\coldbackup.bat   
    15. set term on   
    16. set head on   
    17. set feedback on   
    18. set verify on   
    19. EXIT   
    Keep this file in e:\ folder .

  3. Our script is ready. Now, run the batchfile "backup.bat". The script will first create a spool file, named "coldbackup.bat" and it contains the necessary command to copy the files from the command line and will execute this spooled batch file by host e:\coldbackup.bat. After the successful execution, we will delete this spooled batch file. We can see the Cold backup got generated in e:\dbbackup folder.

A simple batch file for taking date-wise expdp of a schema is given below: 

@ECHO OFF
: Sets the proper date and time stamp with 24Hr Time for log file naming
: convention

SET HOUR=%time:~0,2%
SET dtStamp9=%date:~-4%%date:~4,2%%date:~7,2%_0%time:~1,1%%time:~3,2%%time:~6,2%
SET dtStamp24=%date:~-4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
if "%HOUR:~0,1%" == " " (SET dtStamp=%dtStamp9%) else (SET dtStamp=%dtStamp24%)

set PATH=D:\oracle\product\10.2.0\db_1\BIN;%PATH% --> set your own path
D:\oracle\product\10.2.0\db_1\BIN\expdp aiwa/aiwa@proddb dumpfile=prod_aiwa_%dtStamp%.dmp logfile=prod_aiwa_%dtStamp%.log directory=DATA_PUMP_DIR schemas=aiwa
pause

Next Recommended Reading HOT and COLD Backups in Oracle