脚本-LIUNX oracle热备份

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" <<EOF
@/home/oracle/BACKUP_SCRIPT/hot_backup.sql;
EOF


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


 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值