问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

请问怎么实现oracle数据库的自动定时增量备份呢?

发布网友 发布时间:2022-04-25 12:21

我来回答

2个回答

懂视网 时间:2022-04-30 02:24

*********************************************************************************************************************************

@echo off
setlocal ENABLEDELAYEDEXPANSION

::读取配置文件
md %windir%OracleAutoBackup >nul 2>nul
set configFile=%windir%OracleAutoBackupconfig.ini
set i=0
if not exist %configFile% echo.>%configFile%
for /f "delims=" %%x in (%configFile%) do (
if !i!==0 set bak_hou=%%x
if !i!==1 set bak_lot=%%x
if !i!==2 set bak_dir=%%x
if !i! gtr 2 (
set/a gup=!i!-2
set ora[!gup!]=%%x
)
set/a i+=1
)

::取默认值
if "!bak_hou!"=="" set bak_hou=3
echo !bak_hou!|findstr "^[0-9]*$">nul || set bak_hou=3
if "!bak_lot!"=="" set bak_lot=7
echo !bak_lot!|findstr "^[0-9]*$">nul || set bak_lot=7
if "!bak_dir!"=="" set bak_dir=%cd%数据库备份
for /f "tokens=*" %%x in ("!bak_dir!") do set bak_dir=%%~fx
if not exist !bak_dir! md !val! >nul 2>nul
::去掉格式错误的数据库连接配置项
set j=0
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
set ora[%%i]=
echo !ora_cur!|findstr "/">nul 2>nul && echo !ora_cur!|findstr "@">nul 2>nul && (
set/a j+=1
set ora[!j!]=!ora_cur!
)
)
)

::进入管理程序
if "%1"=="" goto init


::检查exp命令是否可用
:checkexp
set resultFile=%temp%\%random%.txt
del %resultFile% /q>nul 2>nul
exp a/a@a%random% file=%temp%\%random%.dmp >nul 2>%resultFile%
if exist %resultFile% (
type %resultFile%|find "‘exp‘ 不是内部或外部命令">nul
if !errorlevel!==0 (
del %resultFile%>nul
echo exp命令不可用!程序即将退出!
ping -n 10 127.1 >nul 2>nul
exit
)
del %resultFile%>nul
)

