批处理文件[ 备份.bat] p.s:千万别自作聪明的把此批处理文件命名为exp.bat ,否则……,有兴趣的可以试试。O(∩_∩)O
@ echo off
REM ======================================================
REM 备份服务器 rsdlouter帐号下的数据
REM ======================================================
set BACKUP_DIR=D:\DATABACKUP
set BACKUP_WAREHOUSE=D:\DATABACKUP\DATABACKUP_LOG_DMP
set ORACLE_USERNAME=rsdlouter
set ORACLE_PASSWORD=rsdlouter
set ORACLE_DB=orcl
set BACK_OPTION="TABLES=(LOG,NEWS)"
set RAR_CMD="D:\Program Files\HaoZip\Rar.exe"
if not exist "DATABACKUP" md DATABACKUP
if not exist "DATABACKUP\DATABACKUP_LOG_DMP\" md DATABACKUP\DATABACKUP_LOG_DMP\
for /f "tokens=1,2" %%a in ('date/t') do set TODAY=%%a
REM 如果文件名中需要小时及分钟,用下面第一行语句
set BACK_NAME=%ORACLE_DB%_%ORACLE_USERNAME%_%TODAY%(%time:~0,2%时%time:~3,2%分%time:~6,2%秒)_
REM set BACK_NAME=%ORACLE_DB%_%ORACLE_USERNAME%_%TODAY%
set BACK_FULL_NAME=%BACKUP_DIR%\%BACK_NAME%
REM 将操作记入批处理日志 %BACK_FULL_NAME%_bat.log
echo ==================备份服务器 rsdlouter帐号下的数据================= >>%BACK_FULL_NAME%_bat.log
echo 备份开始...... >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
REM 调用exp工具
exp %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%_DMP md %BACKUP_WAREHOUSE%\%BACK_NAME%_DMP
echo 压缩并删除原有dmp文件...... >>%BACK_FULL_NAME%_bat.log
echo 当前的时间是: %DATE% %time% >>%BACK_FULL_NAME%_bat.log
%RAR_CMD% a -df "%BACKUP_DIR%\%BACK_NAME%_dmp.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%_DMP\
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 ===============备份服务器 rsdlouter帐号下的数据完成!!!============== >>%BACK_FULL_NAME%_bat.log
if not exist %BACKUP_WAREHOUSE%\%BACK_NAME%_LOG md %BACKUP_WAREHOUSE%\%BACK_NAME%_LOG
move %BACKUP_DIR%\*.log %BACKUP_WAREHOUSE%\%BACK_NAME%_LOG\
echo .
注意:将备份.bat文件放到D盘的根目录下执行,同时请根据情况修改set参数配置。
备份.bat配置完成后,利用Windows自带的任务计划即可配置在指定的时间执行此批处理文件了,任务计划配置很简单,在这里就不再赘述了。
如果配置任务计划出现异常请参考我的上一篇文章。
希望对朋友们有帮助!