LoginSignup
8

More than 5 years have passed since last update.

マルチパートアップロード対応のS3cmdを使ったファイルアップロード

Last updated at Posted at 2014-09-23

問題

通信環境が悪かったため、ファイルサイズが大きいとタイムアウトしてしまう。
また、パッケージでインストールされるs3cmdは、マルチパートアップロードに対応していないため、ファイルサイズが大きいとタイムアウトしてしまう。

$ s3cmd put example.tar.gz s3://yourbacket/

出力結果

  704512 of 9100252     7% in    1s   457.09 kB/s  failed
WARNING: Upload failed: /example.tar.gz ([Errno 104] Connection reset by peer)
WARNING: Retrying on lower speed (throttle=0.00)
WARNING: Waiting 3 sec...

解決

最新版(1.5.0-rc1)を使う

インストール

$ cd /var/tmp/
$ wget http://downloads.sourceforge.net/project/s3tools/s3cmd/1.5.0-rc1/s3cmd-1.5.0-rc1.tar.gz
$ tar xvzf s3cmd-1.5.0-rc1.tar.gz
$ cd s3cmd-1.5.0-rc1
$ python ./setup.py install

ダウンロード元:sourceforge s3cmd

Versionの確認

$ /usr/local/bin/s3cmd --version

出力結果

s3cmd version 1.5.0-rc1

アクセスキー/シークレットキーの設定

$ /usr/local/bin/s3cmd --configure

オプションの確認

$ /usr/local/bin/s3cmd | grep multipart

出力結果

                        multipart upload parts.  Restarts/parts files that
                        put) and there are multiple partial uploads.  Use
                        s3cmd multipart [URI] to see what UploadIds are
                        used multiple times. For instance set 'Expires' or
  --disable-multipart   Disable multipart upload on files bigger than
                        --multipart-chunk-size-mb
  --multipart-chunk-size-mb=SIZE
                        Size of each chunk of a multipart upload. Files bigger
                        than SIZE are automatically uploaded as multithreaded-
                        multipart, smaller files are uploaded using the
  show multipart uploads
      s3cmd multipart s3://BUCKET [Id]
  abort a multipart upload
  list parts of a multipart upload

アップロード

multipart-chunk-size-mbで分割ファイルサイズを選択する。単位はメガバイト
5MB以上に設定する必要がある。5MBに指定したら成功した。デフォルトは15MB。

$ /usr/local/bin/s3cmd --multipart-chunk-size-mb=5 put <your file> <your s3path>

トラブルシュート

./s3cmd ls
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ImportError trying to import dateutil.parser.
Please install the python dateutil module:
$ sudo apt-get install python-dateutil
  or
$ sudo yum install python-dateutil
  or
$ pip install python-dateutil
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Traceback (most recent call last):
  File "./s3cmd", line 2530, in <module>
    except (ParameterError, InvalidFileError), e:
NameError: name 'ParameterError' is not defined

解決

python-dateutilをインストールする

for ubuntu

$ sudo apt-get install python-dateutil

for centos

$ sudo yum install python-dateutil

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8