前提是在WINDOWS 7上面安装好了Oralce的客服端,并且还要设置好%OraClient10g_home%\NETWORK\ADMIN\tnsnames.ora
在tnsnames.ora中有对应的set DATABASE=ECARD,Ecard与下面的Bat文件里面设置的变量要一直,都是搞程序的,你懂的!
@echo off
REM ###########################################################
REM # Windows 7 下Oracle数据库自动备份批处理脚本
REM ###########################################################
REM 设置备份的目录
set basedir=c:\EnterAccount2.0\backup
REM window7中可以用mkdir创建嵌套目录,如mkdir a\b
if not exist %basedir% mkdir %basedir%
REM 设置日志文件 backup_run.log
set log_file=
if "%1" == "1" set log_file=%basedir%\backup_run_beforedayend.log
if "%1" == "2" set log_file=%basedir%\backup_run_afterdayend.log
REM 删除日志文件
if exist %basedir%\backup_run_beforedayend.log del %basedir%\backup_run_beforedayend.log
if exist %basedir%\backup_run_afterdayend.log del %basedir%\backup_run_afterdayend.log
echo 开始执行备份[%date%] >%log_file% 2>&1
echo ########################################################### >>%log_file% 2>&1
REM 创建日终前备份目录
if not exist %basedir%\beforedayend mkdir %basedir%\beforedayend >>%log_file% 2>&1
REM 创建日终后备份目录
if not exist %basedir%\afterdayend mkdir %basedir%\afterdayend >>%log_file% 2>&1
REM 取得一个星期的第几天
set weekday=%date:~-1%
if %weekday%==日 set num=0
if %weekday%==一 set num=1
if %weekday%==二 set num=2
if %weekday%==三 set num=3
if %weekday%==四 set num=4
if %weekday%==五 set num=5
if %weekday%==六 set num=6
REM echo %weekday%
REM 设置所有者、用户名和密码
set DATABASE=ECARD
set USER=ttecard
set PASSWORD=ttecard
REM 设置备份文件
set backupfile=
if "%1" == "1" set backupfile=%basedir%\beforedayend\bfdbs%num%.dmp
if "%1" == "2" set backupfile=%basedir%\afterdayend\afdbs%num%.dmp
REM %backupfile%
if exist %backupfile% del %backupfile% >>%log_file% 2>&1
REM 调用ORACLE的exp命令导出用户数据
if "%1" == "1" exp %USER%/%PASSWORD%@%DATABASE% file=%backupfile% compress=n tables=ecard.TR_ACCOUNTS >>%log_file% 2>&1
if "%1" == "2" exp %USER%/%PASSWORD%@%DATABASE% file=%backupfile% owner=%USER% compress=n grants=n indexes=y rows=y >>%log_file% 2>&1
echo ########################################################### >>%log_file% 2>&1
echo 备份完成 >>%log_file% 2>&1
exit