oracle备份脚本

#冷备份1
spool /tmp/bak.sql
select 'ho cp '||name||' /u02/orcl/' from v$controlfile 
union all
select 'ho cp '||name||' /u02/orcl/' from v$datafile  
union all
select 'ho cp '||name||' /u02/orcl/' from v$tempfile
union all
select 'ho cp '||/member||' /u02/orcl/' from v$logfile1
create pfile=' /u02/orcl/initorcl.ora' from spfile;
ho cp /u01/oracle/ 10g/dbs/orapworcl /u02/orcl/
spool off
shutdown immediate
ho sed -n '/~ho cp/p' /tmp/bak.sql >/ tmp/ bakorcl.sql
start /tmp/bakorcl.sql
ho rm /tmp/bak* .sqlstartup


#冷备份2
set echo off trimspool off heading off feedback off verify off time off
set pagesize 0 linesize 200
define bakdir= '/home/oracle/prod_bak/cold_bak'
define bakscp= '/home/oracle/prod_bak/cold_cmd.sql'
spoo1 &bakscp
    select 'host cp ' ||name||'&bakdir' from v$datafile order by 1;
    select 'host cp ' ||name||'&bakdir' from v$controlile order by 1;
spool off
shutdown immediate
&bakscp
startup
#热备份
#查看归档  archive log list
#shutdown immediate
#alter  database archiveloglog
#alter database mount
#archive log list
#alter database open
#1.通过数据库备份
spool  /tmp/hot.sql 
  select 'ho cp'||name||' /u02/horcl/" from v$datafile;
spool off

ho sed -n '/~ho cp/p' /tmp/hot.sql >/tmp/hotorcl.sql
alter database begin backup;
start /tmp/hotorcl.sql
alter database end backup ;

ho rm /tmp/hot*.sql

alter database backup controlfile to '/u02/horcl/control01.ctl';
create pfile=' /u02/horcl/initorcl.ora' from spfile;

#2.通过表空间备份

  spool /tmp/hot. sql
  select 'alter tablespace'||tablespace_name||'begin backup;'||chr(10)||'ho cp '||file_ 
  name||'/u02/horcl/'||chr(10)||'alter tablespace '||tablespace name||' end badxup;'  
  from dba_data_files order by tablespace_name ;
  spool off

  start /tmp/hot.sql
  ho rm /tmp/hot.sql

  alter database backup controlfile to '/u02/horcl/control01.ctl';
  create pfile='/u02/horcl/initorcl.ora' from spfile;
#热备份
set echo off trimspool off heading offfeedback off verify off time off
set pagesize 0  1inesize 200

define bakdir='/home/oracle/prod_bak/hot_bak'
define bakscp='/home/oracle/prod_bak/hot_cmd.sq1'
set serveroutput on
spool &bakscp

prompt alter  system archive 1og current;
declare cursor cu_tablespace is

select tablespace_name from dba_tablespaces where contents not like 'TEMP%' and status='ONLINE' ;

cursor cu_datafile(name varchar2) is

      select file_name from dba_data_files where tablespace_name=name;
begin
     for i in cu_tablespace loop
       dbms_output.put_line('alter tablespace'||i.tablespace_name||'begin backup;');
     for j in'cu_datafile(i.tablespace.name) loop
       dbms_output.pu_line('host cp '||j.file_name||' &bakdir ');
     end loop;

      dbms_output. put_line('alter tablespace '||i.tablespace_name||' end backup;');
end loop;

      dbms_output.put_line('a1ter database backup controlfile to trace;'); 

      dbms_output.put_line('alter database backup controlfile to 
                                                 "&bakdir/contro101.ct1";');
end;
/
prompt alter system archive log current;
spool off
@&bakscp

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凤舞飘伶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值