使用exp和imp对Oracle数据库进行简单的备份

来源:互联网 发布:深入浅出数据分析微盘 编辑:程序博客网 时间:2024/05/09 03:45

在dos窗口下执行下面的命令可以对oracle数据库的表做备份

导出命令:

exp jin/otojin@edc81 file=expdat-20061103.dat tables=(ORDR_HDR,ORDR_DTLS) 

其中用户名jin,密码otojin,数据库的连接串edc81,导出到文件expdat-20061103.dat,数据库的表(ORDR_HDR,ORDR_DTLS),

edc81在oracle的安装路径文件E:/oracle/product/10.1.0/Db_1/NETWORK/ADMIN/tnsnames.ora里:

EDC81 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.81)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl)
    )
  )

导入命令:

imp jin/otojin@edc81 fromuser=jin touser=jin file=expdat-20061103.dat tables=(ORDR_HDR,ORDR_DTLS)

其中多了fromuser和touser。

还有其他一些类似的命令,不作详细解释

exp lxf/lxf rows=y indexes=n compress=n buffer=65536 feedback=100000  file=exp_system_manager_20051121.dmp log=exp_system_manager_20051121.log tables=lxf.mt_corp,lxf.mt_account

imp system/manager fromuser=system touser=system rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_system_manager_20051121.dmp log=imp_system_manager_20051121.log tables=test,testuser

可以写到一个sql文件里,然后通过sql plus命令执行,已经记不清是否测试过

文件get__log_radius_data.sql:

BACKUP_DIR=.
year = `date +%Y`
month = `date +%m`
file1 = $BACKUP_DIR/${year}${month}_log_radius.txt

set colsep ' ';
set echo off;
set feedback off;
set heading on;
set pagesize 0;
set linesize 500;
set numwidth 12;
set termout off;
set timing off;
set trimout on;
set trimspool on;
spool $file1;
select * from log_radius;
spool off;
exit;

用下面的命令执行:

sqlplus lxf/lxf@orcl  @get_log_radius_data.sql

还有一些不知道的命令,暂时放在这里:

nohup sqlplus lxf/lxf@orcl < getdata.sql  &