#冷备份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