第一种方式:我自己用的脚本
set BACKUP_DIR=backup
set ORACLE_USERNAME=masicong
set ORACLE_PASSWORD=masicong
set ORACLE_DB=orcl
set BACK_OPTION=SCHEMAS=masicong
set RAR_CMD="C:\Program Files\WinRAR\Rar.exe"
set DUMPDIR=DIRECTORY=dump_dir
for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%a
set BACK_NAME=%ORACLE_DB%%TODAY%
set BACK_FULL_NAME=%BACK_NAME%
rem 开始备份
expdp %ORACLE_USERNAME%/%ORACLE_PASSWORD% %DUMPDIR% %BACK_OPTION% dumpfile=%BACK_FULL_NAME%.dmp logfile=%BACK_FULL_NAME%exp.log
rem 压缩并剔除原有资料
%RAR_CMD% a -df "%BACK_FULL_NAME%back.rar" "%BACK_FULL_NAME%.dmp" "%BACK_FULL_NAME%exp.log"
PAUSE
第二种方式:
@echo off
@echo =========================================================================
@echo Oracle 10g 数据库的自动导出备份脚本(windows环境)。
@echo 说明:启动备份时,需要配置以下变量
@echo 1、BACKUP_DIR 指定要备份到哪个中间目录,压缩完成后将被移动到BACKUP_WAREHOUSE目录下
@echo 2、BACKUP_WAREHOUSE 指定历史备份数据(压缩后的)及日志的存放位置
@echo 3、ORACLE_USERNAME 指定备份所用的Oracle用户名
@echo 4、ORACLE_PASSWORD 指定备份所用的Oracle密码
@echo 5、ORACLE_DB 指定备份所用的Oracle服务名
@echo 6、BACK_OPTION 备份选项,可以为空,可以为full=y,可以为owner=a用户,b用户 或 TABLES=() 等等....
@echo 7、RAR_CMD 指定RAR命令行压缩工具所在目录
@echo =========================================================================
REM ======================================================
REM 备份103服务器 ITCQB 帐号下的数据
REM ======================================================
rem 以下变量需要根据实际情况配置
set BACKUP_DIR=E:\11
set BACKUP_WAREHOUSE=e:\11\11
set ORACLE_USERNAME=manager
set ORACLE_PASSWORD=masicong
set ORACLE_DB=orcl
set BACK_OPTION="SCHEMAS=ekpuser"
set RAR_CMD="C:\Program Files\WinRAR\Rar.exe"
for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%a
REM 如果文件名中需要小时及分钟,用下面第一行语句
REM set BACK_NAME=%ORACLE_DB%_%TODAY%(%time:~0,2%时%time:~3,2%分)_
set BACK_NAME=%ORACLE_DB%_%ORACLE_USERNAME%_%TODAY%
set BACK_FULL_NAME=%BACKUP_DIR%\%BACK_NAME%
REM 将操作记入批处理日志 %BACK_FULL_NAME%_bat.log
echo ==================备份103服务器 ITCQB帐号下的数据================= >>%BACK_FULL_NAME%_bat.log
echo 备份开始...... >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
expdp%ORACLE_USERNAME%/%ORACLE_PASSWORD%@%ORACLE_DB%grants=Y %BACK_OPTION% file="%BACK_FULL_NAME%.dmp" log="%BACK_FULL_NAME%_exp.log"
if not exist %BACKUP_WAREHOUSE%\%BACK_NAME%_LOGIC (md %BACKUP_WAREHOUSE%\%BACK_NAME%_LOGIC)
echo 压缩并删除原有dmp文件...... >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
%RAR_CMD% a -df "%BACK_NAME%_logic.rar" "%BACK_FULL_NAME%.dmp"
REM "%BACK_FULL_NAME%exp.log"
echo 压缩并删除原有dmp文件结束! >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
echo 开始移动文件...... >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
move %BACKUP_DIR%\*.rar %BACKUP_WAREHOUSE%\%BACK_NAME%_LOGIC\
echo 移动文件完成! >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
REM net send %userdomain% "数据库逻辑备份已于:%DATE% %time% 完成!"
echo .
echo 备份完成!!! >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
echo ===============备份103服务器 ITCQB帐号下的数据完成!!!============== >>%BACK_FULL_NAME%_bat.log
move %BACKUP_DIR%\*.log %BACKUP_WAREHOUSE%\%BACK_NAME%_CLOGIC\
echo .
本文出自 “无双城” 博客,谢绝转载!