热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

大数据备份和恢复应用案例--通过分区表备份和恢复数据

大数据备份和恢复应用案例--通过分区表备份和恢复数据海量数据备份和恢复方案   对于OLAP的数据库的业务特点,是将批量的数据加载入库,然后对这些数据进行分析处理,比如报表或者数据挖掘,最后给业务提供一种决策支持;另外,这类数据库的数据实时性非常高,一旦这些数据处理完毕后,就很少再次使

大数据备份和恢复应用案例--通过分区表备份和恢复数据

海量数据备份和恢复方案

     对于OLAP的数据库的业务特点,是将批量的数据加载入库,然后对这些数据进行分析处理,比如报表或者数据挖掘,最后给业务提供一种决策支持;另外,这类数据库的数据实时性非常高,一旦这些数据处理完毕后,就很少再次使用(有时,也需要对这类数据进行查询)。

 对于OLAP数据库的备份和恢复可以考虑这样几种方案:

1、使用分布式数据库

    将数据分布到多个库里,当数据库恢复时,只需要恢复单个库的数据,大大节省恢复时间。

wKiom1Rr-0eyHB5SAAJmv2cd82o348.jpg


2、结合分区技术,以传输表空间方式进行备份和恢复

1、建立分区表,将分区存储在不同的表空间
[oracle@RH6 ~]$sqlplus '/as sysdba'
SQL*Plus: Release 11.2.0.1.0 Production on Tue Nov 18 17:15:47 2014
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
17:15:47 SYS@ prod >create tablespace tbs1
17:16:03   2  datafile '/dsk1/oradata/prod/tbs1.dbf' size 10m;
Tablespace created.
 
17:17:00 SYS@ prod >create tablespace tbs2
17:17:11   2  datafile '/dsk2/oradata/prod/tbs2.dbf' size 10m;
Tablespace created.
 
17:17:49 SYS@ prod >create tablespace tbs3
17:17:57   2  datafile '/dsk3/oradata/prod/tbs3.dbf' size 10m;
Tablespace created.
 
17:18:35 SYS@ prod >create tablespace tbs1_indx
17:18:49   2  datafile '/dsk1/oradata/prod/tbs1_indx.dbf' size 10m;
Tablespace created.
 
17:19:43 SYS@ prod >create tablespace tbs2_indx
17:19:54   2  datafile '/dsk2/oradata/prod/tbs2_indx.dbf' size 10m;
Tablespace created.
 
17:20:18 SYS@ prod >create tablespace tbs3_indx
17:20:30   2  datafile '/dsk3/oradata/prod/tbs3_indx.dbf' size 10m;
Tablespace created.
 
17:22:12 SYS@ prod >select file_id,file_name,tablespace_name from dba_data_files
   FILE_ID FILE_NAME                                          TABLESPACE_NAME
---------- -------------------------------------------------- ------------------------------
        11 /dsk1/oradata/prod/tbs1.dbf                        TBS1
        12 /dsk2/oradata/prod/tbs2.dbf                        TBS2
        13 /dsk3/oradata/prod/tbs3.dbf                        TBS3
         4 /u01/app/oracle/oradata/prod/users01.dbf           USERS
         3 /u01/app/oracle/oradata/prod/undotbs01.dbf         UNDOTBS1
         2 /u01/app/oracle/oradata/prod/sysaux01.dbf          SYSAUX
         1 /u01/app/oracle/oradata/prod/system01.dbf          SYSTEM
         5 /u01/app/oracle/oradata/prod/example01.dbf         EXAMPLE
         6 /u01/app/oracle/oradata/prod/users02.dbf           USERS
         7 /u01/app/oracle/oradata/prod/catatbs1.dbf          CATATBS
         8 /u01/app/oracle/oradata/prod/perfertbs1.dbf        PERFERTBS
         9 /u01/app/oracle/oradata/prod/oggtbs1.dbf           OGG_TBS
        10 /u01/app/oracle/oradata/prod/test1.dbf             TEST1
        14 /dsk1/oradata/prod/tbs1_indx.dbf                   TBS1_INDX
        15 /dsk2/oradata/prod/tbs2_indx.dbf                   TBS2_INDX
        16 /dsk3/oradata/prod/tbs3_indx.dbf                   TBS3_INDX
 
