環境
本エントリ内で出てくるIPアドレスや各ソフトウェアのバージョンは以下を参考にしてください。
s3cmdバージョン(MacOS版) | 1.0.1 |
---|---|
RiakCSホスト名 | riakcs.example.com |
RiakCSサーバーポート番号 | 8080 |
インストール
brew install s3cmd
s3cmdバージョン表示
$ s3cmd --version s3cmd version 1.0.1 $
設定ファイルの作成
s3cmd --configure
対話形式で設定していきますが、設定値の入力を促される箇所は一旦全部空エンターしてください。
完了後、カレントディレクトリに.s3cfg
が作成されます。
後で手動でこの設定ファイルを修正します。
表示例
$ s3cmd --configure Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3 Access Key: Secret Key: Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: Path to GPG program: When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP and can't be used if you're behind a proxy Use HTTPS protocol [No]: On some networks all internet access must go through a HTTP proxy. Try setting it here if you can't conect to S3 directly HTTP Proxy server name: New settings: Access Key: Secret Key: Encryption password: Path to GPG program: None Use HTTPS protocol: False HTTP Proxy server name: HTTP Proxy server port: 0 Test access with supplied credentials? [Y/n] y Please wait... ERROR: Test failed: 403 (InvalidAccessKeyId): The AWS Access Key Id you provided does not exist in our records. Retry configuration? [Y/n] n Save settings? [y/N] y Configuration saved to '/Users/tsunokawa/.s3cfg' $
設定ファイルの修正
上記で作成した.s3cfg
はデフォルトで以下のようになっています。
[default] access_key = bucket_location = US cloudfront_host = cloudfront.amazonaws.com cloudfront_resource = /2010-07-15/distribution default_mime_type = binary/octet-stream delete_removed = False dry_run = False encoding = UTF-8 encrypt = False follow_symlinks = False force = False get_continue = False gpg_command = None gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s gpg_passphrase = guess_mime_type = True host_base = s3.amazonaws.com host_bucket = %(bucket)s.s3.amazonaws.com human_readable_sizes = False list_md5 = False log_target_prefix = preserve_attrs = True progress_meter = True proxy_host = proxy_port = 0 recursive = False recv_chunk = 4096 reduced_redundancy = False secret_key = send_chunk = 4096 simpledb_host = sdb.amazonaws.com skip_existing = False socket_timeout = 300 urlencoding_mode = normal use_https = False verbosity = WARNING
以下のように修正します。
アクセスキー
access_key =
↓
access_key = RiakCSユーザのアクセスキー
RiakCSホスト名
host_base = s3.amazonaws.com host_bucket = %(bucket)s.s3.amazonaws.com
↓
RiakCS設定ファイル/etc/riak-cs/app.config
内の
cs_root_host
で設定されているホスト名にする必要があります。
設定値が{cs_root_host, "riakcs.example.com"},
であった場合、
host_base = riakcs.example.com host_bucket = %(bucket)s.riakcs.example.com
とします。
Riakサーバーとポート番号
proxy_host = proxy_port = 0
↓
RiakCSサーバーのホスト名、ポート番号に修正してください。
proxy_host = riakcs.example.com proxy_port = 8080
シークレットキー
secret_key =
↓
secret_key = RiakCSユーザのシークレットキー
バケット一覧表示
s3cmd ls
表示例
$ s3cmd ls 2014-10-15 04:59 s3://testbucket02 2014-10-15 04:00 s3://testbucket01 $
バケット一覧表示(再帰的に表示)
s3cmd ls --recursive
表示例
$ s3cmd ls --recursive 2014-10-15 04:59 s3://testbucket02 2014-10-15 04:00 s3://testbucket01 2014-10-15 04:00 s3://testbucket01/test1.txt $
オブジェクト一覧表示
s3cmd la
表示例
$ s3cmd la 2014-10-15 04:01 67321 s3://testbucket01/inu.jpg $
バケット作成
s3cmd mb s3://testbucket02
表示例
$ s3cmd mb s3://testbucket02 Bucket 's3://testbucket02/' created $
バケット削除
s3cmd rb s3://testbucket02
表示例
$ s3cmd rb s3://testbucket02 Bucket 's3://testbucket02/' removed $
オブジェクトをバケットにアップロード(HTTPで見られるようにする)
s3cmd put --acl-public test.txt s3://testbucket02
表示例
$ s3cmd put --acl-public test.txt s3://testbucket02 test.txt -> s3://testbucket02/test.txt [1 of 1] 11 of 11 100% in 0s 205.78 B/s done Public URL of the object is: http://testbucket02.riakcs.example.com/test.txt $
オブジェクトをバケットからダウンロード
s3cmd get s3://testbucket02/test.txt ./
表示例
$ s3cmd get s3://testbucket02/test.txt ./ s3://testbucket02/test.txt -> ./test.txt [1 of 1] 10 of 10 100% in 0s 576.47 B/s done $
オブジェクトをバケットから削除
s3cmd del s3://testbucket02/test.txt
表示例
$ s3cmd del s3://testbucket02/test.txt File s3://testbucket02/test.txt deleted $
バケットのディスク使用量表示
s3cmd du s3://testbucket01
表示例
$ s3cmd du s3://testbucket01 67321 s3://testbucket01/ $
バケットのディスク使用量表示(単位変更)
s3cmd du --human-readable s3://testbucket01
表示例
$ s3cmd du s3://testbucket01 67321 s3://testbucket01/ $
バケットの詳細情報表示
s3cmd info s3://testbucket01
表示例
$ s3cmd info s3://testbucket01 s3://testbucket01/ (bucket): Location: any ACL: test: FULL_CONTROL $
オブジェクトの詳細情報表示
s3cmd info s3://testbucket01/inu.jpg
表示例
$ s3cmd info s3://testbucket01/inu.jpg s3://testbucket01/inu.jpg (object): File size: 67321 Last mod: Wed, 15 Oct 2014 04:01:24 GMT MIME type: image/jpeg MD5 sum: e2c47bea27299941333bbc8tw938v8af ACL: test: FULL_CONTROL ACL: *anon*: READ ACL: *anon*: READ_ACP ACL: *anon*: WRITE_ACP URL: http://testbucket01.riakcs.example.com/inu.jpg $
オブジェクトを別バケットへコピー
s3cmd cp s3://testbucket02/test.txt s3://testbucket01
表示例
$ s3cmd cp s3://testbucket02/test.txt s3://testbucket01 File s3://testbucket02/test.txt copied to s3://testbucket01/test.txt $
バケットまたはオブジェクトのアクセス権変更(HTTPで見られるようにする)
s3cmd setacl --acl-public s3://testbucket02/test.txt
表示例
$ s3cmd setacl --acl-public s3://testbucket02/test.txt s3://testbucket02/test.txt: ACL set to Public [1 of 1] $
バケットまたはオブジェクトのアクセス権変更(HTTPで見られないようにする)
s3cmd setacl -–acl-private s3://testbucket02/test.txt
表示例
$ s3cmd setacl --acl-private s3://testbucket02/test.txt s3://testbucket02/test.txt: ACL set to Private [1 of 1] $