oracle11g备份及恢复

oracle备份:

ora文件位置

/myweb/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora

create user ADMIN01 identified by ‘123456’;

grant connect,resource,create session to ADMIN01;

grant dba to ADMIN01;

commit;

创建linux下的表空间和临时空间。

mkdir /myweb/databases

chown -R oracle:oinstall /myweb/databases

create TABLESPACE K3CLOUD01 datafile ‘/myweb/databases/K3CLOUD01.DBF’ size 512M autoextend on next 256M permanent online;

创建临时表空间:

create TEMPORARY TABLESPACE JHTEMP tempfile ‘/myweb/databases/JHTEMP01.DBF’ size 128M autoextend on maxsize 1G tablespace group group1;

默认保存路径:

/myweb/app/oracle/product/11.2.0/dbhome_1/rdbms/log/cloud3.dmp

expdp ADMIN01/123456 schemas=ADMIN01 directory=pump_dir dumpfile=cloud3.dmp logfile=cloud3.log exclude=STATISTICS,TABLE:‘LIKE ‘TMP%’’;

create directory pump_dir as ‘/myweb/backup’;

grant read,write on directory pump_dir to ADMIN01;

expdp ADMIN01/123456 schemas=ADMIN01 directory=pump_dir dumpfile=cloud3.dmp logfile=cloud3.log exclude=STATISTICS,TABLE:‘LIKE ‘TMP%’’;

impdp ADMIN01/123456 directory=pump_dir dumpfile=cloud3.dmp REMAP_SCHEMA=ADMIN01:ADMIN02 EXCLUDE=USER;

导入后,执行:

在恢复出来的库中执行下列的语句。–增加表类型,用于IN子句等处理

CREATE OR REPLACE TYPE udt_inttable AS TABLE OF number(19);

GO

CREATE OR REPLACE TYPE udt_varchartable AS TABLE OF varchar(450);

GO

CREATE OR REPLACE TYPE udt_nvarchartable AS TABLE OF varchar2(450);

GO

如果想导入的用户已经存在:

  1. 导出用户 expdp user1/pass1 directory=dumpdir dumpfile=user1.dmp
  2. 导入用户 impdp user2/pass2 directory=dumpdir dumpfile=user1.dmp REMAP_SCHEMA=user1:user2 EXCLUDE=USER

如果想导入的用户不存在:

  1. 导出用户 expdp user1/pass1 directory=dumpdir dumpfile=user1.dmp
  2. 导入用户 impdp system/passsystem directory=dumpdir dumpfile=user1.dmp REMAP_SCHEMA=user1:user2
  3. user2会自动建立,其权限和使用的表空间与user1相同,但此时用user2无法登录,必须修改user2的密码

file scp

scp cloud3.zip root@192.168.1.10:/myweb/backup

覆盖恢复

impdp ADMIN01/123456 directory=pump_dir dumpfile=cloud1.dmp REMAP_SCHEMA=ADMIN01:ADMIN02 EXCLUDE=USER table_exists_action=replace;

删除oracle中用户ADMIN01

用oracle 登录

执行命令:lsnrctl stop

sqlplus / as sysdba;

shutdown immediate;

startup mount;

alter database open;

drop user ADMIN01 cascade;

退出到命令行

执行命令:lsnrctl start;.

备份脚本:

#filename:backup.sh

#!/bin.sh

now=$(date +%Y%m%d)

cd /myweb/backup

#su oracle

su - oracle -c ‘expdp ADMIN01/123456 schemas=ADMIN01 directory=pump_dir dumpfile=cloud n o w . 1. d m p l o g f i l e = c l o u d {now}.1.dmp logfile=cloud now.1.dmplogfile=cloud{now}.1.log exclude=STATISTICS,TABLE:\‘LIKE ‘TMP%’\’’

tar czvf cloud n o w . 1. t a r . g z c l o u d {now}.1.tar.gz cloud now.1.tar.gzcloud{now}.1.*

rm -rf cloud${now}.1.dmp

expdp ADMIN01/123456 schemas=ADMIN01 CLUSTER=N COMPRESSION=ALL directory=pump_dir dumpfile=cloud${now}.1.dmp exclude=STATISTICS,TABLE:‘LIKE ‘TMP%’’

create user ADMIN01 identified by “123456”;

grant connect,resource,create session to ADMIN01;

grant dba to ADMIN01;

impdp ADMIN01/123456 directory=pump_dir dumpfile=cloud20240527.1.dmp EXCLUDE=USER;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lwprain

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值