Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1279234
  • 博文数量: 1211
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 14340
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-09 11:20
文章分类

全部博文(1211)

文章存档

2011年(1)

2008年(1210)

我的朋友

分类: 服务器与存储

2008-06-13 15:36:55

以下是oracle导出备份和导入恢复自动产生sql源代码各变量含义为:
      EXP_BACK_DIR:  导出ORACLE数据库的DMP文件所放目录
      SCRIPT_FILE: 此代码所生成的批处理文件路径及文件名称
      LOG_FILE: 导出日志文件存放路径及文件名称
      INT_USER:导出的ORACLE数据库的用户名
      INT_PWD: 导出的ORACLE数据库的用户的口令
      以下代码存成sql文件后
      可以通过COMMAND :sqlplus internal/oracle@sqcdb @产生备份SQL代码的原文件名 <参数> 来运行。

  EXP导出备份SQL源文件

  --You must have select privileges on the v$parameter
  --v$logfile v$datafile and v$controlfile data
  --dictionary views belonging to SYS to run this program

  define EXP_BACK_DIR = e:oradbexpbackups
  define SCRIPT_FILE = e:ackexpbackup.bat
  define LOG_FILE= e:ackexpbackup.log
  define INT_USER = gas
  define INT_PWD = gas
  set feedback off
  set heading off
  set pagesize 0
  set linesize 128
  set verify off
  set echo off
  col a new_value b
  col c new_value d
  select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';

  spool &SCRIPT_FILE
  prompt rem ***** EXP ORACLE DATABASE FOR &INT_USER USER of &b ON WINDOWS NT ON &d*****
  prompt
  prompt rem ***** SET BACKUP FILES DIRECTORY *****
  prompt md e:oradb
  prompt md e:oradbexpbackups
  prompt
  select 'del &EXP_BACK_DIRexp&INT_USER.dmp' from dual;
  prompt
  select 'exp Userid=&INT_USER/&INT_PWD file=&EXP_BACK_DIRexp&INT_USER.dmp Buffer=102400 log=&EXP_BACK_DIRexp&INT_USER grants=y indexes=y' from dual;
  prompt
  select 'copy &EXP_BACK_DIRexp&INT_USER.dmp &EXP_BACK_DIRexp&INT_USER'||to_char(sysdate, 'MMDDHH24MI')||'.dmp' from dual;
  prompt
  prompt set LogFile=&LOG_FILE
  prompt echo COMPLETE EXP BACKUP FOR &INT_USER USER "&b" DATABASE STARTED ON &d ...> %logFile%
  prompt exit 

  spool off

  $&SCRIPT_FILE
  $del &SCRIPT_FILE
  exit

  IMP整个用户导入的SQL源文件

  --You must have select privileges on the v$parameter
  --v$logfile v$datafile and v$controlfile data
  --dictionary views belonging to SYS to run this program

  define EXP_BACK_DIR = e:oradbexpbackups
  define SCRIPT_FILE = e:ackimprevall.bat
  define LOG_FILE= e:ackimprevall.log
  define INT_USER = gas
  define INT_PWD = gas
  define TO_USER = gas
  set feedback off
  set heading off
  set pagesize 0
  set linesize 128
  set verify off
  set echo off
  col a new_value b
  col c new_value d
  select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';

  spool &SCRIPT_FILE
  prompt rem ***** IMP ORACLE DATABASE FOR &INT_USER USER OF &b ON WINDOWS NT ON &d*****
  prompt
  select 'imp Userid=&INT_USER/&INT_PWD fromuser=&INT_USER touser=&TO_USER commit=y ignore=y Buffer=102400 file=&EXP_BACK_DIRexp&INT_USER.dmp log=&EXP_BACK_DIRimp&TO_USER '  from dual;
  prompt
  prompt set LogFile=&LOG_FILE
  prompt echo COMPLETE IMP RECOVER FOR &INT_USER USER OF "&b" DATABASE STARTED ON &d ...> %logFile%
  prompt exit 

  spool off

  $&SCRIPT_FILE
  $del &SCRIPT_FILE
  exit

  IMP单个表导入的SQL源文件

  --You must have select privileges on the v$parameter
  --v$logfile v$datafile and v$controlfile data
  --dictionary views belonging to SYS to run this program

  -- define tablename =a3

  define EXP_BACK_DIR = e:oradbexpbackups
  define SCRIPT_FILE = e:ackimprevtab.bat
  define LOG_FILE= e:ackimprevtab.log
  define SQL_FILE = e:ack runtab.sql
  define TRIG_FILE = e:ackentrig.sql
  define INT_USER = gas
  define INT_PWD = gas
  define TO_USER = gas
  set feedback off
  set heading off
  set pagesize 0
  set linesize 128
  set verify off
  set echo off
  col a new_value b
  col c new_value d
  select value a,to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') c from v$parameter where name ='db_name';
  spool &SQL_FILE
  select 'alter table &&1 disable  all triggers;' from dual;
  select 'truncate table &&1 ;' from dual;
  select 'exit' from dual;
  spool off
  spool &TRIG_FILE
  select 'alter table &&1 enable  all triggers;' from dual;
  select 'exit' from dual;
  spool off
  spool &SCRIPT_FILE
  prompt rem ***** IMP ORACLE DATABASE FOR TABLE OF &INT_USER USER OF &b ON WINDOWS NT ON &d*****
  prompt sqlplus gas/gas@sqcdb.sqc.com @&SQL_FILE
  select 'imp Userid=&INT_USER/&INT_PWD fromuser=&INT_USER touser=&TO_USER commit=y ignore=y  Buffer=102400 tables=&&1 file=&EXP_BACK_DIRexp&INT_USER.dmp ' from dual;
  prompt sqlplus gas/gas@sqcdb.sqc.com @&TRIG_FILE
  prompt set LogFile=&LOG_FILE
  prompt echo COMPLETE IMP RECOVER FOR TABLE OF &INT_USER USER OF "&b" DATABASE STARTED ON &d ...> %logFile%
  prompt exit 
  spool off

  $&SCRIPT_FILE
  $del &SQL_FILE
  $del &TRIG_FILE
  $del &SCRIPT_FILE
  exit

   

阅读(340) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~