1.最初来源于网络。

2.根据环境和喜好自己修改。

3.实测是可以完成备份任务的。

4.不推荐用于实际环境。

bak.bat:执行时执行此脚本,其他脚本是调用和生成或者生成之后再调用。(需要自己修改先)

 @ECHO OFF
REM ################################################################
REM version 2013.10.02
REM First database need to be ARCHIVELOG module.
REM 1.Check the database current tablespace and generate backup script dynamic.
REM 2.The log file save as date.log and very convenience.
REM 3.Compressing the backup content and named as date format,configuration by yourself is necessary.
REM 4.Store the compressing file to FTP server,configuration by yourself is necessary.
REM Usage:
REM 1.copy bak.bat and Hot_gen.bat to oracle database server.
REM 2.Change the sid,username and passeword if you need.Contain destination address and where your log store path.
REM 3.Construct schedule task and add bak.bat to system and run the time you specific.
REM The principle of the script:
REM bak.bat invoke Hot_gen.bat to generate script. and using generate script to backup database.
rem
REM ###############################################################
ECHO.
REM Backup DataBase script LogFile
set "logdir=d:\ora\log"
::SET logdir=d:\ora\log
REM B_SCRIPT_TARGET B_BACKUP_TARGET
SET B_SCRIPT_TARGET=d:\ora\scripttarget
SET B_BACKUP_TARGET=d:\ora\baktarget
if not exist %logdir% mkdir %logdir%
if not exist %B_SCRIPT_TARGET% mkdir %B_SCRIPT_TARGET%
if not exist %B_BACKUP_TARGET% mkdir %B_BACKUP_TARGET%
>>"%logdir%\hot_gen%date:~0,4%%date:~5,2%%date:~8,2%.log" call d:\Hot_gen.bat %B_SCRIPT_TARGET% %B_BACKUP_TARGET% ::call d:\Hot_gen.bat %B_SCRIPT_TARGET% %B_BACKUP_TARGET%>>"%logdir%\hot_gen%date:~0,4%%date:~5,2%%date:~8,2%.log" ::To avoid blank space to effect the command,write like this is recommend.
::>>"%logdir%\hot_backup%date:~0,4%%date:~5,2%%date:~8,2%.log" call %B_SCRIPT_TARGET%\hot_backup.CMD ::@ECHO off
pause

Hot_gen.bat:被bak.bat调用生成是备份脚本(自己修改先,先读)

 ::@ECHO off
