R.A. Epigonos et al.

[wget] --jobs オプションでミラーリング時の並列ダウンロード

ダウンロードスピードを加速させる方法として、分割ダウンロード、マルチプロセス、wgetにはそれ自体に並列ダウンロード機能がついていない。

wgetを実行する前にダウンロードするurlが決まっている場合はxargsやGNU parallelを使ってwgetを複数回呼び出すことで簡単にダウンロードの並列化を行うことができる。

$ cat urllist.txt
http://example.com/s00.jpg
http://example.com/s01.jpg
...
http://example.com/s98.jpg
http://example.com/s99.jpg
$ xargs -a urllist.txt -N 1 -P 10 wget
$ parallel -a urllist.txt -N 1 -P 10 wget {}

これに対して、wgetを実行する前にダウンロードするURLが決まっていない(ミラーリングしたい)場合がある。このときには上のようなwgetを複数回呼び出すトリックが使えない。

$ wget --mirror -- http://example.com

これを解決するためにはwgetの--jobsオプションを使う。以下のようにすることでミラーリングの際に10並列でダウンロードすることが可能になる。--jobsオプションを使うにはwgetの開発リポジトリからparallel-wgetブランチをcheckoutしてコンパイルする必要がある。

$ wget --mirror --jobs 10 -- http://example.com

parallel-wgetブランチを使ったwgetのコンパイルは以下の手順

$ git clone git://git.sv.gnu.org/wget.git
Cloning into 'wget'...
remote: Counting objects: 21170, done.
remote: Compressing objects: 100% (3985/3985), done.
remote: Total 21170 (delta 17137), reused 21142 (delta 17120)
Receiving objects: 100% (21170/21170), 7.92 MiB | 1.66 MiB/s, done.
Resolving deltas: 100% (17137/17137), done.
$ cd wget/
$ git checkout parallel-wget
Branch parallel-wget set up to track remote branch parallel-wget from origin.
Switched to a new branch 'parallel-wget'
$ git branch -a -vv
  master                       43c89ab [origin/master] http: aesthetic change
* parallel-wget                35ab8cd [origin/parallel-wget] Merge remote-tracking branch 'origin/master' into parallel-wget
  remotes/origin/HEAD          -> origin/master
  remotes/origin/master        43c89ab http: aesthetic change
  remotes/origin/parallel-wget 35ab8cd Merge remote-tracking branch 'origin/master' into parallel-wget

リポジトリからコンパイルする方法は README.checkout に書かれているので、その内容に従う。configureに--prefixオプションを与えて既存のwgetよりもpathの優先順位が低い場所にインストールすることにする。コンパイルしたバイナリに--helpオプションを与えて、--jobsオプションが使えるようになっていることを確認。

$ cat -n README.checkout | sed -n "73,90p"
    73     For those who might be confused as to what to do once they check out
    74     the source code, considering configure and Makefile do not yet exist at
    75     that point, a shell script called bootstrap.sh has been provided. After
    76     calling ./bootstrap.sh you're ready to build GNU Wget in the normal
    77     fashion, with ./configure and make.
    78
    79     So, to sum up, after checking out the source code as described above,
    80     you may proceed as follows:
    81      1. Change to the topmost GNU Wget directory:
    82   $  cd wget        # assumes you've cloned a repository to "./wget"
    83      2. Generate all the automatically-generated files required prior to
    84         configuring the package:
    85   $  ./bootstrap.sh
    86      3. Configure the package and compile it:
    87   $  ./configure [some_parameters]
    88   $  make
    89      4. Hack, compile, test, hack, compile, test...
    90   $  src/wget --version
$ ./bootstrap
$ ./configure --prefix=$(echo ~/opt/)
$ make
$ src/wget --version
GNU Wget 1.15.151-35ab built on linux-gnu.

+digest +https +ipv6 +iri +large-file -metalink +nls -ntlm +opie
+ssl/gnutls +threads

Wgetrc:
    /home/****/opt/etc/wgetrc (system)
Locale:
    /home/****/opt/share/locale
Compile:
    gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/home/****/opt/etc/wgetrc"
    -DLOCALEDIR="/home/****/opt/share/locale" -I. -I../lib -I../lib -O2
    -Wall
Link:
    gcc -O2 -Wall -lgnutls -lz -lpthread -lidn -luuid -lpcre -lrt
    ftp-opie.o gnutls.o ../lib/libgnu.a

Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
Please send bug reports and questions to <bug-wget@gnu.org>.
$ src/wget --help | grep jobs
       --jobs                    specify how many threads use.
$ su
Password:
# make install
# exit

また、以下のようにccs.cが無いという理由でmakeに失敗する場合はflexパッケージをインストールして./bootstrapからやり直す。

