当前位置:网站首页>Oracle backup or restore database (expdp, impdp)
Oracle backup or restore database (expdp, impdp)
2022-06-25 12:46:00 【good_ good_ xiu】
1. First, create or change the virtual directory
Because the data pump mode ——expdp( export ) and impdp( Import ) Virtual directory path required .
-- grammar
create or replace directory Virtual directory name as ' Virtual directory absolute path ';
-- Example : Create or modify data_backup Logical directory
create or replace directory data_backup as 'D:\app\Administrator\admin\bysjdb\dbdump\20210709';
If it is the first time to create data_backup This logical Directory , You also need to give the data user readable and writable permissions . In this way, you can back up and restore .
-- grammar
grant read,write on directory Virtual directory name to Database users ;
-- Example
grant read,write on directory data_backup to Database users ;
2. Batch export database ( Backup )
Tips :expdp help=Y You can view the prompt
Suppose it's local oracle There are the following users BYSJtest、BYSJuser、System. The following statement will put BYSJ The user database named at the beginning is backed up to the specified virtual directory , Name the backup with the user name dmp file .
Be careful :%exp_pwd% Call for exp_pwd Variable , So in the implementation expdp Statement before , First pair oracle_sid、exp_pwd、exp_ip Variable assignment
-- explain
--username: User name for exporting data , Must write ;
--password: Password for exporting data , Must write ;
[email protected]: Address symbol , Must write ;
--serviceip and exp_sid:oracle Service name of , Must write [ip+ port +sid];
--1521: Port number ,1521 It is the default and can not be written , Non default to write ;
--schemas: The user name of the export operation ;
--dumpfile: Exported files ;
--logfile: Exported log file , Don't write ;
--directory: Name of the virtual folder created ;
--remap_schema= Source database user name : Target database user name , It is not necessary to write at the same time , The same can be omitted ;
-- grammar
expdp username/password@serviceip/servicename directory= Virtual directory dumpfile=username.dmp logfile=username.log schemas=username
-- Batch build expdp sentence
select
distinct
'expdp '||lower(atc.owner)||'/%exp_pwd%@%exp_ip%/%oracle_sid% directory=data_backup dumpfile='||lower(atc.owner)||'.dmp logfile='||lower(atc.owner)||'.log schemas='||lower(atc.owner)||''
from all_tab_columns atc
where atc.owner like 'BYSJ%';
To write bat Document and execute
-- Set up NLS_LANG Variable to specify character attributes
rem set NLS_LANG=CHINESE_CHINA.AL32UTF8
@echo [ Enter the corresponding sid]
set oracle_sid=bysj
@echo [ Enter the corresponding user password ]
set exp_pwd=123456
@echo [ Enter the corresponding ip Address 、 port ]
set exp_ip=192.168.x.xxx:1521
@echo [ Enter the corresponding user name ]
-- export expdp sentence
......
@echo [ Export complete ]
-- Wait for the user to confirm before closing the window
pause
3. Batch import database ( Restore )
according to directory Find the corresponding... According to the user name under the specified virtual directory dumpfile, Then import to the specified oracle_sid Of oracle In the database .
-- Batch build impdp sentence
select
distinct
'impdp '||lower(atc.owner)||'/%imp_pwd%@%imp_ip%/%oracle_sid% directory=data_backup dumpfile='||lower(atc.owner)||'.dmp full=Y ignore=Y logfile='||lower(atc.owner)||'.log'
from all_tab_columns atc
where atc.owner like 'BYSJ%';
To write bat Document and execute
-- Set up NLS_LANG Variable to specify character attributes
rem set NLS_LANG=CHINESE_CHINA.AL32UTF8
@echo [ Enter the corresponding sid]
set oracle_sid=bysj
@echo [ Enter the corresponding user password ]
set imp_pwd=123456
@echo [ Enter the corresponding ip Address 、 port ]
set imp_ip=192.168.x.xxx:1521
@echo [ Enter the corresponding user name ]
-- export impdp sentence
......
@echo [ Complete import ]
-- Wait for the user to confirm before closing the window
pause
4. Batch generate create user statements
Mr. Cheng is importing databases in batches
select
distinct
-- Statements begin
'start drop user '||atc.owner||' cascade; -- Create tablespace , Specify auto expansion as 5m, Maximum unlimited CREATE SMALLFILE TABLESPACE '||atc.owner||' DATAFILE ''D:\database\oracle_dbf\bysj\'||atc.owner||'.dbf'' SIZE 5M AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
-- Create user
CREATE USER '||atc.owner||' IDENTIFIED BY "123456"
-- Specify tablespace
DEFAULT TABLESPACE '||atc.owner||' TEMPORARY TABLESPACE TEMP;
-- Assign roles
GRANT "DBA" TO '||atc.owner||';
GRANT "CONNECT" TO '||atc.owner||';
GRANT "RESOURCE" TO '||atc.owner||';
ALTER USER '||atc.owner||' DEFAULT ROLE "DBA","CONNECT","RESOURCE";
-- User quotas are unlimited
GRANT UNLIMITED TABLESPACE TO '||atc.owner||';
end' -- End of sentence from all_tab_columns atc where atc.owner like 'BYSJ%'; -- Query the specified user
other
Or use exp、imp The way is also feasible , The speed is too slow , But it can be backed up locally , No need to create virtual directories .
-- explain
--username: User name for exporting data , Must write ;
--password: Password for exporting data , Must write ;
[email protected]: Address symbol , Must write ;
--serviceip and exp_sid:oracle Service name of , Must write [ip+ port +sid];
--1521: Port number ,1521 It is the default and can not be written , Non default to write ;
--file: Exported file path ;
--full=Y: Represents full import and Export
-- grammar
exp(imp) username/password@serviceip/servicename file=D:/db/username.dmp full=Y;
Export section according to user table
exp(imp) username/password@serviceip/servicename file='D:/db/username.dmp' tabels= (table1,table2,table3,...);
Export part according to table space
exp(imp) username/password@serviceip/servicename file='D:/db/username.dmp' tablespaces= (tablespace1,tablespace2,tablespace3,...);
Export the section according to the user
exp(imp) username/password@serviceip/servicename file='D:/db/username.dmp' owner(username1,username2,username3);
边栏推荐
- PHP multidimensional array sorting
- 地理空间搜索 ->R树索引
- A half search method for sequential tables
- Zunpin Yongyao advertising e-commerce system -- Zunpin Yongyao advertising e-commerce app system development source code sharing
- 2021-10-21
- [Visio]平行四边形在Word中模糊问题解决
- Micro engine generates QR code
- Optimal solution for cold start
- Error while sending STMT_ PREPARE packet. PID=29294
- laravel 9
猜你喜欢

