数据库的备份和恢复(学习笔记学习中)

--**********************数据泵技术------oracle 10G之后出现

--创建目录

create directory dump_dir as 'e:/backup';

--查询数据库所有有目录

select * from dba_directories;

--删除数据库目录

drop directory dump_dir;

drop directory dump_file;

--创建表空间

create tablespace tbs_test

datafile 'e:/t.dbf'

size 10M

autoextend on;

--查询表空间

select * from dba_tablespaces;

--创建测试用户

create user tests identified by tests;

--用户授权

grant connect,resource to tests;

revoke imp_full_database from scott;

--授予用户操作dump_dir目录的权限

grant read ,write on directory dump_dir to tests;

grant read, write on directory dump_dir to scott;

---------------------------------备份(导出)--------------

--导出整个数据库

expdp help=y --帮助文件

--导出

expdp  system/accp@orcl directory=dump_dir  dumpfile=full.bak full=y 

--expdp导出

--directory   指定目录

--dumpfile  指定备份的文件名

--full      完整备份

--导出表空间

--查询表空间

select * from scott.

select  * from dba_tablespaces;

 --导出全部表空间 tablespaces表空间

expdp system/accp@orcl directory=dump_dir dumpfile=tablespacefull.bak tablespaces

--导出指定表空间 tablespaces=表空间表

expdp system/accp@orcl directory=dump_dir dumpfile=ts_test.bak tablespaces=tbs_test

--删除表空间

drop tablespace tbs_test;

--导出用户用SCHEMAS

--导出scott用户

expdp scott/tiger@orcl directory=dump_dir dumpfile=scottschma.bak  schemas=scott

--导出表

expdp scott/tiger@orcl directory=dump_dir dumpfile=scotttabs.bak  tables=emp,dept,bonus,salgrade

--使用管理员

expdp system/accp@orcl directory=dump_dir dumpfile=scotttbales.bak tables=scott.emp,scott.dept,scott.bonus,scott.salgrade

--导出一个表

expdp scott/tiger@orcl directory=dump_dir dumpfile=scottemp.bak   tables=emp

------------------------------恢复(导入)---------------

--impdd导入关键字

--导入emp表,scottemp.bak文件

impdp scott/tiger@orcl directory=dump_dir dumpfile=scottemp.bak tables=emp

--导入scott下的所有表 scotttabs.bak

impdp scott/tiger@orcl directory=dump_dir dumpfile=scotttabs.bak tables=emp,dept,bonus,salgrade

--将scott下的所有g表恢复到tests用户下,scott

--首先使用dba为scott权限imp_full_database

--导入数据权限

grant imp_full_database to scott;

--导出权限

grant exp_full_database to scott;

impdp scott/tiger@orcl directory=dump_dir dumpfile=SCOTTTABS.BAK tables=emp,dept,bonus,salgrade remap_schema=scott:tests

--将scott下的所有g表恢复到tests用户下,使用管理 员

impdp system/accp@orcl directory=dump_dir dumpfile=SCOTTTABS.BAK tables=scott.emp,scott.dept,scott.bonus,scott.salgrade remap_schema=scott:tests

--导入scott用户,用SCOTT用户

impdp scott/tiger@orcl directory=dump_dir dumpfile=scottschma.bak schemas=scott

--导入scott用户,使用管理员

impdp system/accp@orcl directory=dump_dir dumpfile=scottschma.bak schemas=scott

--将scott中所有对象导入tests中

impdp system/accp@orcl directory=dump_dir dumpfile=scottschma.bak schemas=scott remap_schema=scott:tests

--导入表空间

impdp system/accp@orcl directory=dump_dir dumpfile=tablespacetbs_test.bak tablespaces=tbs_test

--导入全部表空间

impdp system/accp@orcl directory=dump_dir dumpfile=TABLESPACEFULL.BAK

--恢复整个数据库

impdp system/accp@orcl directory=dump_dir dumpfile=full.bak full=y

--使用exp/imp命令------------------oraclr 10之前

使用exp/imp备份

exp help=y

--导出整个数据库

exp system/accp@orcl file=E:/bak/full.back full=y

--导出用户

exp scott/tiger@orcl file=E:/bak/scott.back owner=scott

--导出表

exp scott/tiger@orcl tables=(emp,dept) file=E:/bak/scotttabs.back

--导出USER表空间

exp system/accp@orcl tablespaces=(users) file=E:/bak/tbs_users

---导入

--导入数据库

imp system/accp@orcl file=E:/bak/full.back full=y

--导入表

imp system/accp@orcl file=E:/bak/scotttabs.back fromuser=scott touser=tests tables=(emp,dept)

exp/imp 和expdp/impdp命令在功能上的区别

1.把用户usera的对象导到用户userb

exp/imp用法

fromuser=usera touser=userb;

expdp/impdp用法

remap_schema=usera:userb

2.指定一些表

exp/imp用法:

tables=(table1,table2,....)

tables=(emp,dept);

expdp/impdp用法

tables=table1,table2,....

tables=emp,dept

3.更换表空间

expdp/impdp:

remap_tablespace=旧表空间名:新表空间名

4.是否要导出数据行

exp ROWS=y ,导出数据行,ROWS=N,不导出数据行

expdp content(ALL:对象+导出数据行,DATA_ONLY:只导出对象,METADATA_ONLY,只导出数据记录)

冷备份 和热备份

冷备份发生在数据库已经正常关闭的情况下,当正常关闭时会提供给我们一个完整的数据库

对ORACLE而言,冷备份是最快和最安全的方法

1 完全关闭数据库

2.备份所有数据库的数据文件

3.重新启动数据库

1)关闭数据库

sqlplus /nolog

connect sys/orcl@orcl as sysdba

shutdown normal;

2)复制数据,用复制命令备份ORCL数据库全部数据文件,重做日志文件,控制文件,初始化参数文件到指定目录

复制数据文件,重做日志文件,控制文件

host copy 'oracle主目录'oradateorcl   e:ack

复制初始化参数文件:

host copy 'oracle主目录'...initorcl.ora e:ack

3)重启数据库

 startup

 恢复步骤

 1)关闭数据库

 2)把备份的数据文件,控制文件,和联机重做日志还原

 3)启动数据库

 热备份

 是数据库下在运行情况下进行的,数据备份,热备份需要在数据库的归档模式下运行

 并需要大量的磁盘空间

原文地址:https://www.cnblogs.com/liunanjava/p/4209441.html