$ make
cat css.c >> css_.c
cat: css.c: No such file or directory
make[3]: *** [css_.c] Error 1
make[3]: Leaving directory `/home/*******************/wget/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/*******************/wget/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/*******************/wget'
make: *** [all] Error 2

バイナリは~/opt/bin/wgetにある。10並列でミラーリングを実行するには以下のようにする。

$ ~/opt/bin/wget --mirror --jobs 10 -- http://example.com/

一部のサイトでは以下のようにしてミラーリングを行った結果が違う場合がある。自前でコンパイルした1.15.151-35abはjobsの有無にかかわらず再帰処理がうまくできていない様子(ダウンロードリンクを辿る場合と辿らない場合がランダムに生じているように見える)。

$ rm -fr 1.13/; wget --debug --output-file=log.1.13 --directory-prefix=1.13 --mirror --page-requisites -- http://iwparchives.jp/
Setting --output-file (logfile) to log.1.13
Setting --directory-prefix (dirprefix) to 1.13
Setting --mirror (mirror) to 1
Setting --page-requisites (pagerequisites) to 1
$ rm -fr 1.15/; ~/opt/bin/wget --debug --output-file=log.1.15 --directory-prefix=1.15 --mirror --page-requisites -- http://iwparchives.jp/
Setting --output-file (logfile) to log.1.15
Setting --directory-prefix (dirprefix) to 1.15
Setting --mirror (mirror) to 1
Setting --page-requisites (pagerequisites) to 1
$ rm -fr 1.15j/; ~/opt/bin/wget --debug --output-file=log.1.15j --directory-prefix=1.15j --mirror --page-requisites --jobs 10 -- http://iwparchives.jp/
Setting --output-file (logfile) to log.1.15j
Setting --directory-prefix (dirprefix) to 1.15j
Setting --mirror (mirror) to 1
Setting --page-requisites (pagerequisites) to 1
Setting --jobs (jobs) to 10
$ grep Load log.*
$ wget --version
GNU Wget 1.13.4 built on linux-gnu.

+digest +https +ipv6 +iri +large-file +nls -ntlm +opie +ssl/gnutls

Wgetrc:
    /etc/wgetrc (system)
Locale: /usr/share/locale
Compile: gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/etc/wgetrc"
    -DLOCALEDIR="/usr/share/locale" -I. -I../lib -I../lib
    -D_FORTIFY_SOURCE=2 -Iyes/include -g -O2 -fstack-protector
    --param=ssp-buffer-size=4 -Wformat -Werror=format-security
    -DNO_SSLv2 -D_FILE_OFFSET_BITS=64 -g -Wall
Link: gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat
    -Werror=format-security -DNO_SSLv2 -D_FILE_OFFSET_BITS=64 -g -Wall
    -Wl,-z,relro -Lyes/lib -lgnutls -lgcrypt -lgpg-error -lz -lidn -lrt
    ftp-opie.o gnutls.o ../lib/libgnu.a

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
Please send bug reports and questions to <bug-wget@gnu.org>.
$ ~/opt/bin/wget --version
GNU Wget 1.15.151-35ab built on linux-gnu.

+digest +https +ipv6 +iri +large-file -metalink +nls -ntlm +opie
+ssl/gnutls +threads

Wgetrc:
    /home/****/opt/etc/wgetrc (system)
Locale:
    /home/****/opt/share/locale
Compile:
    gcc -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/home/****/opt/etc/wgetrc"
    -DLOCALEDIR="/home/****/opt/share/locale" -I. -I../lib -I../lib -O2
    -Wall
Link:
    gcc -O2 -Wall -lgnutls -lz -lpthread -lidn -luuid -lpcre -lrt
    ftp-opie.o gnutls.o ../lib/libgnu.a

Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Originally written by Hrvoje Niksic <hniksic@xemacs.org>.
Please send bug reports and questions to <bug-wget@gnu.org>.
$ ~/opt/bin/wget --debug --mirror --page-requisites --wait=0.5 --random-wait --directory-prefix=1.15 --jobs 10 -- http://example.com/
$ ~/opt/bin/wget --debug --mirror --page-requisites --follow-tags=a --directory-prefix=1.15 --jobs 10 -- http://example.com/
$ schroot -c testing_amd64_sandbox
$ export LANG=en_US.UTF-8
$ su -
# apt-get install git autoconf automake autopoint flex
# apt-get build-dep wget
# exit
$ git clone git://git.sv.gnu.org/wget.git
$ cd wget/
$ git checkout parallel-wget
$ git branch -a -vv
$ ./bootstrap
$ ./configure --prefix=$(echo ~/opt/) --enable-race-detection
$ ./configure --prefix=$(echo ~/opt/)
$ make
$ src/wget --version

リファレンス

  1. Why am I failing to mirror a web site (using wget)? - Unix & Linux Stack Exchange
  2. wgetが超絶便利なwebクローラー、クローリングツールだとは知らなかった・・・! | girigiribauer.com
  3. GNU Wget - Bugs: bug #36580, trunk doesn't build [Savannah]

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-09-18T15:04:30+09:00
  2. Modified: 2010-09-18T15:04:30+09:00
  3. Generated: 2023-08-27T23:09:11+09:00