Wiki source code of Архивация для менеджеров
Last modified by Pavel Tuhari on 2021/09/12 20:56
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | (% class="page-header" %) | ||
| 2 | ((( | ||
| 3 | (% itemprop="headline" %) | ||
| 4 | == Oracle: дамп базы данных == | ||
| 5 | ))) | ||
| 6 | |||
| 7 | * ((( | ||
| 8 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 9 | ДЛЯ БЫСТРОГО СОЗДАНИЯ АРХИВА НЕБОЛЬШОЙ БД, НАПРИМЕР БД НА КАССЕ, frontoffice.una.md в режиме терминала MS WINDOWS, команда CMD и при установленным ПО клиент СУБД Oracle введите две 2 команды : | ||
| 10 | |||
| 11 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 12 | (% style="font-size: 14px; font-weight: 700; font-family: Courier; font-size: 10pt" %)exp SYStem/manager@casa FULL=y FILE=dba.dmp LOG=dba.log CONSISTENT=y | ||
| 13 | |||
| 14 | (% style="font-style: normal; text-align: start;" %) | ||
| 15 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %)эта команда выгрузит все схемы внутри базы данных Oracle в файл размером в мегабайты (иначе выгрузка точно не прошла успешно) под именем например (% style="font-family: Courier; font-size: 13.333333015441895px; font-style: normal; font-weight: bold; text-align: start; background-color: rgb(232, 231, 231);" %)dba.dmp (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) ,а также выгрузит в файл например (% style="font-family: Courier; font-size: 13.333333015441895px; font-style: normal; font-weight: bold; text-align: start; background-color: rgb(232, 231, 231);" %)dba.log(% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) в отчет об успешности выгрузки данных и объектов, важно чтобы этот отчет не содержал фроз об ошибках, иначе (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start; background-color: rgb(232, 231, 231);" %) выгрузка скорее всего не прошла успешно | ||
| 16 | |||
| 17 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 18 | (% style="font-family: Courier; font-size: 10pt; font-size: 13.333332px; font-weight: 700" %)zip dbazipflyonedmp dba*.* | ||
| 19 | |||
| 20 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 21 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %)эта команда запакует или сожмет оба файла созданных на первом шаге и позволит быстрее вам выгрузит все схемы внутри базы данных Oracle в файл размером в мегабайты (иначе выгрузка точно не прошла успешно) под именем например (% style="font-family: Courier; font-size: 13.333333015441895px; font-style: normal; font-weight: bold; text-align: start; background-color: rgb(232, 231, 231);" %)dba.dmp (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) ,а также выгрузит в файл например (% style="font-family: Courier; font-size: 13.333333015441895px; font-style: normal; font-weight: bold; text-align: start; background-color: rgb(232, 231, 231);" %)dba.log(% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) в отчет об успешности выгрузки данных и объектов, важно чтобы этот отчет не содержал фраз об ошибках, иначе (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start; background-color: rgb(232, 231, 231);" %) выгрузка скорее всего не прошла успешно | ||
| 22 | |||
| 23 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 24 | |||
| 25 | |||
| 26 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 27 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start; background-color: rgb(232, 231, 231);" %)испытайте wetransfer для передачи файла через линк , без почты | ||
| 28 | |||
| 29 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 30 | |||
| 31 | |||
| 32 | (% style="font-family: sans-serif; font-size: 14px; font-style: normal; text-align: start;" %) | ||
| 33 | (% style="font-family: Courier; font-size: 10pt; font-size: 13.333332px; font-weight: 700" %)далее подробнее об этом | ||
| 34 | ))) | ||
| 35 | * [[oracle>>http://it.skisport.org.ua/index.php/component/tags/tag/oracle||class="label label-info"]] | ||
| 36 | * [[Импорт и экспорт базы данных Oracle.>>http://it.skisport.org.ua/index.php/menuoracle/74-essayoracledump||rel="__blank"]] | ||
| 37 | |||
| 38 | Для экспорта и импорта БД Oracle существуют стандартные утилиты - **exp** и **imp** соответственно. Они идут вместе с основной инсталляцией Oracle и находятся в директории $ORACLE_HOME/bin. | ||
| 39 | |||
| 40 | [[image:EXPDP.png||height="70%" width="70%"]] | ||
| 41 | |||
| 42 | ===== **Экспорт** ===== | ||
| 43 | |||
| 44 | (% style="font-size: 10pt; font-family: Courier" %)**exp SYSTEM/password FULL=y FILE=dba.dmp LOG=dba.log CONSISTENT=y** | ||
| 45 | |||
| 46 | или | ||
| 47 | |||
| 48 | (% style="font-size: 10pt; font-family: Courier" %)**exp SYSTEM/password PARFILE=params.dat** | ||
| 49 | |||
| 50 | Но в этом случае необходим файл с параметрами params.dat с таким содержимым: | ||
| 51 | |||
| 52 | (% style="font-family: Courier; font-size: 10pt;" %)FILE=dba.dmp(%%) | ||
| 53 | (% style="font-family: Courier; font-size: 10pt;" %)GRANTS=y(%%) | ||
| 54 | (% style="font-family: Courier; font-size: 10pt;" %)FULL=y(%%) | ||
| 55 | (% style="font-family: Courier; font-size: 10pt;" %)ROWS=y(%%) | ||
| 56 | (% style="font-family: Courier; font-size: 10pt;" %)LOG=dba.log | ||
| 57 | |||
| 58 | (% style="font-family: Courier; font-size: 10pt;" %)**exp SYSTEM/password FIlE=expdat.dmp TABLES=(emp,deploy,offices,...)** | ||
| 59 | |||
| 60 | экспорт отдельных таблиц. | ||
| 61 | |||
| 62 | (% style="font-size: 10pt;" %)Экспорт схемы: | ||
| 63 | |||
| 64 | (% style="font-family: Courier; font-size: 10pt;" %)**exp SYSTEM/password OWNER=user FILE=dumpfile LOGFILE=logfile** | ||
| 65 | |||
| 66 | ===== **Импорт** ===== | ||
| 67 | |||
| 68 | (% style="font-size: 10pt; font-family: Courier" %)**imp SYSTEM/password FULL=y FIlE=dba.dmp** | ||
| 69 | |||
| 70 | (% style="font-family: Courier; font-size: 10pt;" %)**imp SYSTEM/password FIlE=dba.dmp FROMUSER=scott TABLES=(dept,emp)** | ||
| 71 | |||
| 72 | импорт выбранных таблиц пользователя scott. | ||
| 73 | |||
| 74 | |||
| 75 | Если запуск утилит exp, imp осуществляется без параметров, то мы попадем в интерактивный режим работы утилит. | ||
| 76 | |||
| 77 | Начиная с версии Oracle 10g наряду с утилитами exp,imp появились новые утилити Data Pump - expdp и impdp соответственно. Они также находятся в каталоге bin домашней папки Оракла. Коренное отличие состоит в том что обычные утилиты экспорта и импорта ориентированы на работу со стороны клиента, а новые - на работу со стороны сервера. Хотя старые и новые утилиты похожи друг на друга по использованию, однако результаты их работы совершенно разные. Это означает, что дамп, экспортированный с помощью exp, нельзя импортировать с помощью impdp. | ||
| 78 | |||
| 79 | Для работы этих утилит сначала необходимо создать папку-объект ("directory object") например в директории /tmp/backup, а также дать права на чтение и запись пользователю, который будет делать экспорт : | ||
| 80 | |||
| 81 | (% style="font-size: 10pt; font-family: Courier" %)**$ sqlplus /nolog** | ||
| 82 | |||
| 83 | (% style="font-size: 10pt; font-family: Courier" %)**SQL>connect sys/password@orcl as sysdba** | ||
| 84 | |||
| 85 | (% style="font-size: 10pt; font-family: Courier" %)**Connected.** | ||
| 86 | |||
| 87 | (% style="font-size: 10pt; font-family: Courier" %)**SQL>create directory export_dir as '/tmp/backup';** | ||
| 88 | |||
| 89 | (% style="font-size: 10pt; font-family: Courier" %)**SQL>grant read,write on directory export_dir to scott;** | ||
| 90 | |||
| 91 | Для того чтобы сделать полный экспорт, у пользователя должна быть роль exp_full_database. Дадим эту роль пользователю scott: | ||
| 92 | |||
| 93 | (% style="font-size: 10pt; font-family: Courier" %)**SQL>grant exp_full_database to scott;** | ||
| 94 | |||
| 95 | Теперь можно непосредственно приступать к экспорту: | ||
| 96 | |||
| 97 | (% style="font-size: 10pt; font-family: Courier" %)**$ expdp scott/password@orcl DIRECTORY=export_dir DUMPFILE=dump.tmp FULL=y** | ||
| 98 | |||
| 99 | Можно экспортировать отдельные таблицы: | ||
| 100 | |||
| 101 | (% style="font-size: 10pt; font-family: Courier" %)**$ expdp scott/password@orcl DIRECTORY=export_dir DUMPFILE=dump.tmp TABLES=table1,table2,...** | ||
| 102 | |||
| 103 | Импорт делается аналогично. Для импорта полной базы у пользователя должна быть роль imp_full_database: | ||
| 104 | |||
| 105 | (% style="font-size: 10pt; font-family: Courier" %)**$ impdp scott/password@orcl DIRECTORY=export_dir DUMPFILE=dump.tmp FULL=y** | ||
| 106 | |||
| 107 | (% style="font-size: 10pt; font-family: Courier" %)**$ impdp scott/password@orcl DIRECTORY=export_dir DUMPFILE=dump.tmp TABLES=table1,table2,...** |