备份 Oracle

  1. 表单位
    1. 备份指定表
      exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 file=exp_icdmain_table_yyyymmdd.dmp log=exp_icdmain_table_yyyymmdd.log tables=icdmain.commoninformation,icdmain.serviceinfo,icdmain.dealinfo
    2. 恢复所有的表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_table_yyyymmdd.dmp log=imp_icdmain_table_yyyymmdd.log
    3. 恢复其中一部分表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_table_yyyymmdd.dmp log=imp_icdmain_table_yyyymmdd.log tables=commoninformation,serviceinfo
  2. 用户单位
    1. 备份指定用户的所有对象
      exp icdmain/icd rows=y indexes=n compress=n buffer=65536 feedback=100000 owner=icdmain file=exp_icdmain_user_yyyymmdd.dmp log=exp_icdmain_user_yyyymmdd.log
    2. 恢复指定用户的所有对象
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_user_yyyymmdd.dmp log=imp_icdmain_user_yyyymmdd.log
    3. 恢复指定用户的的一部分表
      imp icdmain/icd fromuser=icdmain touser=icdmain rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y file=exp_icdmain_user_yyyymmdd.dmp log=imp_icdmain_user_yyyymmdd.log tables=commoninformation,serviceinfo
  3. 整体备份
    1. 备份整个数据库
      exp system/manager rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y inctype=complete file=exp_fulldb_yyyymmdd.dmp log=exp_fulldb_yyyymmdd.log
    2. 整个数据库的增量备份
      exp system/manager rows=y indexes=n compress=n buffer=65536 feedback=100000 full=y inctype=incremental file=exp_fulldb_zl_yyyymmdd.dmp log=exp_fulldb_zl_yyyymmdd.log
    3. 从整体备份恢复所有对象
      imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y full=y file=exp_fulldb_yyyymmdd.dmp log=imp_fulldb_yyyymmdd.log
    4. 从增量备份恢复所有对象
      imp system/manager rows=y indexes=n commit=y buffer=65536 feedback=100000 ignore=y full=y inctype=restore file=exp_fulldb_zl_yyyymmdd.dmp log=imp_fulldb_zl_yyyymmdd.log

缩小 Oracle 表空间

———– maxshrink.sql ———————————-

set verify off
column file_name format a50 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column currsize format 999,990 heading "Current|Size"
column savings  format 999,990 heading "Poss.|Savings"
break on report
compute sum of savings on report

column value new_val blksize
select value from v$parameter where name = 'db_block_size'
/

select file_name,
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
       ceil( blocks*&&blksize/1024/1024) currsize,
       ceil( blocks*&&blksize/1024/1024) -
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
from dba_data_files a,
     ( select file_id, max(block_id+blocks-1) hwm
         from dba_extents
        group by file_id ) b
where a.file_id = b.file_id(+)
/

column cmd format a75 word_wrapped

select 'alter database datafile '''||file_name||''' resize ' ||
       ceil( (nvl(hwm,1)*&&blksize)/1024/1024 )  || 'm;' cmd
from dba_data_files a,
     ( select file_id, max(block_id+blocks-1) hwm
         from dba_extents
        group by file_id ) b
where a.file_id = b.file_id(+)
  and ceil( blocks*&&blksize/1024/1024) -
      ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/

转移 Oracle 的表空间

1.将表空间置于只读

只读状态可以使数据仍然可为用户访问.

alter tablespace tablespace_name read only;

2.物理拷贝文件

3.将表空间offline

alter tablespace tablespace_name offline;

4.rename数据文件

alter database rename file 'old_dir_file' to 'new_dir_file';

5.将表空间联机

alter tablespace tablespace_name online;

6.将表空间置于read write模式

alter tablespace tablespace_name read write;