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'
            }
        }
    }
  • 相关阅读:
    vue之父子组件间通信实例讲解(props、$ref、$emit)
    jsp的内置对象
    一道关于类加载顺序的面试题
    web.xml中的load-on-startup
    静态代理、JDK动态代理和CGLib动态代理之前的区别
    有关于tomcat启动时,利用listener来执行某个方法
    有关于注解
    java 代码块,静态代码块,构造器等的执行顺序
    java容器的理解(collection)
    PHP常用的缓存技术汇总
  • 原文地址:https://www.cnblogs.com/cuishuai/p/7834260.html
Copyright © 2011-2022 走看看