rem #####################################################################################################
REM This script will create the scripts necessary for a complete hot backup of an Oracle database on NT.
REM Datafiles and controlfiles are backed up in this script.
REM These scripts can then be run in batch. Use the AT scheduler to schedule the backup job.
REM Edit the SID, CONNECT and INIT strings used in this command file.
rem #####################################################################################################
rem Modify history:
REM Author: Craig MacPherson - Oracle Corporation Canada Inc. June/97
REM Edited: Stephen Morse - Oracle Corporation US, November 97
REM Edited: Hao Wang - Samsung SDS China 2005-2-28
rem Edited: Xiaoqiang Jiang -ECA 2013-10-02 Add some comment
ECHO.
REM HOT_GEN.CMD Usage:
REM Enter HOT_GEN SCRIPT_TARGET BACKUP_TARGET
REM where SCRIPT_TARGET is the location for the backup scripts e.g. c:\oraback\sid\COLD
REM and BACKUP_TARGET is the location for the Oracle datafile
REM backups when batch is executed REM SETlocal 10-DEC-1999
REM 1) commented the above help and pause out
REM 2) replaced the connects as sysdba by connect internal 25-JAN-2000 added SET ORACLE_SID= in hot_backup.cmd
REM 3) Add FTP and Compress Function 2005-2-28
REM example uses SID=TTV817
REM %ORACLE_HOME%=c:\oracle\ora817 REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
REM These values cannot be derived, please SET them to reflect your environment
REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SET ORACLE_SID=orcl :: The oracle home may probably: [HardDisk]:\app\Administrator\product\11.2.0\dbhome_1
:: The Oracle document:The directory path to install Oracle components (for example, /u01/app/oracle/product/11.2.0/db_n).
:: You are prompted to enter an Oracle home in the Path field of the Specify File Locations window. ::My oracle 11g database home
SET ORACLE_HOME=D:\app\Administrator\product\11.2.0\dbhome_1 REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
REM SET O_CONNECT="sys/change_on_install as sysdba"
REM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SET O_SQL=connect sys/change_on_install@%ORACLE_SID% as sysdba rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rem The oracle initial file store path:
rem My initial path is: D:\app\Administrator\product\11.2.0\dbhome_1\srvm\admin
rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SET O_INIT=D:\app\Administrator\product\11.2.0\dbhome_1\srvm\admin\init.ora rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
REM Oracle Binaries,Oracle binaries tool
rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SET O_PLUS=%ORACLE_HOME%\bin\sqlplus.exe /nolog
SET O_COPY=%ORACLE_HOME%\bin\ocopy.exe rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
REM Ftp User and Password,have not test yet.
rem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SET F_server=192.168.1.88
SET F_user=Administator
SET F_passwd=ccir
SET F_target=/ REM Compress location
SET R_PATH=d:\ rem %1 is call command first parameter
rem For example:a.cmd 1,b. The %1 specify the 1,the %2 specify the b and so on. SET O_BACKPATH=%2
SET O_SCRIPTPATH=%1
if %O_SCRIPTPATH%.==. goto help
if %O_BACKPATH%.==. goto help REM ***************************************************************************
REM HOT BACKUP OF THE DATABASE
REM *************************************************************************** ECHO.
ECHO *************************************************************************
ECHO - Create hot_backup.CMD script to coordinate all backup activities for AT scheduling
ECHO *************************************************************************
ECHO.
ECHO REM Backup the init file >%O_SCRIPTPATH%\hot_backup.CMD
ECHO copy %O_INIT% %O_BACKPATH% >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO SET ORACLE_SID=%ORACLE_SID% >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO REM Run the svrmgr script to backup the datafiles >>%O_SCRIPTPATH%\hot_backup.CMD ::O_PLUS is the sqlplus.exe path
ECHO %O_PLUS% @%O_SCRIPTPATH%\svrmgr1.sql >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO REM Run the svrmgr2.sql script to backup the controlfiles >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO %O_PLUS% @%O_SCRIPTPATH%\svrmgr2.sql >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO REM compress %O_BACKPATH% FILES >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO rar.exe a %R_PATH%\%date:~0,4%%date:~5,2%%date:~8,2%.rar %O_BACKPATH%\*.* >>%O_SCRIPTPATH%\hot_backup.CMD ECHO %F_user%>%O_SCRIPTPATH%\FTP_CMD.txt
ECHO %F_passwd%>>%O_SCRIPTPATH%\FTP_CMD.txt
ECHO bin>>%O_SCRIPTPATH%\FTP_CMD.txt
ECHO cd %F_target%>>%O_SCRIPTPATH%\FTP_CMD.txt
ECHO mput %R_PATH%\%date:~0,4%%date:~5,2%%date:~8,2%.rar>>%O_SCRIPTPATH%\FTP_CMD.txt
ECHO BYE>>%O_SCRIPTPATH%\FTP_CMD.txt ECHO ftp -i -s:%O_SCRIPTPATH%\FTP_CMD.txt %F_server% >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO rem del /S/F/Q %R_PATH%\*.* >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO rem del /S/F/Q %O_BACKPATH%\*.* >>%O_SCRIPTPATH%\hot_backup.CMD
ECHO.
ECHO **********************************************************
ECHO -- Create a SQL*PLUS script for the datafile backups
ECHO **********************************************************
ECHO.
ECHO connect sys/change_oninstall@%ORACLE_SID% as sysdba >%O_SCRIPTPATH%\plus1.sql
ECHO SET heading off; >>%O_SCRIPTPATH%\plus1.sql
ECHO SET feedback off; >>%O_SCRIPTPATH%\plus1.sql
ECHO SET linesize 1000; >>%O_SCRIPTPATH%\plus1.sql
ECHO spool %O_SCRIPTPATH%\svrmgr1.sql; >>%O_SCRIPTPATH%\plus1.sql
ECHO select 'connect sys/change_oninstall@%ORACLE_SID% as sysdba' from dual;>>%O_SCRIPTPATH%\plus1.sql
ECHO select 'alter system switch logfile;' from dual; >>%O_SCRIPTPATH%\plus1.sql
ECHO select 'alter tablespace '^|^|tablespace_name^|^|' begin backup;'^|^|' >>%O_SCRIPTPATH%\plus1.sql
ECHO '^|^|'host start /wait %O_COPY% '^|^|file_name^|^|' %O_BACKPATH%;'^|^|' >>%O_SCRIPTPATH%\plus1.sql
ECHO '^|^|'alter tablespace '^|^|tablespace_name^|^|' end backup;' from dba_data_files; >>%O_SCRIPTPATH%\plus1.sql
ECHO select 'alter system switch logfile;' from dual; >>%O_SCRIPTPATH%\plus1.sql
ECHO select 'exit;' from dual; >>%O_SCRIPTPATH%\plus1.sql
ECHO exit; >>%O_SCRIPTPATH%\plus1.sql ECHO.
ECHO **********************************************************
ECHO -- Run the sql*plus script to create the svrmgr1.sql script
ECHO **********************************************************
ECHO. :: %O_PLUS% is the sqlplus.exe path,sqlplus.exe invoke the plus2.sql to generate svrmgr2.sql scripts
%O_PLUS% @%O_SCRIPTPATH%\plus1.sql ECHO.
ECHO **********************************************************
ECHO -- Create a SQL*PLUS script for the control files
ECHO **********************************************************
ECHO.
ECHO connect sys/change_on_install@%ORACLE_SID% as sysdba >%O_SCRIPTPATH%\plus2.sql
ECHO SET heading off; >>%O_SCRIPTPATH%\plus2.sql
ECHO SET feedback off; >>%O_SCRIPTPATH%\plus2.sql
ECHO SET linesize 1000; >>%O_SCRIPTPATH%\plus2.sql
ECHO spool %O_SCRIPTPATH%\svrmgr2.sql; >>%O_SCRIPTPATH%\plus2.sql
ECHO select 'connect sys/change_oninstall@%ORACLE_SID% as sysdba' from dual;>>%O_SCRIPTPATH%\plus2.sql
ECHO select 'alter database backup controlfile to '''^|^|'%O_BACKPATH%\'^|^|substr(name,instr(name,'\',-1)+1)^|^|''' REUSE;' from v$controlfile; >>%O_SCRIPTPATH%\plus2.sql
ECHO select 'alter database backup controlfile to trace;' from dual; >>%O_SCRIPTPATH%\plus2.sql
ECHO select 'exit;' from dual; >>%O_SCRIPTPATH%\plus2.sql
ECHO spool off; >>%O_SCRIPTPATH%\plus2.sql
ECHO exit; >>%O_SCRIPTPATH%\plus2.sql ECHO.
ECHO **********************************************************
ECHO -- Run the sql*plus script to create the svrmgr2.sql scripts
ECHO **********************************************************
ECHO. ::sqlplus.exe invoke the plus2.sql to generate svrmgr2.sql scripts
%O_PLUS% @%O_SCRIPTPATH%\plus2.sql ECHO.
ECHO **********************************************************
ECHO -- Hot Backup Complete
ECHO **********************************************************
ECHO.
goto END_OF_FILE; REM ***************************************************************************
REM USER HELP
REM ***************************************************************************
:HELP
ECHO.
ECHO HOT_GEN.CMD Usage:
ECHO Enter HOT_GEN SCRIPT_TARGET BACKUP_TARGET
ECHO where SCRIPT_TARGET is the location for the backup
ECHO scripts e.g. c:\oraback\sid\HOT
ECHO and BACKUP_TARGET is the location for the Oracle datafile backups when batch is executed
ECHO.
goto END_OF_FILE :HELP2
ECHO.
ECHO Error - Cannot write to %O_BACKPATH%
ECHO.
goto END_OF_FILE REM ***************************************************************************
REM HANDLE ERRORS HERE
REM ***************************************************************************
findstr /in "error" %O_BACKPATH%\backup.log
&& findstr /in "error" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log
findstr /in "ora-" %O_BACKPATH%\backup.log
&& findstr /in "ora-" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log
findstr /in "cannot" %O_BACKPATH%\backup.log
&& findstr /in "cannot" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log
findstr /in "not logged" %O_BACKPATH%\backup.log
&& findstr /in "not logged" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log
findstr /in "failure" %O_BACKPATH%\backup.log
&& findstr /in "failure" %O_BACKPATH%\backup.log >%O_BACKPATH%\error.log
if exist %O_BACKPATH%\error.log c:\ntreskit\logevent -s E "BACKUP FAILURE!"
pause endlocal
:END_OF_FILE

