خب در حقیقت با exportگیری کل structure دیتابیس رو انتقال می‌دهیم یعنی می‌توانیم کل structure یک دیتابیس را از یک سرور به یک سرور دیگه به صورت کامل انتقال دهیم. ولی برای بک‌آپ گیری به صورت معمول از RMAN استفاده می‌شود.

نکته: تو محیط RMAN می‌توان بک‌آپ با structure هم گرفت.

در اوراکل محیط export شامل ۲ ورژن میشه:

  1. Classic Export
  2. Export Data Pump (قابل دسترس از ورژن 10g به بعد)

قبل از export‌گیری محیطی را برای تست آماده می‌کنیم:

Enter user-name: system
Enter password:
Last Successful login time: Sat Apr 25 2015 22:24:51 +04:30

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> create user test identified by 123;
User created.
SQL> grant dba, connect to test;
Grant succeeded.
SQL> connect test
Enter password:
Connected.
SQL> create table t1(id number, name varchar2(20));
Table created.
SQL> insert into t1 values (1, 'mahdi');
1 row created.
SQL> insert into t1 values (2, 'mohsen');
1 row created.
SQL> insert into t1 values (2, 'mohammad');
1 row created.
SQL> select * from t1;
ID         NAME
---------- --------------------
1 mahdi
2 mohsen
2 mohammad
SQL>

حال دستور exp را برای آزمایش کپی گرفتن اطلاعات به صورت Classic Export اجرا می‌کنیم:

C:\Users\Mahdi>exp
Export: Release 12.1.0.1.0 - Production on Thu Jul 30 14:29:29 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.

Username: system
Password:
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
Enter array fetch buffer size: 4096 >

در این قسمت باید میزان سایز بافر را مشخص نمایید. اگر مقدار پیش‌فرض را مناسب می‌دانید با کلید enter آن را قبول کنید.

باقی تنظیمات را نیز با توجه به سیاست‌های بک‌آپ‌گیری دستابیس مشخص کنید:

Enter array fetch buffer size: 4096 >
Export file: EXPDAT.DMP > E:\app\EXP\test.dmp

(1)E(ntire database), (2)U(sers), or (3)T(ables): (2)U > U

Export grants (yes/no): yes >
Export table data (yes/no): yes >
Compress extents (yes/no): yes >
Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
server uses AL32UTF8 character set (possible charset conversion)

About to export specified users ...
User to be exported: (RETURN to quit) > test
User to be exported: (RETURN to quit) >

. exporting pre-schema procedural objects and actions
. exporting foreign function library names for user TEST
. exporting PUBLIC type synonyms
. exporting private type synonyms
. exporting object type definitions for user TEST

About to export TEST's objects ...
. exporting database links
. exporting sequence numbers
. exporting cluster definitions

در نهایت بعد از مشخص کردن تنظیمات لازم (اسم یوزر یا یوزرهای مورد نظر و ...) لاگ خروجی exp به صورت زیر خواهد بود:

. about to export TEST's tables via Conventional Path ...
. . exporting table T1 3 rows exported
. exporting synonyms
. exporting views
. exporting stored procedures
. exporting operators
. exporting referential integrity constraints
. exporting triggers
. exporting indextypes
. exporting bitmap, functional and extensible indexes
. exporting posttables actions
. exporting materialized views
. exporting snapshot logs
. exporting job queues
. exporting refresh groups and children
. exporting dimensions
. exporting post-schema procedural objects and actions
. exporting statistics
Export terminated successfully without warnings.

 اگر خط آخر لاگ خروجی شما نیز مانند لاگ من در بالا بود می‌توانید مطمئن باشید مشکلی در بک‌آپ‌گیری وجود ندارد وگرنه باید خطاها چک شوند.

نکته: در تنظمات exp می‌توانید مشخص کنید که از چند یوزر به بک‌آپ‌گیری انجام شود.

 

بازگردانی بک‌آپ Classic Exp

