ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 第5章:从打开的数据库备份与恢复之备份打开的数据库

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

原创 Linux操作系统 作者:mengzhaoliang 时间:2008-05-27 19:12:40 0 删除 编辑

/* 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博客 ” ,链接:https://blog.itpub.net/12778571/viewspace-312655/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2008-01-30

  • 博文量
    336
  • 访问量
    3085660