创建bat文件,在把下面内容复制后修改!适用于windows!
@echo off
REM ###########################################################
REM # Windows下Oracle数据库自动备份批处理脚本
REM ###########################################################
REM 取当前系统时间,可能因操作系统不同而取值不一样
set CURDATE=%date:~0,4%%date:~5,2%%date:~8,2%
set CURMON=%date:~0,4%%date:~5,2%
set CURTIME=%time:~0,2%
::delete
set /a deldata=CURDATE-7
set RAR_CMD="C:\Program Files\WinRAR\Rar.exe"
REM 小时数如果小于10,则在前面补0
if "%CURTIME%"==" 0" set CURTIME=00
if "%CURTIME%"==" 1" set CURTIME=01
if "%CURTIME%"==" 2" set CURTIME=02
if "%CURTIME%"==" 3" set CURTIME=03
if "%CURTIME%"==" 4" set CURTIME=04
if "%CURTIME%"==" 5" set CURTIME=05
if "%CURTIME%"==" 6" set CURTIME=06
if "%CURTIME%"==" 7" set CURTIME=07
if "%CURTIME%"==" 8" set CURTIME=08
if "%CURTIME%"==" 9" set CURTIME=09
set CURTIME=%CURTIME%%time:~3,2%%time:~6,2%
REM 设置所有者、用户名和密码
set OWNER=10.51.11.222:1521/xydb
set USER=dataquality
set PASSWORD=dataquality
REM 创建备份用目录,目录结构为oraclebak/YYYYMMDD/
if not exist "C:\databak\dataquality" mkdir C:\databack\dataquality
set DATADIR=C:\databak\dataquality
REM if not exist "%CURMON%" mkdir %CURMON%
set FILENAME=dataquality_%CURDATE%.DMP
set EXPLOG=dataquality_%CURDATE%.log
set RARPATH=%CURDATE%.rar
REM 调用ORACLE的exp命令导出用户数据
exp %USER%/%PASSWORD%@%OWNER% file=%FILENAME% log=%EXPLOG% owner=%USER%
::设定连接ftp所需参数
set localdmp=C:\databak\dataquality\%FILENAME%
set locallog=C:\databak\dataquality\%EXPLOG%
set deletedmp=dataquality_%deldata%.DMP
set deltetlog=dataquality_%deldata%.log
set ftpip=10.50.10.111
set username=zzzz
set password=zzzz
set dataPath=.\databak\dataquality
::连接ftp
Echo open %ftpip% >ftp.up
Echo %username%>>ftp.up
Echo %password%>>ftp.up
::打开ftp路径并上传文件
Echo cd %dataPath% >>ftp.up
Echo binary>>ftp.up
Echo put %localdmp%>>ftp.up
Echo put %locallog%>>ftp.up
::delete
echo delete %deletedmp%>>ftp.up
echo delete %deltetlog%>>ftp.up
Echo bye>>ftp.up
FTP -s:ftp.up
del ftp.up /q
REM 压缩
REM %RAR_CMD% a -df "%RARPATH%" "%FILENAME%" "%EXPLOG%"
REM 删除30天前的备份。
set DaysAgo=30
forfiles /p %DATADIR% /s /m *.dmp /d -%DaysAgo% /c "cmd /c del /f /q /a @path"
exit