oracle数据库备份与还原完整版

备份和还原数据库是我们开发人员的必备技能,在这里写篇文章记录一下,供大家参考。

oracle创建表空间

备份与还原oracle数据库前,先查一下导出库的表空间,在导入库添加相应的表空间。

  • 查看当前用户的缺省表空间
select * from user_users;
  • 查询用户所有表空间(一个用户可能有多个表空间)
select tablespace_name,owner from dba_segments where owner ='old_db_name' group by tablespace_name,owner;
  • 修改用户表空间
alter user username default tablespace TBS01;
  • (超管)查看表空间
select * from dba_tablespaces;
  • (超管)查看表空间文件
    select * from dba_data_files;

  • 在新库(就是一会要建新用户来还原数据库的机器上的oracle)创建表空间

create tablespace TBS01
datafile '/u01/app/oracle/oradata/TBS01.DBF'
size 128m
autoextend on
    next 50m
    maxsize unlimited;
  • 删除非空表空间,包含物理文件
    drop tablespace TBS01 including contents and datafiles;

oracle创建用户

新增一个用户用来还原数据库(对于oracle,一个数据库就是对应的一个oracle用户)。备份数据库时查一下用户有哪些权限,新增的用户也分配同样的权限。

  • 创建用户并授权
create user db_user_name identified by oracle
default tablespace TBS01 
temporary tablespace TEMP
profile DEFAULT;

grant connect to db_user_name;
grant resource to db_user_name;
grant create database link to db_user_name;
grant create job to db_user_name;
grant create procedure to db_user_name;
grant create public database link to db_user_name;
grant create synonym to db_user_name;
grant create table to db_user_name;
grant create view to db_user_name;
grant debug connect session to db_user_name;
grant select any dictionary to db_user_name;
grant unlimited tablespace to db_user_name;
  • 查询用户
select * from all_users;   
  • 删除用户
drop user db_user_name cascade;

导出(备份)

  • 执行dos命令,导出数据库备份文件:
exp 'sys/oracle@192.168.10.162/orcl as sysdba' owner=old_db file=d:\old_db.dmp buffer=102400000

导入(还原)

  • 执行dos命令,把数据库备份文件还原到新库:
imp 'sys/oracle@192.168.10.174/orcl as sysdba' fromuser=old_db touser=new_db file=d:\old_db.dmp  log=d:\new_db_imp.log ignore=y;

备注:执行导出导入命令的机器要安装oracle客户端。

欢迎大家访问我的博客:随风飘雁的博客

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值