ITPub博客

首页 > 数据库 > Oracle > 脚本-LIUNX oracle热备份

脚本-LIUNX oracle热备份

原创 Oracle 作者:monkeybron 时间:2015-04-02 10:26:44 0 删除 编辑

LINUX:热备份脚本

mkdir -P /oracle_backup/hot_backup_dir/
touch /home/oracle/BACKUP_SCRIPT/hot_backup.sh
touch /home/oracle/BACKUP_SCRIPT/hot_backup.sql


hot_backup.sh 内容如下:

#!/bin/bash
. /home/oracle/.bash_profile
cd /oracle_backup
export ORACLE_SID=你的SID
rm -Rf hot_backup_dir
mkdir hot_backup_dir
echo off
sqlplus "sys/你的密码 as sysdba" <


hot_backup.sql 内容如下:

set heading off   
set feedback on  
set linesize 121
set termout on
set serveroutput on
begin                                                                                      
for x in ( select tablespace_name from dba_tablespaces where contents <> 'TEMPORARY' )     
loop                                                                                       
        dbms_output.put_line( 'alter tablespace ' || x.tablespace_name || ' begin backup');    
        execute immediate 'alter tablespace ' || x.tablespace_name || ' begin backup';       
end loop;         
end; 
/
set heading off   
set feedback off  
set linesize 121  
set termout off   
--generation  host backup sql scripts
spool /opt/oracle/BACKUP_SCRIPT/hot_01.log
select '--'||ts.name tsname,'host cp '||df.name||' /oracle_backup/hot_backup_dir/'
   ||substr(df.name,instr(df.name,'/',-1) + 1) 
from v$datafile df,v$tablespace ts
where ts.ts# not in (select distinct ts# from v$tempfile)
  and df.ts# = ts.ts#
  order by 1;
select 'host cp '||name||' /oracle_backup/hot_backup_dir/' from v$controlfile;  
spool off
--generation recovery sql scripts
spool /opt/oracle/BACKUP_SCRIPT/hot_02.log
select '--'||ts.name tsname,'host cp /oracle_backup/hot_backup_dir/'||substr(df.name,instr(df.name,'/',-1) + 1)||' '||df.name
from v$datafile df,v$tablespace ts
where ts.ts# not in (select distinct ts# from v$tempfile)
  and df.ts# = ts.ts#
  order by 1;
select 'host cp /oracle_backup/hot_backup_dir/'||substr(name,instr(name,'/',-1) + 1)||' '||name from v$controlfile;  
spool off
--execute auto hot backup
@/opt/oracle/BACKUP_SCRIPT/hot_01.log
set termout on
begin                                                                                     
for x in ( select tablespace_name from dba_tablespaces where contents <> 'TEMPORARY' )    
loop                                                                                      
        dbms_output.put_line( 'alter tablespace ' || x.tablespace_name || ' end backup'); 
        execute immediate 'alter tablespace ' || x.tablespace_name || ' end backup';      
end loop;                                                                                 
end;
/
exit


 

 

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30182853/viewspace-1482666/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-03-30

  • 博文量
    70
  • 访问量
    94588