zoukankan      html  css  js  c++  java
  • Oracle学习笔记十四:备份与恢复案例

    获取命令帮助

    exp -help
    imp -help
    expdp -help
    impdp -help
    rman target /
    ?

    测试数据准备

    CREATE TABLESPACE test01 datafile 'C:APPADMINISTRATORORADATATEST	est01.dbf' SIZE 10M autoextend off;
    CREATE USER hello IDENTIFIED BY world DEFAULT TABLESPACE test01;
    grant dba to hello;
    conn hello/world;
    
    create table emp01 (id number(3),name varchar2(10));
    insert into emp01 values(1,'hello01');
    insert into emp01 values(2,'hello02');
    insert into emp01 values(3,'hello03');

    案例一

    1.1、案例说明:在Oracle生产环境中,如何使用exp备份的整个数据库?

    1)查看数据库字符集:

    select * from nls_database_parameters where parameter='NLS_CHARACTERSET';
    --或者
    select userenv('language') from dual;

    本机数据库的字符集是:ZHS16GBK,若数据库与环境字符集不一样的话,请先设置字符集,如:

    export NLS_LANG=AMERICAN_AMERICA.AL32UTF8

    2)使用exp备份的整个数据库:

    exp system/oracle buffer=65536 feedback=10000 full=y file=exp.dmp log=exp.log

    案例二

    2.1、案例说明:在Oracle生产环境中,如果某员工删库跑路,把hello整个用户全误删,请使用imp进行恢复。

    1)模拟删除hello整个用户:

    drop user hello cascade;
    DROP TABLESPACE test01 INCLUDING CONTENTS AND DATAFILES;

     

    2)先创建表空间,再创建用户授权:

    CREATE TABLESPACE test01 datafile 'C:APPADMINISTRATORORADATATEST	est01.dbf' SIZE 10M autoextend off;
    CREATE USER hello IDENTIFIED BY world DEFAULT TABLESPACE test01;
    grant dba to hello;

    3)恢复hello整个用户:

    imp system/oracle fromuser=hello touser=hello commit=y buffer=65536 feedback=10000 ignore=y file=exp.dmp log=imp.log

    案例三

    3.1、案例说明:在Oracle生产环境中,如何使用expdp备份的整个数据库?

    1)先建一个备份的文件夹:

    cd c:usersadministrator
    mkdir dump

    2)创建一个Oralce内部用来识别OS文件系统路径目录并授权:

    create directory dump_dir as 'C:UsersAdministratordump';
    grant read,write on directory dump_dir to system;

    3)使用expdp备份的整个数据库:

    expdp system/oracle directory=dump_dir dumpfile=full_expdp.dmp full=y logfile=expdp.log parallel=2

    案例四

    4.1、案例说明:在Oracle生产环境中,如果某员工删库跑路,把整个数据库误删,请使用impdp进行恢复。

    1)这里就不删数据库了,只模拟删除hello整个用户来搞破坏:

    drop user hello cascade;
    DROP TABLESPACE test01 INCLUDING CONTENTS AND DATAFILES;

    2)创建数据库(此处略去),再创建表空间:

    CREATE TABLESPACE test01 datafile 'C:APPADMINISTRATORORADATATEST	est01.dbf' SIZE 10M autoextend off;

    3)配置directory(案例三2)已授权,此步可以省略):

    create directory dump_dir as 'C:UsersAdministratordump';
    grant read,write on directory dump_dir to system;

    4)使用impdp进行恢复:

    impdp system/oracle directory=dump_dir dumpfile=full_expdp.dmp full=y logfile=impdb.log

    5)编译无效对象:

    @?:@是sqlplus调用脚本的标识,?是指Oracle的安装路径(ORACLE_HOME)。

    @?/rdbms/admin/utlrp.sql

    6)结果验证:

    案例五

    5.1、案例说明:在Oracle中,机房需停电维修UPS,请备份整个Oracle环境。

    1)停止监听:

    lsnrctl stop

    2)关闭数据库:

    shutdown immediate;

    3)创建备份目录:

    cd c:usersadministrator
    mkdir backup

    4)使用WinRar备份整个Oracle环境:

    cd C:Program FilesWinRAR
    Rar a C:UsersAdministratorackuporaclebak20201016.rar C:app

    案例六

    6.1、案例说明:在Oracle中,机房完成UPS维护后,启动系统,发现Oracle启动失败,数据文件损坏,为了快速恢复业务,你应该怎么处理?

    1)删除数据库安装目录(仅为测试,请慎重):

    rd /s /q c:app

    2)目录恢复:

    cd C:Program FilesWinRAR
    Rar x -o+ C:UsersAdministratorbackuporaclebak20201016.rar C:

    案例七

    7.1、案例说明:在Oracle生产环境中,如何使用rman备份整个数据库?

    1)创建备份目录:

    cd c:usersadministrator
    mkdir backup1

    2)进入rman:

    rman target /

    3)使用rman备份整个数据库:

    CONFIGURE CONTROLFILE AUTOBACKUP ON;
    run{
    allocate channel d1 type disk;
    sql 'alter system archive log current';
    backup format 'C:UsersAdministratorackup1	estfull_%U' database include current controlfile plus archivelog;
    release channel d1;
    }

    案例八

    8.1、案例说明:在Oracle生产环境中,如果某员工删库跑路,把Oracle数据目录误删,请使用RMAN进行恢复。

    1)模拟把数据文件删除:

    关闭数据库:

    shutdown immediate;

    删除数据文件:

    DEL /S /Q C:appAdministratororadata	est*.*

    2)把数据库启动到nomount状态:

    startup nomount;

    3)进入rman:

    rman target /

    4)恢复控制文件:

     restore controlfile from 'C:UsersAdministratorackup1TESTFULL_04VCQ4PG_1_1';

    5)将数据库启动到mount状态:

    alter database mount;

    6)恢复数据库:

    restore database;
    recover database;
    alter database open resetlogs;

    7)结果验证:

  • 相关阅读:
    使用 Spring data redis 结合 Spring cache 缓存数据配置
    Spring Web Flow 笔记
    Linux 定时实行一次任务命令
    css js 优化工具
    arch Failed to load module "intel"
    go 冒泡排序
    go (break goto continue)
    VirtualBox,Kernel driver not installed (rc=-1908)
    go运算符
    go iota
  • 原文地址:https://www.cnblogs.com/atomy/p/13821395.html
Copyright © 2011-2022 走看看