建立分区表及索引:
17:26:41 SCOTT@ prod >create table t1(id int,name varchar2(1000))
17:26:57   2   partition by range(id)
17:27:01   3  (partition p1 values less than(1000) tablespace tbs1,
17:27:13   4  partition p2 values less than(2000) tablespace tbs2,
17:27:23   5  partition p3 values less than(maxvalue) tablespace tbs3);
Table created.
 
17:30:33 SCOTT@ prod >create index t1_indx on t1(id) local
  2  (
  3  partition p1 tablespace tbs1_indx,
  4  partition p2 tablespace tbs2_indx,
  5* partition p3 tablespace tbs3_indx )
/
 
17:30:37 SCOTT@ prod >select partition_name,tablespace_name from user_segments where segment_name='T1';
PARTITION_NAME                 TABLESPACE_NAME
------------------------------ ------------------------------
P1                             TBS1
P2                             TBS2
P3                             TBS3
 
17:31:33 SCOTT@ prod >select partition_name,tablespace_name from user_segments where segment_name='T1_INDX';
PARTITION_NAME                 TABLESPACE_NAME
------------------------------ ------------------------------
P1                             TBS1_INDX
P2                             TBS2_INDX
P3                             TBS3_INDX
 
插入数据:
17:34:09 SYS@ prod >begin
17:34:26   2  for i in 1..3 loop
17:34:32   3  insert into scott.t1 select object_id*i,object_name from dba_objects where object_id <1000;
17:34:43   4  end loop;
17:34:51   5  commit;
17:34:57   6  end;
17:35:02   7  /
PL/SQL procedure successfully completed.
 
17:32:08 SCOTT@ prod >select count(*) from t1;
  COUNT(*)
----------
      2826
 
17:36:52 SCOTT@ prod >select &#39;p1&#39;,count(*) from t1 partition(p1)
17:37:42   2  union
17:37:47   3  select &#39;p2&#39;,count(*) from t1 partition(p2)
17:38:11   4  union
17:38:13   5  select &#39;p3&#39;,count(*) from t1 partition(p3);
&#39;P1&#39;                               COUNT(*)
-------------------------------- ----------
p1                                     1740
p2                                      774
p3                                      312
 
2、传输表空间
17:35:04 SYS@ prod >alter tablespace tbs1 read only;
Tablespace altered.
 
17:41:02 SYS@ prod >alter tablespace tbs1_indx read only;
Tablespace altered.
 
17:39:14 SYS@ prod >create directory tbs_dir as &#39;/home/oracle/data&#39;;
Directory created.
 
17:40:30 SYS@ prod >grant read,write on directory tbs_dir to scott;
Grant succeeded.
 
