天天看點

HADOOP資料複制工具Distcp和cp比較

HADOOP資料複制工具Distcp和cp比較

1、工具描述

DistCp(分布式拷貝)是用于大規模叢集内部和叢集之間拷貝的工具。它使用Map/Reduce

實作檔案分發,錯誤處理和恢複,以及報告生成。 它把檔案和目錄的清單作為map任務的輸入,每個任務會完成源清單中部分檔案的拷貝。 由于使用了Map/Reduce方法,這個工具在語義和執行上都會有特殊的地方。

Cp是一個hadoop 檔案系統shell指令,用來複制源檔案或目錄到目的目錄。

2、共同點

都可以複制HDFS系統的檔案或目錄到目的目錄。

3、差別

cp指令是單程序,distcp是多程序,使用mapReduce進行分布式複制。

4、性能測試對比

資料量 cp執行時間 cp複制速率 Distcp執行時間 Distcp複制速率
1G
10G
100G

5、附錄

cp詳細用法

[[email protected] hadoop]$hadoop dfs -help cp

hadoop dfs -cp [-f] [-p | -p[topax]]<src> ... <dst> :

Copy files that match the file pattern<src> to a destination.  Whencopying

 multiple files, the destination must be a directory.

Passing -p preserves status[topax](timestamps, ownership, permission, ACLs, XAttr). If -p is specified  with no <arg>, then preserves timestamps,ownership, permission. If -pa is specified, then preserves permission also because ACL is a super-setof  permission.

Passing -f overwrites the destinationif it already exists. raw  namespaceextended attributes are preserved if (1) they are supported (HDFS  only) and, (2) all of the source and targetpathnames are in the /.reserved/raw hierarchy. raw namespace xattr preservation is determined solely by thepresence  (or absence) of the/.reserved/raw prefix and not by the -p option.

選項說明

辨別 描述 備注
-f 選項将覆寫目标 覆寫目标,如果它已經存在。
-p 選項将保留檔案屬性(時間戳、所有權、許可、ACL、XAttr)。 如果P是無參數指定,然後儲存時間戳,所有權,許可。如果指定PA,則保留權限,因為ACL是超級權限集。
<src> 源檔案或目錄 可以指定多個源檔案或目錄
<dst> 目的目錄 最後一個參數是目的目錄

distcp詳細用法

[[email protected] hadoop]$ hadoop distcp

usage: distcp OPTIONS [source_path...] <target_path>

   OPTIONS

 -append                Reuse existing data in targetfiles and append new

                        data to them ifpossible

 -async                 Should distcp execution beblocking

 -atomic                Commit all changes or none

 -bandwidth<arg>       Specify bandwidth permap in MB

 -delete                Delete from target, filesmissing in source

 -diff <arg>            Use snapshot diff report toidentify the

                        difference between sourceand target

 -f <arg>               List of files that need to becopied

 -filelimit<arg>       (Deprecated!) Limitnumber of files copied to <= n

 -i                     Ignore failures duringcopy

 -log <arg>             Folder on DFS where distcp executionlogs are

                        saved

 -m <arg>               Max number of concurrent maps touse for copy

 -mapredSslConf<arg>   Configuration for sslconfig file, to use with

                        hftps://

 -overwrite             Choose to overwrite target filesunconditionally,

                        even if they exist.

 -p <arg>               preserve status(rbugpcaxt)(replication,

                        block-size, user,group, permission,

                        checksum-type, ACL, XATTR,timestamps). If -p is

                        specified with no<arg>, then preserves

                        replication, blocksize, user, group, permission,

                        checksum type andtimestamps. raw.* xattrs are

                        preserved when both thesource and destination

                        paths are in the/.reserved/raw hierarchy (HDFS

                        only). raw.*xattrpreservation is independent of

                        the -p flag. Refer tothe DistCp documentation for

                        more details.

 -sizelimit<arg>       (Deprecated!) Limitnumber of files copied to <= n

                        bytes

 -skipcrccheck          Whether to skip CRC checks betweensource and

                       target paths.

 -strategy<arg>        Copy strategy to use.Default is dividing work

                        based on file sizes

 -tmp <arg>             Intermediate work path to be usedfor atomic

                        commit

 -update                Update target, copying onlymissingfiles or

                        directories

選項說明

辨別 描述 備注
-p[rbugp]

Preserve

  r: replication number

  b: block size

  u: user

  g: group

  p: permission

修改次數不會被保留。并且當指定 -update 時,更新的狀态不會 被同步,除非檔案大小不同(比如檔案被重新建立)。
-i 忽略失敗 就像在 附錄中提到的,這個選項會比預設情況提供關于拷貝的更精确的統計, 同時它還将保留失敗拷貝操作的日志,這些日志資訊可以用于調試。最後,如果一個map失敗了,但并沒完成所有分塊任務的嘗試,這不會導緻整個作業的失敗。
-log <logdir> 記錄日志到 <logdir> DistCp為每個檔案的每次嘗試拷貝操作都記錄日志,并把日志作為map的輸出。 如果一個map失敗了,當重新執行時這個日志不會被保留。
-m <num_maps> 同時拷貝的最大數目 指定了拷貝資料時map的數目。請注意并不是map數越多吞吐量越大。
-overwrite 覆寫目标 如果一個map失敗并且沒有使用-i選項,不僅僅那些拷貝失敗的檔案,這個分塊任務中的所有檔案都會被重新拷貝。 就像下面提到的,它會改變生成目标路徑的語義,是以 使用者要小心使用這個選項。
-update 如果源和目标的大小不一樣則進行覆寫 像之前提到的,這不是"同步"操作。 執行覆寫的唯一标準是源檔案和目标檔案大小是否相同;如果不同,則源檔案替換目标檔案。 像 下面提到的,它也改變生成目标路徑的語義, 使用者使用要小心。
-f <urilist_uri> 使用<urilist_uri> 作為源檔案清單 這等價于把所有檔案名列在指令行中。 urilist_uri 清單應該是完整合法的URI。