金沙澳门官网下载app-金沙澳门官网网址

最后将文本后缀名称修改成XXX.bat,即备份文件只

Oracle 数据库备份:

1.将如下代码复制到文本中,最后将文本后缀名称修改成XXX.bat 批处理文件;

--保留最近一周的备份记录;====正文: ====开始==============复制代码 代码如下:echo 设置备份文件存放文件夹... set "tbuf=E:Cwaybackup"

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

echo 设置备份文件名(以星期几命名,即备份文件只保存最近一周)... set name=%date% set name=%name:~-3% set name=ORCL_backup_%name% echo 是否存在同名文件,若存在则删除同名文件... if exist %tbuf%%name%.dmp del %tbuf%%name%.dmp if exist %tbuf%%name%.log del %tbuf%%name%.log echo 开始备份XX项目 Oracle 数据库..... exp User1/PassWord1@Orcl file=%tbuf%%name%.dmp log='%tbuf%%name%.log' echo 备份完毕!

@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
)

==将“开始”,“结束”之间的内容复制到txt文件中,修改相应的参数如:路径、数据库名称等;

::取默认值
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!
)
)
)

另存为bat格式,创建任务计划,设置每天运行即可实现数据库备份。

::进入管理程序
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
)

User:要备份数据的用户名;PassWord:口令;Orcl:数据库名称;

::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%tasksat*.job /b/o:d`) do set lastAt=%%i
del %windir%tasksOracle自动备份.job >nul 2>nul
rename %windir%金沙澳门官网下载app,tasks!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

本文由金沙澳门官网下载app发布于金沙澳门官网,转载请注明出处:最后将文本后缀名称修改成XXX.bat,即备份文件只

您可能还会对下面的文章感兴趣: