zoukankan      html  css  js  c++  java
  • Hadoop之hive的drop table恢复

    一、引言:

      快下班的时候我开发同事问能不能将hive中drop掉的数据恢复过来,我记得是有开回收站的,当时我回答说可以恢复的。

    二、恢复过程:

      在之前我有对hadoop的回收站有过了解,就是将hdfs dfs -rm删除掉的文件进行恢复,只需要hdfs dfs -mv将文件从回收站中搬过来就行,我就先使用这个方法,但是效果不佳,执行select count(*) from table_name,得到的结果为0。这个时候我想到这个表被drop掉以后在mysql的元数据库中已经没有数据了,那就得需要将这些数据的信息重新写入到mysql中。具体恢复步骤如下:

      1、创建表:

    CREATE TABLE temp_richard(
    op_time string,                             
    province_id string,  
    pay_type string,
    client_type string,
    index_id string,
    index_value  bigint
    
    ) PARTITIONED BY (dayid string) stored as rcfile location '/dw/tmp/temp_richard';

      2、将回收站中的数据cp出来一份:

    hdfs dfs -cp /user/hadoop/.Trash/Current/dw/dm/tmp_richard /tmp/richard/

      3、将临时目录下的数据load到表中:

    load data inpath '/tmp/zhulh/dayid=20160101/000000_0' into table tmp_richard PARTITION (dayid='20160101');

      备注:这里需要将每个分区的数据load到相应的分区表中。

      4、验证数据:

    hive> select count(*) from tmp_richard;

    三、重点说明:

      hive 中使用truncate命令将表截断的话,它是不会进回收站的,是没办法恢复的。这个跟oracle truncate有点类似的。

  • 相关阅读:
    CSS3实现平行四边形
    [Python]图的遍历-DFS
    [Python]图的遍历-BFS
    [Python]图的遍历-拓扑排序
    [Python]哈夫曼编码
    [Python]贪心算法-Prim-和-Kruskal实现-最小生成树
    [Python]贪心算法-Dijkstra-实现
    [python3]稳定匹配算法实现和优化
    从csv文件构建Tensorflow的数据集
    Tensorflow 基础API
  • 原文地址:https://www.cnblogs.com/Richardzhu/p/5315107.html
Copyright © 2011-2022 走看看