欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle 10g 数据库逻辑备份

程序员文章站 2024-01-06 17:53:46
...

1.首先我建立了一个名为linuxidc”的用户并且将其密码设为“linuxidc123” (以sys身份进行操作的sql语句) create user linuxi

1.首先我建立了一个名为"linuxidc”的用户并且将其密码设为“linuxidc123” (以sys身份进行操作的sql语句)

create user linuxidc identified by linuxidc123;

2.为新 用户分配一些权限

grant create session to linuxidc;
grant create table to linuxidc;

3.新建一个目录用来存放文件。(root身份在服务器上进行的操作。并且为该目修改所有者及组属性)

[root@ ~]# cd /u01/

[root@ u01]# mkdir ts

[root@ u01]# chown -R Oracle:oinstall ts

4.创建名为“linuxidc” (表空间)tablespace。并且将linuxidc用户加入到linuxidc表空间。并且给他分配一定的空间使用配额(sys身份)

create tablespace linuxidc
datafile '/u01/ts/linuxidc001.dbf'
size 20m ;

alter user linuxidc default tablespace linuxidc;

alter user linuxidc quota 20m on linuxidc;

5.使用linuxidc账户登录。创建一张名称为test1的测试表。

create table test1(
ts int,tsname varchar2(30));

Oracle 10g 数据库逻辑备份

6.建立备份目录并使用exp对数据进行导出(在服务器上执行)

[oracle@ u01]$ mkdir dump

[root@ u01]# chown -R oracle:oinstall dump

[root@ u01]# chmod 775 dump

[oracle@ dump]$ exp

Export: Release 10.2.0.1.0 - Production on Wed May 16 06:44:20 2012

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Username: sys as sysdba
Password:

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Enter array fetch buffer size: 4096 >

Export file: expdat.dmp > /u01/dump/emp052209.dmp --为要备份的对象选择目标文件及存储路径

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > t --在这里悬着对表备份

Export table data (yes/no): yes >

Compress extents (yes/no): yes > --默认压缩备份文件

Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
Table(T) or Partition(T:P) to be exported: (RETURN to quit) > scott.emp --所要导出的表,,指定该表的用户名

Current user changed to SCOTT
. . exporting table EMP 14 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Table(T) or Partition(T:P) to be exported: (RETURN to quit) >

Export terminated successfully with warnings.

此时已经完成备份

7.使用imp导入备份

[oracle@ dump]$ imp

Import: Release 10.2.0.1.0 - Production on Wed May 16 07:07:21 2012

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Username: sys as sysdba
Password:

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

Import file: expdat.dmp > /u01/empo52209.dmp --指定要导入的备份文件及所在的路径

IMP-00002: failed to open /u01/empo52209.dmp for read
Import file: expdat.dmp > /u01/dump/emp052209.dmp

Enter insert buffer size (minimum is 8192) 30720>

Export file created by EXPORT:V10.02.01 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no >

Ignore create error due to object existence (yes/no): no > yes --忽略错误提示

Import grants (yes/no): yes >

Import table data (yes/no): yes >

Import entire export file (yes/no): no >
Username: scott --该表的所属用户

Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done:

. importing SYS's objects into SYS
. importing SCOTT's objects into SCOTT
. . importing table "EMP" 14 rows imported
About to enable constraints...
Import terminated successfully with warnings.
[oracle@ dump]$

这个过程就是逻辑备份

更多Oracle相关信息见Oracle 专题页面 ?tid=12

Oracle 10g 数据库逻辑备份