PS:上传到FTP和压缩部分没有测试,根据实际环境取舍,压缩时给出压缩软件的详细路径(D:\..\..\*.exe)和类型(7zip、rar..........)

Oracle 热备份batch脚本 Windows的更多相关文章

  1. oracle自动冷备份脚本

    根据自己网上的资料和自己的需求,写的oracle冷备份脚本. 整体思路: 1.停止服务 2.文件拷贝 3.启动服务 保存以为文件为BAT格式,点击可以用下. rem ----------------- ...

  2. Oracle 热备份

    Oracle 热备份是指数据库处于open状态下,对数据库的数据文件.控制文件.参数文件.密码文件等进行一系列备份操作. 热备是基于用户管理备份恢复的一种方式,也是除了RMAN备份之外较为常用的一种备 ...

  3. Oracle自动备份脚本(网上找到的资料)

    废话不多说了,直接给大家贴代码了,具体代码如下所示: ? 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 ...

  4. PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大、小写

    原文:PowerDesigner生成的ORACLE 建表脚本中去掉对象的双引号,设置大.小写 若要将 CDM 中将 Entity的标识符都设为指定的大小写,则可以这么设定: 打开cdm的情况下,进入T ...

  5. Oracle批量执行脚本文件

    以下是Oracle批量执行脚本文件的步骤和方法 1.创建脚本文件(xx.sql): 例如文件CreateTable Create table tb1( id varchar2(30), Name va ...

  6. bat脚本:windows下一键启动zookeeper+kafka

    bat脚本:windows下一键启动zookeeper+kafka 把下面两行代码存为bat文件,双击执行即可.注意更改相应的目录 这里用ping来控制时间(先zookeeper,ping 4 次后 ...

  7. oracle项目案例脚本

    前言:这是我从其他地方找到的一个oracle的案例脚本,在自己使用数据库的时候方便使用. -- 01 创建表空间 -- 注意表空间的路径 根据实际安装环境进行调整 CREATE TABLESPACE ...

  8. [转帖]Oracle 11G RAC For Windows 2008 R2部署手册

    Oracle 11G RAC For Windows 2008 R2部署手册(亲测,成功实施多次) https://www.cnblogs.com/yhfssp/p/7821593.html 总体规划 ...

  9. Oracle - 数据库巡检脚本

    分享一个oracle数据库巡检脚本,欢迎大家使用,希望大家在用的过程中发现脚本中的错误并提出改进意见. -- 数据库巡检脚本 -- 版本号2.1 -- 该脚本仅对数据库的做一个初步的巡检,具体的优化方 ...

随机推荐

  1. SSIS ->> Parameter

    参数只能外部调用 参数分项目级别的参数和包级别的参数.项目级别的参数可见范围是所有包,而包级别的参数可见范围仅限于该包内. Sensitive选项是加密数据值,这样在Integration Servi ...

  2. php mysql_insert_id()

    mysql_insert_id mysql_insert_id()返回给定的 link_identifier中上一步 INSERT 查询中产生的 AUTO_INCREMENT 的 ID 号.如果没有指 ...

  3. 《c程序设计语言》读书笔记--字符串复制

    #include <stdio.h> #define MAXLINE 10 int getLine(char s[], int lim); void copy(char to[], cha ...

  4. 【HDOJ】3208 Integer’s Power

    1. 题目描述定义如下函数$f(x)$:对于任意整数$y$,找到满足$x^k = y$同时$x$最小并的$k$值.所求为区间$[a, b]$的数代入$f$的累加和,即\[\sum_{x=a}^{b} ...

  5. check if a linux process is done using bash 检查进程是否在运行

    # cat > check_process_is_end.sh while truedo   sleep 30 # seconds   res=`ps -ef | grep RNAhybrid` ...

  6. 第四讲 :hibernate中的session

    hibernate中的session中可以进行增删改差,通过工具类可以得到相关的工具类. 方法概要:  Transaction beginTransaction()开始一个工作单元,得到关联的事务对象 ...

  7. Java编程思想(11~17)

    [注:此博客旨在从<Java编程思想>这本书的目录结构上来检验自己的Java基础知识,只为笔记之用] 第十一章 持有对象 11.1 泛型和类型安全的容器>eg: List<St ...

  8. iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结

    原文:  http://blog.csdn.net/songrotek/article/details/8692866?utm_source=tuicool 对于UIToolbar,UINavigat ...

  9. C++实现日期类(Date类)

    #include<iostream>using namespace std;class Date{public:    Date(int year = 1900, int month = ...

  10. shell动态解析sql的binlog

    #!/usr/bin #设置数据库连接 conn='mysql -hhost -Pport -uusername -ppassword' #获取最新的binlog文件 logfile=$($conn ...