• 用户管理的备份与恢复



    用户管理的备份与恢复也称OS物理备份,是指通过数据库命令设置数据库为备份状态, 然后用操作系统命令,拷贝需要备份或恢复的文件。这种备份与恢复需要用户的参与手工或 自动完成。

    一、归档与非归档


    (一)、NONARCHIVELOG 模式


              1.脱机冷备与恢复


             冷备份发生在数据库已经正常关闭的情况下,当正常关闭时会提供给我们一个完整的数 据库。冷备份是将关键性文件拷贝到另外位置的一种说法。对于备份Oracle 信息而言,冷 备份是最快和最安全的方法。

              2.冷备份的优点:

    1.是非常快速的备份方法(只需拷贝文件)
    2.容易归档(简单拷贝即可)
    3.容易恢复到某个时间点上(只需将文件再拷贝回去)
    4.能与归档方法相结合,作数据库“最新状态”的恢复。
    5.低度维护,高度安全。


             3.冷备份的不足:


    1.单独使用时,只能提供到“某一时间点上”的恢复。
    2.在实施备份的全过程中,数据库必须要作备份而不能作其它工作。也就是说,在 冷备份过程中,数据库必须是关闭状态。
    3.若磁盘空间有限,只能拷贝到磁带等其它外部存储设备上,速度会很慢。
    4.不能按表或按用户恢复。

    如果可能的话(主要看效率),应将信息备份到磁盘上,然后启动数据库(使用户可以 工作)并将所备份的信息拷贝到磁带上(拷贝的同时,数据库也可以工作)。冷备份中必须 拷贝的文件包括:
    1.所有数据文件
    2.所有控制文件
    3.所有联机REDO LOG文件
    4.参数化参数Init.ora文件(可选)



    (二)、ARCHIVELOG 模式


               1.脱机冷备与恢复


    同NONARCHIVELOG模式

                 2.联机热备


    联机热备是在数据库运行的情况下进行备份的方法。热备份要求数据库在Archivelog 方式下操作,并需要大量的档案空间。

                 3.热备份的优点:


    1.可在表空间或数据文件级备份,备份时间短。
    2.备份时数据库仍可使用,支持24*7 不间断运行。
    3.可达到秒级恢复(恢复到某一时间点上)。
    4.可对几乎所有数据库实体作恢复。
    5.恢复是快速的,在大多数情况下在数据库仍工作时恢复。

               4.热备份的不足是:

    1.不能出错,否则后果严重。
    2.若热备份不成功,所得结果不可用于时间点的恢复。
    3.因难于维护,所以要特别仔细小心,不允许“以失败而告终”。
    注意:在热备过程中系统会生成更多的重做日志和回滚数据。所以必须在数据库较 空闲时才进行备份





    二、非归档模式


    (一)、丢失控制文件


              1.单个控制文件丢失


    这种情况解决方法很简单,只要把多路复用的控制文件拷贝到相应路径就行了。

               2.所有控制文件丢失


    (1) 重建控制文件(略)
    (2) 使用备份的控制文件进行恢复


    Last login: Sat Aug 3 22:58:59 2013 from 192.168.21.1
    -----登录oracle 用户
    [root@oracle ~]# su - oracle
    -----修改环境变量的实例名
    [oracle@oracle ~]$ export ORACLE_SID=emrep
    -----连接到数据库
    [oracle@oracle ~]$ sqlplus / as sysdba
    SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 3 23:01:58 2013
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    -----备份控制文件(二进制)
    SQL> alter database backup controlfile to
    '/u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl';
    Database altered.
    -----删除正在使用的控制文件(制造故障)
    SQL> ho rm -rf /u01/app/oracle/oradata/emrep/*.ctl
    -----重启数据库
    SQL> startup force;
    ORACLE instance started.
    Total System Global Area 444596224 bytes
    Fixed Size 1219904 bytes
    Variable Size 138412736 bytes
    Database Buffers 301989888 bytes
    Redo Buffers 2973696 bytes
    -----观察错误信息
    ORA-00205: error in identifying control file, check alert log for more info
    -----从备份复原控制文件
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/.
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/control02.ctl
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/control03.ctl
    -----将数据库开到mount 模式
    SQL> alter database mount;
    Database altered.
    -----打开数据库
    SQL> alter database open;
    alter database open
    *
    ERROR at line 1:
    ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
    -----要求以RESETLOGS 或者NORESETLOGS 选项打开数据库
    SQL> alter database open resetlogs;
    alter database open resetlogs
    *
    ERROR at line 1:
    ORA-01194: file 1 needs more recovery to be consistent
    ORA-01110: data file 1: '/u01/app/oracle/oradata/emrep/system01.dbf'
    -----需要进行介质恢复
    SQL> recover database using backup controlfile;
    ORA-00279: change 720303 generated at 08/03/2013 22:55:38 needed for thread 1
    ORA-00289: suggestion :
    /u01/app/oracle/product/10.2.0/db_1/dbs/arch1_11_822517966.dbf
    ORA-00280: change 720303 for thread 1 is in sequence #11
    -----查询可知当前的日志文件组
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    /u01/app/oracle/oradata/emrep/redo01.log
    Log applied.
    Media recovery complete.
    -----以RESETLOGS 的方式启动数据库
    SQL> alter database open resetlogs;
    Database altered.
    -----及时进行全库备份 

           3.修改数据库结构后丢失所有控制文件

    -----备份控制文件
    SQL> alter database backup controlfile to
    '/u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl';
    Database altered.
    -----创建新的表空间(数据文件)
    SQL> create tablespace t1 datafile '/u01/app/oracle/oradata/emrep/t1.dbf' size 10m;
    Tablespace created.
    -----在新的表空间上创建表a
    SQL> create table a(id number) tablespace t1;
    Table created.
    -----删除当前的控制文件
    SQL> ho rm -rf /u01/app/oracle/oradata/emrep/*.ctl
    -----重启数据库
    SQL> startup force;
    ORACLE instance started.
    Total System Global Area 444596224 bytes
    Fixed Size 1219904 bytes
    Variable Size 138412736 bytes
    Database Buffers 301989888 bytes
    Redo Buffers 2973696 bytes
    -----观察错误信息
    ORA-00205: error in identifying control file, check alert log for more info
    -----还原控制文件
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/.
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/control02.ctl
    SQL> ho cp /u01/app/oracle/backup/emrep/ctl/2013-8-4/control01.ctl
    /u01/app/oracle/oradata/emrep/control03.ctl
    -----将数据库置为mount
    SQL> alter database mount;
    Database altered.
    -----要求以RESETLOGS 或者NORESETLOGS 选项打开数据库
    SQL> alter database open;
    alter database open
    *
    ERROR at line 1:
    ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
    
    -----以RESETLOGS 选项打开数据库
    SQL> alter database open resetlogs;
    alter database open resetlogs
    *
    ERROR at line 1:
    ORA-01194: file 1 needs more recovery to be consistent
    ORA-01110: data file 1: '/u01/app/oracle/oradata/emrep/system01.dbf'
    -----使用备份的控制文件进行恢复
    SQL> recover database using backup controlfile;
    ORA-00279: change 720553 generated at 08/03/2013 23:05:27 needed for thread 1
    ORA-00289: suggestion :
    /u01/app/oracle/product/10.2.0/db_1/dbs/arch1_1_822524687.dbf
    ORA-00280: change 720553 for thread 1 is in sequence #1
    -----应用在线日志
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    /u01/app/oracle/oradata/emrep/redo01.log
    ORA-00283: recovery session canceled due to errors
    -----数据文件未命名
    ORA-01244: unnamed datafile(s) added to control file by media recovery
    ORA-01110: data file 5: '/u01/app/oracle/oradata/emrep/t1.dbf'
    ORA-01112: media recovery not started
    -----查询数据文件信息
    SQL> select name from v$datafile;
    NAME
    --------------------------------------------------------------------------------
    /u01/app/oracle/oradata/emrep/system01.dbf
    /u01/app/oracle/oradata/emrep/undotbs01.dbf
    /u01/app/oracle/oradata/emrep/sysaux01.dbf
    /u01/app/oracle/oradata/emrep/users01.dbf
    /u01/app/oracle/product/10.2.0/db_1/dbs/UNNAMED00005
    -----更名数据文件
    SQL> alter database create datafile
    '/u01/app/oracle/product/10.2.0/db_1/dbs/UNNAMED00005' as
    '/u01/app/oracle/oradata/emrep/t1.dbf';
    Database altered.
    -----恢复数据库
    SQL> recover database using backup controlfile;
    ORA-00279: change 721446 generated at 08/03/2013 23:07:44 needed for thread 1
    ORA-00289: suggestion :
    /u01/app/oracle/product/10.2.0/db_1/dbs/arch1_1_822524687.dbf
    ORA-00280: change 721446 for thread 1 is in sequence #1
    
    
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    /u01/app/oracle/oradata/emrep/redo01.log
    Log applied.
    Media recovery complete.
    -----以RESETLOGS 方式打开数据库
    SQL> alter database open resetlogs;
    Database altered.
    SQL> select name from v$datafile;
    NAME
    --------------------------------------------------------------------------------
    /u01/app/oracle/oradata/emrep/system01.dbf
    /u01/app/oracle/oradata/emrep/undotbs01.dbf
    /u01/app/oracle/oradata/emrep/sysaux01.dbf
    /u01/app/oracle/oradata/emrep/users01.dbf
    /u01/app/oracle/oradata/emrep/t1.dbf
    -----检验a 表是否存在
    SQL> select * from a;
    no rows selected
    SQL> desc a;
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    ID NUMBER


                4.修改数据库后脱机或者只读表空间,丢失所有控制文件

    -----trace 备份控制文件
    SQL> alter database backup controlfile to tracer as
    '/u01/app/oracle/backup/emrep/ctl/2013-8-4/ct.sql';
    Database altered.
    -----创建表空间t2(数据文件)
    SQL> create tablespace t2 datafile '/u01/app/oracle/oradata/emrep/t2.dbf' size 10m;
    Tablespace created.
    -----在t2 表空间上创建表b
    SQL> create table b(id number) tablespace t2;
    Table created.
    -----只读表空间
    SQL> alter tablespace t2 read only;
    -----删除当前的控制文件
    SQL> ho rm -rf /u01/app/oracle/oradata/emrep/*.ctl
    
    -----重新启动数据库
    SQL> startup force;
    ORACLE instance started.
    Total System Global Area 444596224 bytes
    Fixed Size 1219904 bytes
    Variable Size 138412736 bytes
    Database Buffers 301989888 bytes
    Redo Buffers 2973696 bytes
    ORA-00205: error in identifying control file, check alert log for more info
    -----重建控制文件(使用备份的控制文件进行恢复也可以)
    SQL> @/u01/app/oracle/backup/emrep/ctl/2013-8-4/c.sql
    Control file created.
    -----打开数据库
    SQL> alter database open;
    Database altered.
    -----查询数据文件信息
    SQL> select name,status from v$datafile;
    NAME STATUS
    ---------------------------------------------------------------------------------------
    /u01/app/oracle/oradata/emrep/system01.dbf SYSTEM
    /u01/app/oracle/oradata/emrep/undotbs01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/sysaux01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/users01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/t1.dbf ONLINE
    /u01/app/oracle/product/10.2.0/db_1/dbs/MISSING00006 OFFLINE
    6 rows selected.
    -----发现有一个数据文件名字不对,重命名
    SQL> alter database rename file
    '/u01/app/oracle/product/10.2.0/db_1/dbs/MISSING00006' to
    '/u01/app/oracle/oradata/emrep/t2.dbf';
    Database altered.
    -----再次查询
    SQL> select name,status from v$datafile;
    NAME STATUS
    ---------------------------------------------------------------------------------------
    /u01/app/oracle/oradata/emrep/system01.dbf SYSTEM
    /u01/app/oracle/oradata/emrep/undotbs01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/sysaux01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/users01.dbf ONLINE
    /u01/app/oracle/oradata/emrep/t1.dbf ONLINE
    /u01/app/oracle/oradata/emrep/t2.dbf OFFLINE
    6 rows selected.
    
    -----将t2 表空间置为online
    SQL> alter tablespace t2 online;
    Tablespace altered.
    -----将t2 表空间置为读写
    SQL> alter tablespace t2 read write;
    Tablespace altered.
    -----验证b 表
    SQL> select * from b;
  • 相关阅读:
    Spring格式化注解
    Mysql 慢查询和慢查询日志分析
    jQuery中的end()方法
    webService学习笔记
    让Hibernate和触发器协同工作
    JavaScript中的setInterval用法
    jQuery中事情的动态绑定
    mongoDB如何处理多对多关系
    新生儿信息管理系统在线帮助
    MySQL数据库安装与配置详解
  • 原文地址:https://www.cnblogs.com/ios9/p/9580017.html
Copyright © 2020-2023  润新知