第5章:从打开的数据库备份与恢复之备份打开的数据库

/* 2008/05/27
*环境:Windows XP +Oracle10.2.0.1
*Oracle 备份与恢复培训教程 Kenny Smith,Stephan Haisley著 周琪、韩岷、李渝琳等译
*第二部分:用户管理的备份与恢复
*第5章:从打开的数据库备份与恢复
*/

练习5.1:备份打开的数据库
1、产生数据库活动
SQL> insert into tina.date_log values(sysdate);

已创建 1 行。
SQL> alter system switch logfile;

系统已更改。

2、创建备份脚本
创建e:\open_backup.sql脚本
脚本内容:
Set feedback off pagesize 0 heading off verify off linesize 100 trimspool on
define dir='e:\backup'
define fil='e:\open_backup_commands.sql'
define spo='&dir\open_backup_output.lst'
prompt *** Spooling to &fil

set serveroutput on
spool &fil
prompt spool &spo

prompt archive log list;;
prompt alter system switch logfile;;

declare
   cursor cur_tablespace is
    select tablespace_name from dba_tablespaces
     where status<>'READ ONLY' and tablespace_name<>'TEMP';
   cursor cur_datafile (tn varchar) 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 copy '||cd.file_name||' &dir');
  end loop;
    dbms_output.put_line('alter tablespace '|| ct.tablespace_name||' end backup;');
  end loop;
end;
/

prompt alter system switch logfile;;
prompt alter database backup controlfile to '&dir\backup.ctl' reuse;;
prompt archive log list;;
prompt spool off;;
spool off;
@&fil


3、运行热备份脚本
SQL> @e:\open_backup.sql


注释:用户表空间置于备份模式,查看联机数据文件的备份状态:
SQL> alter tablespace users begin backup;

表空间已更改。

SQL> select d.tablespace_name tablespace,b.file#,
  2  b.status,b.change#,b.time
  3  from dba_data_files d,v$backup b
  4  where b.file#=d.file_id
  5  order by tablespace_name;

TABLESPACE          FILE# STATUS                CHANGE# TIME
-------------- ---------- ------------------ ---------- --------------
RISE                    5 NOT ACTIVE             572699 27-5月 -08
SYSAUX                  3 NOT ACTIVE             572668 27-5月 -08
SYSTEM                  1 NOT ACTIVE             572636 27-5月 -08
UNDOTBS1                2 NOT ACTIVE             572655 27-5月 -08
USERS                   4 ACTIVE                 573763 27-5月 -08


SQL> alter tablespace users end backup;

表空间已更改。

4、检查备份命令
查看e:\open_bakcup_commands.sql文件,该文件中的命令是否正确。

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

转载于:http://blog.itpub.net/12778571/viewspace-312655/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值