Go novice exploration road 1

Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities

2021-09-28

PPT绘图之AI助力论文图

Wechat full-text search technology optimization

Render values to corresponding text

又是被Visdom搞崩溃的一夜

更新pip&下载jupyter lab

百度搜索稳定性问题分析的故事

聊聊高可用的 11 个关键技巧
随机推荐
Micro engine remote attachment 7 Niu cloud upload
Flutter automatically disappears after receiving push
Summary of common MySQL database commands (from my own view)
JS array length is defined
2021-09-22
Go novice exploration pause
Lighten the source code -- lighten the app system development function introduction to the beautiful world lighten the app system development source code in China
MySQL common interview questions
Zhangxiaobai's way of penetration (III) -- detailed explanation of SQL injection vulnerability principle (SQL Server)
PHP multidimensional array sorting
Total number of MySQL statistics, used and unused
[Visio]平行四边形在Word中模糊问题解决
The difference between this and super and their respective functions
Jupyter Notebook主题字体设置及自动代码补全
Optimal solution for cold start
node. JS architecture optimization: reverse proxy and cache service
Service charge and time setting code sharing involved in crmeb withdrawal process
C program linking SQLSERVER database: instance failed
(3) Pyqt5 tutorial -- > signal and slot preliminary test
Zhangxiaobai's way of penetration (VIII) - detailed operation steps of SQL injection - Boolean blind injection of blind injection