您在这里:首页 > 学员专区 > 技术文章
Oracle视频
Oracle
CUUG课程

非一致性备份(热备份)

 

(1)编写热备份脚本(双重spool)

set feedback off pagesize 0 heading off verify off linesize 100 trimspool on echo off time off

define bakdir='/disk1/backup/anny/hot_bak'

define bakscp='/disk1/backup/anny/hot_cmd.sql'

define spo='&bakdir/hot_bak.lst'

prompt ***spooling to &bakscp

set serveroutput on

spool &bakscp

prompt spool &spo

prompt alter system switch logfile;;

declare

cursor cur_tablespace is

select tablespace_name from dba_tablespaces where status <>'READ ONLY' and contents  not like '%TEMP%';

cursor  cur_datafile (tn varchar2) is

select file_name from dba_data_files where tablespace_name=tn;

begin

for ct in cur_tablespace loop

dbms_output.put_line('alter tablespace '||ct.tablespace_name ||' begin backup; ');

for cd in cur_datafile(ct.tablespace_name) loop

dbms_output.put_line('host cp '||cd.file_name||' &bakdir');

end loop;

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

end loop;

end;

/

prompt archive log list;;

prompt spool off;;

spool off;

@&bakscp          ——一般先不执行该脚本,要先检查有没有错

 

(2)执行上面的脚本,会生成一个/disk1/backup/anny/hot_cmd.sql脚本,用来进行冷备份的

[oracle@solaris10 anny]$cat hot_cmd.sql

spool /disk1/backup/anny/hot_bak/hot_bak.lst

alter system switch logfile;

alter tablespace SYSTEM begin backup;

host cp /u01/app/oracle/oradata/anny/system01.dbf /disk1/backup/anny/hot_bak

alter tablespace SYSTEM end backup;

alter tablespace SYSAUX begin backup;

host cp /u01/app/oracle/oradata/anny/sysaux01.dbf /disk1/backup/anny/hot_bak

alter tablespace SYSAUX end backup;

alter tablespace USERS begin backup;

host cp /u01/app/oracle/oradata/anny/user01.dbf /disk1/backup/anny/hot_bak

alter tablespace USERS end backup;

alter tablespace TEXT begin backup;

host cp /u01/app/oracle/oradata/anny/text01.dbf /disk1/backup/anny/hot_bak

alter tablespace TEXT end backup;

alter tablespace LX01 begin backup;

host cp /u01/app/oracle/oradata/anny/lx01.dbf /disk1/backup/anny/hot_bak

alter tablespace LX01 end backup;

alter tablespace UNDOTBS begin backup;

host cp /u01/app/oracle/oradata/anny/undotbs01.dbf /disk1/backup/anny/hot_bak

alter tablespace UNDOTBS end backup;

alter tablespace LX02 begin backup;

host cp /u01/app/oracle/oradata/anny/lx02.dbf /disk1/backup/anny/hot_bak

alter tablespace LX02 end backup;

alter tablespace LX03 begin backup;

host cp /u01/app/oracle/oradata/anny/lx03.dbf /disk1/backup/anny/hot_bak

alter tablespace LX03 end backup;

alter tablespace LX04 begin backup;

host cp /u01/app/oracle/oradata/anny/lx04.dbf /disk1/backup/anny/hot_bak

alter tablespace LX04 end backup;

alter tablespace INDEXES begin backup;

host cp /u01/app/oracle/oradata/anny/index01.dbf /disk1/backup/anny/hot_bak

alter tablespace INDEXES end backup;

archive log list;

spool off;

 

(3)执行上面的脚本hot_cmd.sql,又会生成一个列表文件hot_bak.lst,以下是列表文件的内容,也就是执行hot_cmd.sql的结果!

Database log mode              Archive Mode

Automatic archival             Enabled

Archive destination            /disk1/arch/anny

Oldest online log sequence     17

Next log sequence to archive   20

Current log sequence           20

***********************************至此,备份成功************************************

 

——查看原始文件的大小

——手工备份会备份database里datafile的所有数据块
SQL> col name for a50

SQL> select file#,name,bytes/1024/1024 "Size" from v$datafile;

1 /u01/app/oracle/oradata/anny/system01.dbf                 325

2 /u01/app/oracle/oradata/anny/lx02.dbf                      10

3 /u01/app/oracle/oradata/anny/sysaux01.dbf                 325

4 /u01/app/oracle/oradata/anny/user01.dbf                   200

5 /u01/app/oracle/oradata/anny/text01.dbf                   100

6 /u01/app/oracle/oradata/anny/lx01.dbf                      10

7 /u01/app/oracle/oradata/anny/undotbs01.dbf                110

8 /u01/app/oracle/oradata/anny/lx03.dbf                      10

9 /u01/app/oracle/oradata/anny/lx04.dbf                      10

10 /u01/app/oracle/oradata/anny/index01.dbf                  100

 

——查看备份后文件大小

[oracle@solaris10 hot_bak]$ls -lht

×üêy 2459138

-rw-r--r--   1 oracle   oinstall     243  3   19è  16:32 hot_bak.lst

-rw-r-----   1 oracle   oinstall    100M  3   19è  16:32 index01.dbf

-rw-r-----   1 oracle   oinstall     10M  3   19è  16:32 lx04.dbf

-rw-r-----   1 oracle   oinstall     10M  3   19è  16:32 lx03.dbf

-rw-r-----   1 oracle   oinstall     10M  3   19è  16:32 lx02.dbf

-rw-r-----   1 oracle   oinstall    110M  3   19è  16:32 undotbs01.dbf

-rw-r-----   1 oracle   oinstall     10M  3   19è  16:32 lx01.dbf

-rw-r-----   1 oracle   oinstall    100M  3   19è  16:32 text01.dbf

-rw-r-----   1 oracle   oinstall    200M  3   19è  16:32 user01.dbf

-rw-r-----   1 oracle   oinstall    325M  3   19è  16:32 sysaux01.dbf

-rw-r-----   1 oracle   oinstall    325M  3   19è  16:32 system01.dbf


通过对比,手工备份后大小和原文件大小几乎相等,RMAN备份不一样,只备份已经使用的块。

相关文章 [上一篇] 一致性备份(冷备份)
010-88589926(88587026)
CUUG热门培训课程
Oracle DBA就业培训
CUUG名师
网络课程
技术沙龙
最新动态

总机:(010)-88589926,88589826,88587026 QQ讨论群:243729577 182441349 邮箱:cuug_bj@cuug.com
通信地址:北京市海淀区紫竹院路98号北京化工大学科技园609室(CUUG)邮政编码:100089 
中国UNIX用户协会 Copyright 2010  ALL Rights Reserved 北京神脑资讯技术有限公司
京ICP备11008061号  京公网安备110108006275号