在数据库领域,oralce数据库系统的性能,可靠性等都是大家一致公认-非常的优秀,但是他的可操作行一直是一个弱项,
很多时候让用户退却。现在的oracle公司好像已经认识到了,oracle据库系统的发展朝着更简单的使用方法,更智能的内部管理。
关于oracle数据库的备份,oracle有许多中方法,也有许多的方式,为使大家能轻松方便的完成oracle数据库的备份
我把自己工作中写的一些自动完成数据库备份的方法,教本整理一下。发给大家,希望能给朋友们一些帮助。
需要时间,希望你有耐心等,我会一集一集送给朋友们。
oracle数据库冷备份:(windows平台)
1. 建立教本管理目录 C:\oracle\admin\admin script 2. 建立数据库备份的脚本 在上面建立的目录下建立如下的两个教本。
2.1 建立执行备份任务的脚本(批处理文件)
文件内容如下:
@echo OFF
Rem ===========================================================================
Rem NAME - close_Backup_run.bat
Rem FUNCTION - Creates a backup script for a User Managed backup
Rem NOTES - This script will create a script and run OS copy commands
Rem on closed (cold) database
Rem MODIFIED - Mr. Tianliang Guo 02/08/08 Original File
Rem ===========================================================================
Rem For Windows, set environment variables for the root path.
set ORACLE_SID=TSTDB
set ORACLE_CONNECTSTRING=tstdb
set ORACLE_BASE=c:\oracle
set ORACLE_HOME=%ORACLE_BASE%\ora81
set ORACLE_DATA=%ORACLE_BASE%\oradata\%ORACLE_SID%
set ORACLE_ADMIN=%ORACLE_BASE%\admin\%ORACLE_SID%
%ORACLE_HOME%\bin\sqlplus /nolog @close_backup.sql > close_backup.log
2.2 建立完成备份认为的命令文件(sqlplus内执行的sql脚本)
文件内容如下:
Rem ===========================================================================
Rem NAME - close_backup.sql
Rem FUNCTION - Creates a backup script for a User Managed backup
Rem NOTES - This script will create a script and run OS copy commands
Rem on closed (cold) database
Rem MODIFIED - ksmith 01/01/02 Original File
Rem - Tianliang Guo 2002/08/18
Rem ===========================================================================
Rem Set SQL*Plus variables to manipulate output
set heading off
set verify off
set pagesize 0
set linesize 600
set feedback off
Rem Set SQL*Plus user variables used in script
define adm = 'sys'
define pwd = 'oracle8i'
Rem Windows User variables
define bkdir = 'C:\oracle\admin\TSTDB\backup'
define filcbc = 'closed_backup_commands.sql'
define copy = 'ocopy'
Rem login database
connect &adm/&pwd as sysdba;
Rem Create a file containing all the file copy commands needed for physical backup
spool &filcbc
prompt Rem NAME - close_backup.sql
prompt
prompt Rem Shutdown the database cleanly
prompt shutdown immediate;;
prompt
prompt Rem backup data file
select 'host ? '|| name ||' &bkdir' from v$datafile order by 1;
prompt
prompt Rem backup log file
select 'host ? '|| member ||' &bkdir' from v$logfile order by 1;
prompt
prompt Rem backup control file
select 'host ? '|| name ||' &bkdir' from v$controlfile order by 1;
prompt
prompt Rem backup temporay file
select 'host ? '|| name ||' &bkdir' from v$tempfile order by 1;
prompt
prompt alter database backup controlfile to trace;;
prompt
prompt Rem Start the database again
prompt startup;;
prompt
spool off;
Rem Run the copy file commands
@&
exit;
3. 修改教本定义的变量 在运行教本中定义的一些变量,将其改为本地数据库安装环境的变量。
需要修改的变量有,
在close_Backup_run.bat脚本中:
set ORACLE_SID=TSTDB
set ORACLE_CONNECTSTRING=tstdb
set ORACLE_BASE=c:\oracle
set ORACLE_HOME=%ORACLE_BASE%\ora81
在close_backup.sql脚本中:
define adm = 'sys'
define pwd = 'oracle8i'
define bkdir = 'C:\oracle\admin\TSTDB\backup'
4. 执行数据库备份任务 在C:\oracle\admin\admin script目录下双击close_Backup_run.bat文件 or
从命令中运行C:\oracle\admin\admin script\close_Backup_run.bat
现在你可以端起咖啡杯休息一下了
5. 如果要执行自动的备份,在windows的计划任务里添加一项定期运行教本C:\oracle\admin\admin script\close_Backup_run.bat 即可。