برای بازگردانی از دستور imp به شکل زیر استفاده می‌کنیم:

C:\Users\Mahdi>imp
Import: Release 12.1.0.1.0 - Production on Thu Jul 30 15:22:59 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Username: system
Password:
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
Import data only (yes/no): no >
Import file: EXPDAT.DMP > E:\app\EXP\test.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V12.01.00 via conventional path
import done in WE8MSWIN1252 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 >
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no >
Username: test
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 SYSTEM's objects into SYSTEM
. importing TEST's objects into TEST
IMP-00015: following statement failed because the object already exists:
"CREATE TABLE "T1" ("ID" NUMBER, "NAME" VARCHAR2(20)) PCTFREE 10 PCTUSED 40"
" INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 FR"
"EELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) LOGGING"
" NOCOMPRESS"
Import terminated successfully with warnings.

خب همونطور که در لاگ مشخصه اشتباهی که من کردم اینه که محتویات یوزر test رو پاک نکردم به همین دلیل امکان بازگردانی بک‌آپ در یوزر موجود وجود نداره.

SQL> drop user test cascade;
User dropped.

SQL> create user test identified by 123;
User created.

دقت داشته باشید با آپشن cascade کل محتویات درون یوزر همراه با یوزر پاک می‌شود، همچنین برای اینکه محتویات بک‌آپ به یوزر بازگردد ایجاد یوزر در Classic EXP لزومی است.

C:\Users\Mahdi>imp
Import: Release 12.1.0.1.0 - Production on Thu Jul 30 15:31:05 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.

Username: system
Password:

Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions

Import data only (yes/no): no >
Import file: EXPDAT.DMP > E:\app\EXP\test.dmp
Enter insert buffer size (minimum is 8192) 30720>

Export file created by EXPORT:V12.01.00 via conventional path
import done in WE8MSWIN1252 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 >

Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no >

Username: test
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 SYSTEM's objects into SYSTEM
. importing TEST's objects into TEST
. . importing table "T1"
IMP-00058: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'USERS'
Import terminated successfully with warnings.

باز اشتباهی رخ داده که به خاطر نداشتن رول‌های dba و connect یوزر مورد نظره:

C:\Users\Mahdi>sqlplus

SQL*Plus: Release 12.1.0.1.0 Production on Thu Jul 30 15:35:16 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.

Enter user-name: system
Enter password:
Last Successful login time: Thu Jul 30 2015 15:31:10 +04:30

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> drop user test cascade;
User dropped.

SQL> create user test identified by 123;
User created.

SQL> grant dba, connect to test;
Grant succeeded.

دوباره عملیات بازگردانی بک‌آپ را شروع می‌کنیم:

SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64
bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
C:\Users\Mahdi>imp
Import: Release 12.1.0.1.0 - Production on Thu Jul 30 15:41:31 2015
Copyright (c) 1982, 2013, Oracle and/or its affiliates. All rights reserved.
Username: system
Password:
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit
Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing opt
ions
Import data only (yes/no): no >
Import file: EXPDAT.DMP > E:\app\EXP\test.dmp
Enter insert buffer size (minimum is 8192) 30720>
Export file created by EXPORT:V12.01.00 via conventional path
import done in WE8MSWIN1252 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 >
Import grants (yes/no): yes >
Import table data (yes/no): yes >
Import entire export file (yes/no): no >
Username: test
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 SYSTEM's objects into SYSTEM
. importing TEST's objects into TEST
. . importing table "T1" 3 rows imported
Import terminated successfully without warnings.

C:\Users\Mahdi>

خب همانطور که در لاگ می‌بینید عملیات بک‌آپ بدون مشکل خاصی به اتمام رسید، برا اطمینان یکبار از جدول مورد نظر کوئری می‌گیریم:

SQL> select * from test.t1
2 ;

ID NAME
---------- --------------------
1 mahdi
2 mohsen
2 mohammad

SQL>