::1.数据库备份
title 备份进程
echo.
echo.
echo 一、正在进行备份……
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
set ora_usr=
set ora_net=
for /f "delims=/" %%a in (‘echo !ora_cur!‘) do set ora_usr=%%a
for /f "delims=@ tokens=2" %%a in (‘echo !ora_cur!‘) do set ora_net=%%a
echo.
echo.
echo %%i.正在备份 !ora_usr!/******@!ora_net!……
md !bak_dir!!ora_net!__!ora_usr! >nul 2>nul
set ftmr=!time: =0!
set bak_cur_dir=!bak_dir!!ora_net!__!ora_usr!
for /f "tokens=*" %%x in ("!bak_cur_dir!") do set bak_cur_dir=%%~fx
set bak_cur_fnm=!ora_net!__!ora_usr!__!date:~0,4!!date:~5,2!!date:~8,2!-!ftmr:~0,2!!ftmr:~3,2!
set bakfile=!bak_cur_dir!!bak_cur_fnm!.dmp
set logfile=!bak_cur_dir!!bak_cur_fnm!.log
exp !ora_cur! file="!bakfile!" log="!logfile!"
echo 如果备份成功的话,就进行压缩>nul
if exist "!bakfile!" (
pushd !bak_cur_dir!
set zipfile=
if exist "%ProgramFiles%winrarwinrar.exe" (
echo 使用WinRAR进行压缩>nul
set zipfile=!bak_cur_fnm!.rar
"%programfiles%winrarwinrar" a -r "!zipfile!" "!bak_cur_fnm!.dmp" "!bak_cur_fnm!.log"
) else (
echo 使用ZIP指令进行压缩>nul
set zipfile=!bak_cur_fnm!.zip
zip "!zipfile!" "!bak_cur_fnm!.dmp" "!bak_cur_fnm!.log">nul
)
if exist "!zipfile!" (
del /q "!bakfile!"
del /q "!logfile!"
)
popd
) else (
echo 如果不存在备份文件,但有日志文件,则删除日志文件>nul
if exist "!logfile!" del /q "!logfile!"
)
)
)
::2.数据库过期备份删除
echo.
echo.
echo 二、正在清除过期的备份文件……
for /f "tokens=1,2,3 delims=-" %%a in (‘echo wscript.echo date-!bak_lot! ^>t~.vbs ^& cscript //nologo t~.vbs ^& del t~.vbs‘) do (
set y=%%a&set m=%%b&set d=%%c
if %%b lss 10 set m=0%%b
if %%c lss 10 set d=0%%c
)
set DateE=!y!-!m!-!d!
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
set ora_usr=
set ora_net=
for /f "delims=/" %%a in (‘echo !ora_cur!‘) do set ora_usr=%%a
for /f "delims=@ tokens=2" %%a in (‘echo !ora_cur!‘) do set ora_net=%%a
set cur_dir=!bak_dir!!ora_net!__!ora_usr!
for /f "tokens=*" %%x in ("!cur_dir!") do set cur_dir=%%~fx

echo 检查今天的备份成功了没有 >nul
set fnm_pre=!cur_dir!!ora_net!__!ora_usr!__!date:~0,4!!date:~5,2!!date:~8,2!-& set today_success=0
dir !fnm_pre!*.dmp !fnm_pre!*.zip !fnm_pre!*.rar /b >nul 2>nul && set today_success=1
if "!today_success!"=="1" (
echo 判断文件夹条件是否满足 >nul
for %%a in (!cur_dir!*.dmp,!cur_dir!*.log,!cur_dir!*.zip,!cur_dir!*.rar) do (
echo 判断文件名称条件是否满足 >nul
set n=%%a&set n=!n:~-17,-9!&set n=!n:~0,4!-!n:~4,2!-!n:~6,2!
set t=%%~ta
set FileDate=!t:~0,10!
if "!n!"=="!FileDate!" (
echo 判断时间条件是否满足 >nul
if !FileDate! leq %DateE% (
echo %date:~0,10% %time:~0,8% 删除过期备份 %%a
echo %date:~0,10% %time:~0,8% 删除过期备份 %%a>>!cur_dir!delete.log
del /q "%%a"
)
)
)
) else (
echo %date:~0,10% %time:~0,8% [!ora_net!__!ora_usr!]因为今天的备份没有成功,暂时不删除过期文件!
echo %date:~0,10% %time:~0,8% [!ora_net!__!ora_usr!]因为今天的备份没有成功,暂时不删除过期文件!>>!cur_dir!delete.log
)
)
)
::3.完成退出
echo.
echo.
echo 三、本次备份操作完成,即将退出。
ping -n 10 127.1 >nul 2>nul
exit

 

::=================================以下是备份程序=================================
::=================================以下是管理程序=================================
:init
mode con cols=100 lines=40
title Oracle自动备份 - by zhouyou96
color 0e

::复制到 Windows 目录
copy "%~f0" "%windir%OracleAutoBackupOracleAutoBackup.bat" >nul 2>nul

::注册计划任务
:regtasks
sc config schedule start= auto >nul 2>nul
at|find "服务尚未启动">nul 2>nul&&(
net start schedule
if not !errorlevel!==0 (
echo Task Scheduler^(计划任务^)服务未能启动,程序即将退出!
pause>nul
goto exit
)
)
set job_tmr=!bak_hou!:00
if !bak_hou! lss 10 set job_tmr=0!bak_hou!:00
at !job_tmr! /every:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 %windir%OracleAutoBackupOracleAutoBackup.bat -backup >nul 2>nul
for /f "usebackq" %%i in (`dir %windir% asksat*.job /b/o:d`) do set lastAt=%%i
del %windir% asksOracle自动备份.job >nul 2>nul
rename %windir% asks!lastAt! Oracle自动备份.job

::保存配置文件
:saveconfig
echo !bak_hou!>%configFile%
echo !bak_lot!>>%configFile%
echo !bak_dir!>>%configFile%
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
echo !ora_cur!>>%configFile%
)
)
::准备数据库配置字符串
set ora_str=
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
set ora_usr=
set ora_net=
for /f "delims=/" %%a in (‘echo !ora_cur!‘) do set ora_usr=%%a
for /f "delims=@ tokens=2" %%a in (‘echo !ora_cur!‘) do set ora_net=%%a
set ora_str=!ora_str!%%i. !ora_usr!/******@!ora_net!;
)
)

::开始
:start
cls
echo --------------------------------------------------------------------------------------------------
echo Oracle自动备份
echo 作者:zhouyou96 QQ:191458000
echo --------------------------------------------------------------------------------------------------
echo   使用操作系统自带的计划任务功能,每天定时运行exp命令导出指定的Oracle数据库并压缩,然后按需删除
echo 已过期的压缩的导出文件,以实现自动备份的功能。
echo   通常,为了便于管理,在我们公司一个oracle用户有且仅有的全权管理一个数据库,因此该用户的登陆名称
echo 其实可以视做为数据库名称。
echo.
echo 1.添加数据库:!ora_str!
echo 2.删除数据库
echo 3.设置文件夹:!bak_dir!
echo 4.几点钟备份:!bak_hou!
echo 5.删除几天前:!bak_lot!
echo 6.立即备份
echo 7.退出
echo.


::选择
:cho
set choice=
set /p choice=请选择:
if not "%choice%"=="" set choice=%choice:~0,1%
if "%choice%"=="1" goto addora
if "%choice%"=="2" goto delora
if "%choice%"=="3" goto setdir
if "%choice%"=="4" goto sethou
if "%choice%"=="5" goto setlot
if "%choice%"=="6" goto nowbak
if "%choice%"=="7" goto exit
echo.
echo =================================================================================================
echo =================================== 请选择1~7,按任意键重选!====================================
echo =================================================================================================
pause>nul
goto start


::添加数据库
:addora
set maxora=0
for %%i in (1,2,3,4,5,6,7,8,9) do (set ora[%%i]>nul 2>nul&&(set maxora=%%i))
set str_result=最多9个!
if not !maxora!==9 (
set/a maxora+=1
set new_ora=
set/p new_ora=请输入(用户名/密码@网络服务名):
set str_result=格式错误!
if not "!new_ora!"=="" (
echo !new_ora!|findstr "/">nul 2>nul && echo !new_ora!|findstr "@">nul 2>nul && (
set ora[!maxora!]=!new_ora!
set str_result=添加成功,
)
)
)
echo =================================================================================================
echo ==================================== !str_result!按任意键继续!====================================
echo =================================================================================================
pause>nul
if "!str_result!"=="添加成功," goto saveconfig
goto start


::删除数据库
:delora
set str_result=操作错误!
set del_idx=0
set/p del_idx=请输入要删除的序数(1~9):
if not "%del_idx%"=="" set del_idx=%del_idx:~0,1%
if "!del_idx!"=="" set del_idx=0
echo !del_idx!|findstr "^[0-9]*$">nul || set del_idx=0
if not "!del_idx!"=="0" (
set ora[!del_idx!]=
set str_result=删除成功,
)
::去掉格式错误的数据库连接配置项
if "!str_result!"=="删除成功," (
set j=0
for %%i in (1,2,3,4,5,6,7,8,9) do (
set ora[%%i]>nul 2>nul&& (
set ora_cur=
for /f "usebackq delims==. tokens=1-3" %%a in (`set ora[%%i]`) do set ora_cur=%%b
set ora[%%i]=
echo !ora_cur!|findstr "/">nul 2>nul && echo !ora_cur!|findstr "@">nul 2>nul && (
set/a j+=1
set ora[!j!]=!ora_cur!
)
)
)
)
echo =================================================================================================
echo ==================================== !str_result!按任意键继续!====================================
echo =================================================================================================
pause>nul
if "!str_result!"=="删除成功," goto saveconfig
goto start

::设置文件夹
:setdir
set new_dir=
set/p new_dir=请输入备份用的文件夹:
if "!new_dir!"=="" set new_dir=%cd%数据库备份
for /f "tokens=*" %%x in ("!new_dir!") do set new_dir=%%~fx
set bak_dir=!new_dir!
echo =================================================================================================
echo ==================================== 设置成功,按任意键继续!====================================
echo =================================================================================================
pause>nul
goto saveconfig

::几点钟备份
:sethou
set str_result=操作错误!
set new_hou=
set/p new_hou=请输入每天几点钟备份(0~23):
echo !new_hou!|findstr "^[0-9]*$">nul || set new_hou=
if not "!new_hou!"=="" (
if !new_hou! geq 0 (
if !new_hou! leq 23 (
set bak_hou=!new_hou!
set str_result=设置成功,
)
)
)
echo =================================================================================================
echo ==================================== !str_result!按任意键继续!====================================
echo =================================================================================================
pause>nul
if "!str_result!"=="设置成功," goto regtasks
goto start


::删除几天前
:setlot
set str_result=操作错误!
set new_lot=
set/p new_lot=请输入删除几天之前的备份(大于零):
echo !new_lot!|findstr "^[0-9]*$">nul || set new_lot=
if not "!new_lot!"=="" (
if !new_lot! gtr 0 (
set bak_lot=!new_lot!
set str_result=设置成功,
)
)
echo =================================================================================================
echo ==================================== !str_result!按任意键继续!====================================
echo =================================================================================================
pause>nul
if "!str_result!"=="设置成功," goto saveconfig
goto start

::现在备份
:nowbak
start %windir%OracleAutoBackupOracleAutoBackup.bat -backup
echo =================================================================================================
echo ==================================== 成功启动,按任意键继续!====================================
echo =================================================================================================
pause>nul
goto start


::退出程序
:exit
::pause>nul

 

***************************************************************************************************************************************

2.配置网络连接,必须确保能正常远超访问到指定备份数据库的操作系统,或者ping通。

3.安装oracle数据库,并配置好能指定到备份数据的库的连接,可以使用PLSQL Developer做oracle的连接;

  1. 配置方法:1.到oracle的安装文件中找到tnsnames.ora,(安装目录:product10.2.0db_1 etworkADMIN nsnames.ora,)使用编辑器添加连接信息

    例如:

    LINUX =

    (DESCRIPTION =
      (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 备份数据库IP地址)(PORT = 1521))
        )
        (CONNECT_DATA =
          (SERVICE_NAME = 备份数据库实例)
                    )
              )

    2.使用PLSQL Developer测试是否连接通过

4.设置定时计划,直接复制下来的代码执行XXX.bat,在任务计划中找到该计划,在后面添加一个参数 –backup 设置好备份时间即可

技术分享

 

oracle定时备份

标签:

热心网友 时间:2022-04-29 23:32

oracle实现自动定时备份其实比较好的方法是:
oracle中的job
+
存储过程
job定时执行,而存储过程则完成增量备份!!
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
宁波社保卡办理需要什么材料 宁波社保卡如何申领 有什么高性价比的隔离霜可以推荐? 防晒效果好的隔离霜有哪些值得入手? 下雨天经常爬在房子墙上的那种软体动物,不是蜗牛没壳的,可以在墙上把身... 原来是美男啊里面插曲、主题曲都有哪些? 请问下各位大虾,我在外地用外地农行卡网上转账到本地邮政卡星期六转账的... 为什么用支付宝买东西明明我余额足够,付款时却说我余额不足?2个... 萍乡烛式过滤器品牌 衡水烛式过滤器品牌推荐 oracle自动定期执行存储过程 oracle中的存储过程,执行后oracle自己会记录执行日志到数据库中么,比如... oracle 定时备份 好看的校园言情小说,男女主角名字要好听的 一位9岁女孩在猪肉店跳芭蕾舞让人惊讶不已,她究竟有何神奇之处?_百度... 描写秋日银杏树银杏树叶的成语或词语 描写小动物的作文要有好词好句,标出来!急急急急急急!1个小时内的加分... 像企鹅革命或顶峰的漫画 我家的杏熟了这篇短文你认为哪些句子好为什么至少写三个? 没有朋友的冬天作文 三段 小动物 段落 急求 如何用银杏写一句话来表达浓浓的秋意? 把 冬天来了,寻觅不到雪花的踪迹 扩写成不少于600字的作文,怎么写... 请帮忙找一篇以 呼唤 为题的作文 求作文 题目:那一声呼唤 600字左右 甜蜜的呼唤作文600字以上 以呼唤为题 600字 以呼唤为话题的作文,600字 饿了么红包邀请码 五元是多少? 呼唤话题作文600字 ORACLE服务器定时备份怎么做 oracle数据库如何每天自动执行脚本完成正式数据库到备份数据库的... 如何查看oracle中存储过程执行的历史记录 利用oracle提供的dbms_job.submit定时任务功能,可以对数据库进行备份吗... oracle定时器 调用存储过程 每次采集前15分钟的记录 怎样保证时间不遗漏... oracle 添加一个计划任务 每天凌晨两点 定时执行一个存储过程 求详细步 ... 怎样实现每天自动执行oracle的存储过程一次 ORACLE里怎样每天自动执行一个存储过程 oracle中的存储过程怎么跟踪打出日志 怎样实现每天自动执行oracle的存储过程一次? oracle定时执行怎么执行多个存储过程 《龙之谷》手游为什么下架了? 龙之谷手游推荐玩什么职业? 手游龙之谷2抢先服和其它服有什么区别? 手游龙之谷哪个职业平民玩 龙之谷手游哪个职业输出最高 龙之谷,手游什么职业好 手游龙之谷什么职业最强 蓝牌货车限高多少? 三文鱼放冷藏还是冷冻