[oracle@RH6 data]$ expdp system/oracle directory=tbs_dir dumpfile=p1.dmp transport_tablespaces=tbs1,tbs1_indx logfile=p1.log
Export: Release 11.2.0.1.0 - Production on Tue Nov 18 17:44:25 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/******** directory=tbs_dir dumpfile=p1.dmp transport_tablespaces=tbs1,tbs1_indx logfile=p1.log
ORA-39123: Data Pump transportable tablespace job aborted
ORA-39187: The transportable set is not self-contained, violation list is
ORA-39901: Partitioned table SCOTT.T1 is partially contained in the transportable set.
ORA-39921: Default Partition (Table) Tablespace USERS for T1 not contained in transportable set.
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" stopped due to fatal error at 17:44:49
传输表空间出错,表空间处于非自包含模式:
18:14:47 SYS@ prod >exec dbms_tts.transport_set_check(&#39;TBS1&#39;,true);
PL/SQL procedure successfully completed.
 
18:17:49 SYS@ prod >select * from transport_set_violations;
VIOLATIONS
------------------------------------------------------------------------------------------------------------------------
ORA-39921: Default Partition (Table) Tablespace USERS for T1 not contained in transportable set.
.
ORA-39901: Partitioned table SCOTT.T1 is partially contained in the transportable set.
 
解决方法,需要创建一个临时表和一个临时表索引,将分区和分区索引交换到临时表和临时表索引表空间上,然后到处临时表和临时表索引。由于临时表不是分区表,它们呢所在的表空间符合自包含条件。
17:45:37 SCOTT@ prod >create table t1_tmp as select * from t1 where 1=3;
Table created.
Elapsed: 00:00:00.20
17:45:58 SCOTT@ prod >create index t1_tmp_indx on t1_tmp(id);
Index created.
17:46:33 SCOTT@ prod >select segment_name,tablespace_name from user_segments
17:47:18   2   where segment_name in (&#39;T1_TMP&#39;,&#39;T1_TMP_INDX&#39;);
SEGMENT_NAME                                                                      TABLESPACE_NAME
--------------------------------------------------------------------------------- ------------------------------
T1_TMP                                                                            USERS
T1_TMP_INDX                                                                       USERS
 
将分区表交换到临时表:
17:48:32 SCOTT@ prod >alter table t1 exchange partition p1 with table t1_tmp including indexes;
Table altered.
 
17:49:02 SCOTT@ prod >select segment_name,tablespace_name from user_segments
17:49:35   2   where segment_name in (&#39;T1_TMP&#39;,&#39;T1_TMP_INDX&#39;);
SEGMENT_NAME                                                                      TABLESPACE_NAME
--------------------------------------------------------------------------------- ------------------------------
T1_TMP                                                                                 TBS1
T1_TMP_INDX                                                                       TBS1_INDX
 
17:50:44 SYS@ prod >exec dbms_tts.transport_set_check(&#39;TBS1&#39;,true);
PL/SQL procedure successfully completed.
 
17:51:59 SYS@ prod >select * from transport_set_violations;
no rows selected
已经符合自包含条件
 
[oracle@RH6 data]$ expdp system/oracle directory=tbs_dir dumpfile=p1.dmp transport_tablespaces=tbs1,tbs1_indx logfile=p1.log
Export: Release 11.2.0.1.0 - Production on Tue Nov 18 17:52:55 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/******** directory=tbs_dir dumpfile=p1.dmp transport_tablespaces=tbs1,tbs1_indx logfile=p1.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
  /home/oracle/data/p1.dmp
******************************************************************************
Datafiles required for transportable tablespace TBS1:
  /dsk1/oradata/prod/tbs1.dbf
Datafiles required for transportable tablespace TBS1_INDX:
  /dsk1/oradata/prod/tbs1_indx.dbf
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 17:54:17
表空间导出成功!
17:56:16 SYS@ prod >select file_name,tablespace_name from dba_data_files where tablespace_name in (&#39;TBS1&#39;,&#39;TBS1_INDX&#39;);
FILE_NAME                                          TABLESPACE_NAME
-------------------------------------------------- ------------------------------
/dsk1/oradata/prod/tbs1.dbf                        TBS1
/dsk1/oradata/prod/tbs1_indx.dbf                   TBS1_INDX
 
[oracle@RH6 ~]$ cp /dsk1/oradata/prod/tbs1* /home/oracle/data
[oracle@RH6 ~]$ ls -lh /home/oracle/data
total 21M
-rw-r----- 1 oracle oinstall  92K Nov 18 17:54 p1.dmp
-rw-r--r-- 1 oracle oinstall 1.4K Nov 18 17:54 p1.log
-rw-r----- 1 oracle oinstall  11M Nov 18 17:57 tbs1.dbf
-rw-r----- 1 oracle oinstall  11M Nov 18 17:57 tbs1_indx.dbf
然后再将表空间的数据文件进行备份,由于表空间传输,只是导出了metadata,所以数据量非常小,速度非常快。
 
3、数据恢复
17:58:29 SYS@ prod >drop tablespace tbs1 including contents and datafiles;
Tablespace dropped.
 
17:58:55 SYS@ prod >drop tablespace tbs1_indx  including contents and datafiles;
Tablespace dropped.
 
17:59:12 SYS@ prod >col segment_name for a20
17:59:42 SYS@ prod >col partition_name for a10
17:59:49 SYS@ prod >col tablespace_name for a10
17:59:59 SYS@ prod >select segment_name,partition_name,tablespace_name from dba_segments
18:00:32   2   where segment_name in (&#39;T1&#39;,&#39;T1_INDX&#39;) order by 2;
SEGMENT_NAME         PARTITION_ TABLESPACE
-------------------- ---------- ----------
T1                   P1         USERS
T1_INDX              P1         USERS
T1_INDX              P2         TBS2_INDX
T1                   P2         TBS2
T1_INDX              P3         TBS3_INDX
T1                   P3         TBS3
6 rows selected.
 
拷贝备份数据文件到数据库下,进行数据导入
[oracle@RH6 oradata]$ cp /home/oracle/data/tbs1*.dbf /u01/app/oracle/oradata/prod/
 
[oracle@RH6 data]$ impdp system/oracle directory=tbs_dir dumpfile=p1.dmp transport_datafiles=&#39;/u01/app/oracle/oradata/prod/tbs1.dbf&#39;,&#39;/u01/app/oracle/oradata/prod/tbs1_indx.dbf&#39; logfile=imp.log
 
Import: Release 11.2.0.1.0 - Production on Tue Nov 18 18:06:22 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01":  system/******** directory=tbs_dir dumpfile=p1.dmp transport_datafiles=/u01/app/oracle/oradata/prod/tbs1.dbf,/u01/app/oracle/oradata/prod/tbs1_indx.dbf logfile=imp.log
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/INDEX
Processing object type TRANSPORTABLE_EXPORT/INDEX_STATISTICS
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_01" successfully completed at 18:06:37
 
数据导入成功
18:01:03 SYS@ prod >select segment_name,partition_name,tablespace_name from dba_segments
18:07:37   2  where segment_name in (&#39;T1_TMP&#39;,&#39;T1_TMP_INDX&#39;);
SEGMENT_NAME         PARTITION_ TABLESPACE
-------------------- ---------- ----------
T1_TMP                          TBS1
T1_TMP_INDX                     TBS1_INDX
 
18:09:40 SCOTT@ prod >alter table t1 exchange partition p1 with table t1_tmp including indexes;
Table altered.
 
18:08:15 SYS@ prod >select segment_name,partition_name,tablespace_name from dba_segments
18:10:46   2  where segment_name in (&#39;T1&#39;,&#39;T1_INDX&#39;) order by 2;
SEGMENT_NAME         PARTITION_ TABLESPACE
-------------------- ---------- ----------
T1                   P1         TBS1
T1_INDX              P1         TBS1_INDX
T1_INDX              P2         TBS2_INDX
T1                   P2         TBS2
T1_INDX              P3         TBS3_INDX
T1                   P3         TBS3
6 rows selected.
 
访问正常(索引亦导入成功)
18:12:07 SCOTT@ prod >col name for a50
18:12:19 SCOTT@ prod >r
  1* select * from t1 where id=4
        ID NAME
---------- --------------------------------------------------
         4 C_OBJ#
         4 TAB$
Elapsed: 00:00:00.00
Execution Plan
----------------------------------------------------------
Plan hash value: 1229066337
--------------------------------------------------------------------------------------------------------------
| Id  | Operation                          | Name    | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
--------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                   |         |     2 |  1030 |     1   (0)| 00:00:01 |       |       |
|   1 |  PARTITION RANGE SINGLE            |         |     2 |  1030 |     1   (0)| 00:00:01 |     1 |     1 |
|   2 |   TABLE ACCESS BY LOCAL INDEX ROWID| T1      |     2 |  1030 |     1   (0)| 00:00:01 |     1 |     1 |
|*  3 |    INDEX RANGE SCAN                | T1_INDX |     1 |       |     1   (0)| 00:00:01 |     1 |     1 |
--------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - access("ID"=4)
Note
-----
   - dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
          5  consistent gets
          0  physical reads
          0  redo size
        524  bytes sent via SQL*Net to client
        419  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          2  rows processed
           
18:11:05 SYS@ prod >alter tablespace tbs1 read write;
Tablespace altered.
Elapsed: 00:00:02.10
18:14:34 SYS@ prod >alter tablespace tbs1_indx read write;
Tablespace altered.

三、备份载入的原介质

wKioL1RsASeisT3lAAEZkx474KQ032.jpg


wKiom1RsARmQiCSkAAG2w6nkODw112.jpg  以上文档参考:谭怀远《让Oracle跑的更快2-基于海量数据的数据库设计和优化》,感谢作者!


欢迎大家访问我的个人网站 萌萌的IT人

推荐阅读
  • Hadoop入门与核心组件详解
    本文详细介绍了Hadoop的基础知识及其核心组件,包括HDFS、MapReduce和YARN。通过本文,读者可以全面了解Hadoop的生态系统及应用场景。 ... [详细]
  • 数据库内核开发入门 | 搭建研发环境的初步指南
    本课程将带你从零开始,逐步掌握数据库内核开发的基础知识和实践技能,重点介绍如何搭建OceanBase的开发环境。 ... [详细]
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • 本文探讨了MariaDB在当前数据库市场中的地位和挑战,分析其可能面临的困境,并提出了对未来发展的几点看法。 ... [详细]
  • 探讨如何真正掌握Java EE,包括所需技能、工具和实践经验。资深软件教学总监李刚分享了对毕业生简历中常见问题的看法,并提供了详尽的标准。 ... [详细]
  • 云计算的优势与应用场景
    本文详细探讨了云计算为企业和个人带来的多种优势,包括成本节约、安全性提升、灵活性增强等。同时介绍了云计算的五大核心特点,并结合实际案例进行分析。 ... [详细]
  • Netflix利用Druid实现高效实时数据分析
    本文探讨了全球领先的在线娱乐公司Netflix如何通过采用Apache Druid,实现了高效的数据采集、处理和实时分析,从而显著提升了用户体验和业务决策的准确性。文章详细介绍了Netflix在系统架构、数据摄取、管理和查询方面的实践,并展示了Druid在大规模数据处理中的卓越性能。 ... [详细]
  • 本文深入探讨了MySQL中常见的面试问题,包括事务隔离级别、存储引擎选择、索引结构及优化等关键知识点。通过详细解析,帮助读者在面对BAT等大厂面试时更加从容。 ... [详细]
  • 数据集成策略:ETL与ELT架构对比及工具选择
    随着企业信息化的深入发展,‘数据孤岛’问题日益突出,阻碍了数据的有效利用与整合。本文探讨了如何通过构建数据仓库解决这一问题,重点分析了ETL与ELT两种数据处理架构的特点及适用场景,为企业选择合适的ETL工具提供了指导。 ... [详细]
  • 本文介绍了如何使用 PostgreSQL 的 `UPDATE ... FROM` 语法,通过映射表实现对多行记录进行高效的批量更新。这种方法不仅适用于单列更新,还支持多列的同时更新。 ... [详细]
  • PHP 编程疑难解析与知识点汇总
    本文详细解答了 PHP 编程中的常见问题,并提供了丰富的代码示例和解决方案,帮助开发者更好地理解和应用 PHP 知识。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 深入解析Serverless架构模式
    本文将详细介绍Serverless架构模式的核心概念、工作原理及其优势。通过对比传统架构,探讨Serverless如何简化应用开发与运维流程,并介绍当前主流的Serverless平台。 ... [详细]
  • 从码农到创业者:我的职业转型之路
    在观察了众多同行的职业发展后,我决定分享自己的故事。本文探讨了为什么大多数程序员难以成为架构师,并阐述了我从一家外企离职后投身创业的心路历程。 ... [详细]
author-avatar
mobiledu2502914617
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有