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

2020-05-07  本文已影响0人  随风飘雁

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

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;
create tablespace TBS01
datafile '/u01/app/oracle/oradata/TBS01.DBF'
size 128m
autoextend on
    next 50m
    maxsize unlimited;

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;

导出(备份)

exp 'sys/oracle@192.168.10.162/orcl as sysdba' owner=old_db file=d:\old_db.dmp buffer=102400000

导入(还原)

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客户端。

上一篇 下一篇

猜你喜欢

热点阅读