CMD常用命令02定期备份Oracle

项目实施后,为了以防万一,决定每天夜里备份数据库
虽然Oracle本身就有自动备份的功能,但我仍然不放心于是用bat和windows的任务计划进行了备份

REM HANSEN 2011-03-31
REM 用于备份Oracle数据库
color 2

set FilePath=S:/Backup/
set UserName=user
set PassWord=pwd
set ServiceName=orcl

if not exist "%FilePath%" (exit)

set FileName=%DATE:~0,10%-%TIME:~0,8%
set FileName=%FileName::=-%

set FileName=%FileName: =0%
set DBFile=%FilePath%%FileName%.dmp
set LogFile=%FilePath%%FileName%.log

echo ORACLE数据库备份开始
echo %DATE:~0,10% %TIME:~0,8%
echo ORACLE数据库备份数据保存到%DBFile%
echo ORACLE数据库备份日志保存到%LogFile%

exp %UserName%/%PassWord%@%ServiceName% file=%DBFile% log=%LogFile% compress=y direct=n rows=y 
owner='%UserName%' consistent=n constraints=y grants=y indexes=y triggers=y

另外又加了个定期删除的bat,但这个有些问题的,就是只考虑了备份文件的创建时间,并没有考虑到要保留几个备份
换句话说,当连续7天备份失败后,就没有备份了,所以请修改一下再用

Rem Delete Files Older Than One Week
set FilePath=E:/Backup/
forfiles /p %FilePath% /s /m *.dmp /d -7 /c "cmd /c del @file
forfiles /p %FilePath% /s /m *.log /d -7 /c "cmd /c del @file

Leave a Reply

Your email address will not be published. Required fields are marked *

*