Windows环境下Oracle定时备份

1、新建oracle_backup.bat文件,加入如下内容

@echo off

forfiles /p "D:\hmykt_backup_db(备份文件存储路径)" /d -30 /c "cmd /c echo deleting @file ... && del /f @path" 
echo 执行完成!

set RAR_CMD="E:\Program Files\WinRAR\WinRAR.exe(压缩工具路径)"
set SIDDISCRIBE=127.0.0.1:1521/orcl(数据库地址)
set DIRECTIONPATH=D:\hmykt_backup_db(备份文件存储路径)

set hour=%time:~,2%
if "%time:~,1%"==" " set hour=0%time:~1,1%
set TIMESTYLE=%date:~0,4%-%date:~5,2%-%date:~8,2%


echo ============================================
echo 设置2018年数据库参数
echo ============================================
set USERNAME_2018=ocs_init(用户名)
set PASSWORD_2018=ocs_init(密码)
set CONDETION_2018=%USERNAME_2018%/%PASSWORD_2018%@%SIDDISCRIBE%

echo ============================================
echo 设置2018年数据库导出文件、日志文件、压缩文件路径属性名称
echo ============================================
set FILEPATH_2018=%DIRECTIONPATH%/%USERNAME_2018%_%TIMESTYLE%.dmp
set LOGPATH_2018=%DIRECTIONPATH%/%USERNAME_2018%_%TIMESTYLE%.log
set RARPATH_2018=%DIRECTIONPATH%/%USERNAME_2018%_%TIMESTYLE%.rar

echo ============================================
echo 按照数据库年度,备份Oracle数据库,请稍等......
echo ============================================

exp userid=%CONDETION_2018% file=%FILEPATH_2018% log=%LOGPATH_2018%

echo 备份完成!

echo ============================================
echo 按照数据库年度,压缩备份文件,请稍等......
echo ============================================

%RAR_CMD% a -df "%RARPATH_2018%" "%FILEPATH_2018%" "%LOGPATH_2018%"

echo 压缩完成!

2、D盘新建hmykt_backup_db文件夹

在这里插入图片描述

3、创建定时任务

(1)点击创建基本任务
Windows环境下Oracle定时备份_第1张图片

(2)点击下一步
Windows环境下Oracle定时备份_第2张图片

(3)选择‘每天’,点击‘下一步’
Windows环境下Oracle定时备份_第3张图片

(4)设置每天定时备份时间,点击‘下一步’
Windows环境下Oracle定时备份_第4张图片

(5)选择‘启动程序’,点击‘下一步’
Windows环境下Oracle定时备份_第5张图片

(6)选择备份脚本
Windows环境下Oracle定时备份_第6张图片

(7)点击‘完成’
Windows环境下Oracle定时备份_第7张图片

4、执行bat文件进行备份

Windows环境下Oracle定时备份_第8张图片
备份完成
Windows环境下Oracle定时备份_第9张图片

你可能感兴趣的:(Oracle)