(原创)oracle数据库备份与恢复 a piece of cake (2)
2024-08-29 13:42:52
供稿:网友
第二集……
Oracle数据库冷备份:(unix or linux平台)
1. 建立教本治理目录 /u01/app/oracle/admin/admin_script
2. 建立数据库备份的脚本
在上面建立的目录下建立如下的两个脚本。
2.1 建立执行备份任务的脚本(shell script)
文件内容如下:
#! /bin/sh
Rem ===========================================================================
Rem NAME - close_Backup_run.sh
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 unix, set environment variables for the root path.
ORACLE_SID=TSTDB
ORACLE_CONNECTSTRING=tstdb
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/PRodUCt/8.1.7
ORACLE_DATA=$ORACLE_BASE/oradata/$ORACLE_SID
ORACLE_ADMIN=$ORACLE_BASE/admin/$ORACLE_SID
eXPort ORACLE_SID ORACLE_CONNECTSTRING ORACLE_BASE ORACLE_HOME ORACLE_DATA ORACLE_ADMIN
$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 Linux or Unix User variables
define bkdir = '/u05/oracle/oradata/tstdb/backup'
define filcbc = '/tmp/closed_backup_commands.sql'
define copy = 'cp'
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=/u01/app/oracle/
set ORACLE_HOME=$ORACLE_BASE/product/8.1.7
在close_backup.sql脚本中:
define adm = 'sys'
define pwd = 'oracle8i'
define bkdir = '/u05/oracle/oradata/TSTDB/backup'
4. 执行数据库备份任务
在$ORACLE_BASE/admin/admin_script目录下运行close_Backup_run.sh
[oracle@RHT admin_script]./close_Backup_run.sh
5. 执行自动备份。
在crontab文件中添加如下的一行
00 3 * * 6 $ORACLE_BASE/admin/admin_script/close_Backup_run.sh
解释:每周六凌晨3点执行数据库关闭,数据库备份,数据库重启。
具体的方式自己定义。
假如你有问题可以联系:
站内的短信:ganku
mail: peter_guo@pub.szedi.com.cn
guo_tianliang@yahoo.com