zoukankan      html  css  js  c++  java
  • Hdfs数据备份

    Hdfs数据备份

    一、概述

    本文的hdfs数据备份是在两个集群之间进行的,如果使用snapshot在同一个集群上做备份,如果datanode损坏或误操作清空了数据,这样的备份就无法完全保证数据安全性。所以选择将hdfs里面的数据备份到另外的地方进行存储,选择hadoop的分布式复制工具distcp。将集群的数据备份到一个制作备份使用的集群,不要怕浪费资源,因为只是做备份使用,所以配置不要求太高,并且可以只是用一个节点接收数据。平常的话此服务器可以跑其他的任务,只有在备份的时间周期内才会有备份任务。至于备份任务的周期可以自己根据实际情况以及可以接受丢失数据时间来确定备份计划任务,我这里采用的是每天备份一次,尽量选择线上的hadoop集群任务不繁忙的时候进行。因为我们的数据量不是很大,需要备份的数据目录也不是很多,所以就选择为每天备份一次。

     

    二、备份之前首先要了解distcp的工作原理以及考虑同步数据的速度以及磁盘io、网络带宽等。

    1、distcp介绍

    http://hadoop.apache.org/docs/r1.2.1/distcp.html

    以下摘自官网:

    DistCp (distributed copy) is a tool used for large inter/intra-cluster copying. It uses MapReduce to effect its distribution, error handling and recovery, and reporting. It expands a list of files and directories into input to map tasks, each of which will copy a partition of the files specified in the source list. Its MapReduce pedigree has endowed it with some quirks in both its semantics and execution. The purpose of this document is to offer guidance for common tasks and to elucidate its model.

       

    2、使用方法

    1)相同版本

    #hadoop  distcp  -p  -skipcrccheck  -update –m 10

      hdfs://spark:9000/data/metastore/userlogs

      hdfs://backup:9000/data/userlogs

    参数解释:

    -p:带权限复制

    -skipcrccheck: 跳过hdfs检查

    -update: 比较两边文件的大小,如果不一样就更新,相同就不操作。如果不是追加数据,而是修改的数据,并且数据大小没有变,那就要结合-overwrite-delete来使用

     

    2)如果版本不相同,则可以使用只读的HftpFileSystem,需要在目标集群上执行:

    #hadoop  distcp  -p  -skipcrccheck  -update –m 10

      hftp://spark:50090/data/metastore/userlogs

      hdfs://backup:9000/data/userlogs

     hftp的端口是在hdfs-site.xml:

     <property>

          <name>dfs.namenode.http-address</name>

          <value>spark:50090</value>

        </property>

    OPTIONS:

    -p[rbugp]              Preserve status

    r: replication number

    b: block size

    u: user

    g: group

    p: permission

    -p alone is equivalent to -prbugp

    -i                     Ignore failures

    -log <logdir>          Write logs to <logdir>

    -m <num_maps>          Maximum number of simultaneous copies

    -overwrite             Overwrite destination

    -update                Overwrite if src size different from dst size

    -f <urilist_uri>       Use list at <urilist_uri> as src list

    -filelimit <n>         Limit the total number of files to be <= n

    -sizelimit <n>         Limit the total size to be <= n bytes

    -delete                Delete the files existing in the dst but not in src

     

    3、计划任务

    脚本:

    #!/bin/bash
    # copy spark:/data/metastore/userlogs to docker:/data/userlogs
    /data/hadoop-2.7.3/bin/hadoop distcp -skipcrccheck -update -m 10 hdfs://spark:9000/data/metastore/userlogs hdfs://backup:9000/data/userlogs

    #-m 是指启动10个map任务执行,每个map任务默认256m,如果设定为10,则每个map是总数据量/10
    #使用update是因为历史数据没有修改,如果修改则可以加上overwrite.

    使用jenkins的pipline执行计划任务

    pipeline {
        agent {label 'spark' }
        stages {
            stage('userlogs') {
                steps {
                    dir('/data/scripts'){
                      sh 'sh userlogs.sh'
                      
                    }
                }
            }
        }
        post {
            failure {
                    emailext subject: '$DEFAULT_SUBJECT',
                            body: '$DEFAULT_CONTENT',
                            recipientProviders: [
                                [$class: 'CulpritsRecipientProvider'],
                                [$class: 'DevelopersRecipientProvider'],
                                [$class: 'RequesterRecipientProvider']
                            ], 
                            replyTo: '$DEFAULT_REPLYTO',
                            to: '93048029849203@qq.com'
            }
        }
    }
  • 相关阅读:
    第七章习题G题
    第二周习题O题
    P4735 最大异或和
    P3008 [USACO11JAN]道路和飞机Roads and Planes
    P4009 汽车加油行驶问题
    P1073 最优贸易
    P2260 [清华集训2012]模积和
    P2865 [USACO06NOV]路障Roadblocks
    P1821 [USACO07FEB]银牛派对Silver Cow Party
    P4180 【模板】严格次小生成树[BJWC2010]
  • 原文地址:https://www.cnblogs.com/cuishuai/p/7834260.html
Copyright © 2011-2022 走看看