harumaki.net

インフラ屋の覚書や、ラーメン食べある記とか。

AWS infra 運用

[AWS]s3-tools(s3cmd)のインストールと検証

投稿日:2013年6月14日

Last Updated on 2021年7月4日 by かんりにん

EC2上のDB→S3バケットへのダンプファイルの転送にて、s3fs以外のものでも試してみよう、ということで
今日はs3-toolsのテストを。
インスタンスはAmazon Linux AMI、ラージインスタンスで。

1)ダウンロード

# wget http://sourceforge.net/projects/s3tools/files/s3cmd/1.5.0-alpha1/s3cmd-1.5.0-alpha1.tar.gz/download

2)展開、インストール

パッケージでも提供されている様子だが、今回はダウンロードしたアーカイブのうち
以下のファイルを/usr/local/bin以下に移動。

# mv S3 /usr/local/bin
# mv s3cmd /usr/local/bin

3)初期設定

s3cmdにオプション"–configure"をつけて実行。

	# 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 [/usr/bin/gpg]:					←GPGの実行ファイルのパスを指定、デフォルトは/usr/bin/gpg
	 
	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]:						←HTTPS使用の有無を指定、デフォルトは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:							←Proxyサーバーの指定、デフォルトは無し
	 
	New settings:
	  Access Key: ******************
	  Secret Key: ******************
	  Encryption password: ************
	  Path to GPG program: /usr/bin/gpg
	  Use HTTPS protocol: False
	  HTTP Proxy server name:
	  HTTP Proxy server port: 0
	 
	Test access with supplied credentials? [Y/n] Y
	Please wait, attempting to list all buckets...
	Success. Your access key and secret key worked fine :-)
	 
	Now verifying that encryption works...
	Success. Encryption and decryption worked fine :-)
	 
	Save settings? [y/N] y
	Configuration saved to '/root/.s3cfg'
	#

4)追加インストール

実行にはpython-magicが必要だったのでyumでインストール

# yum install python-magic

5)動作テスト

デフォルトではファイルを15MB単位でスプリットして転送する様子(マルチパートアップロード?)。

5-1)ファイルサイズ120MB

# time s3cmd -c /root/.s3cfg put /home/ec2-user/db-sprittest/backup_dbah s3://backup-db1-tokyo/backup_dbah
/home/ec2-user/db-sprittest/backup_dbah -> s3://backup-db1-tokyo/backup_dbah  [part 1 of 8, 15MB]
 15728640 of 15728640   100% in    0s    16.98 MB/s  done
/home/ec2-user/db-sprittest/backup_dbah -> s3://backup-db1-tokyo/backup_dbah  [part 2 of 8, 15MB]
 15728640 of 15728640   100% in    0s    15.09 MB/s  done
 
 
	--- snip ---
 
 
/home/ec2-user/db-sprittest/backup_dbah -> s3://backup-db1-tokyo/backup_dbah  [part 8 of 8, 2MB]
 2689560 of 2689560   100% in    0s     5.41 MB/s  done
	 
	real    0m10.279s
	user    0m1.624s
	sys     0m0.620s
 

→所要時間10秒

ファイル確認

s3fsで/mnt以下にバケットをマウントしているので、直接確認してみる。

# ll /mnt/s3-backup-db1-tokyo/backup_dbah
---------- 1 root root 112790040 Jun 14 06:56 /mnt/s3-backup-db1-tokyo/backup_dbah

なぜかパーミッションがついていないので、後から設定する必要がある。

# ll /mnt/s3-backup-db1-tokyo/backup_dbah
---------- 1 root root 112790040 Jun 14 06:56 /mnt/s3-backup-db1-tokyo/backup_dbah

2)ファイルサイズ750MB

# time s3cmd -c /root/.s3cfg put /home/ec2-user/db-sprittest/backup_dbaa s3://backup-db1-tokyo/backup_dbaa
/home/ec2-user/db-sprittest/backup_dbaa -> s3://backup-db1-tokyo/backup_dbaa  [part 1 of 48, 15MB]
 15728640 of 15728640   100% in    4s     3.06 MB/s  done
/home/ec2-user/db-sprittest/backup_dbaa -> s3://backup-db1-tokyo/backup_dbaa  [part 2 of 48, 15MB]
 15728640 of 15728640   100% in    3s     4.35 MB/s  done
 
 
--- snip ---
  
 
/home/ec2-user/db-sprittest/backup_dbaa -> s3://backup-db1-tokyo/backup_dbaa  [part 47 of 48, 15MB]
 15728640 of 15728640   100% in    4s     3.41 MB/s  done
/home/ec2-user/db-sprittest/backup_dbaa -> s3://backup-db1-tokyo/backup_dbaa  [part 48 of 48, 10MB]
 10753920 of 10753920   100% in    1s     5.99 MB/s  done
	 
	real    1m48.703s
	user    0m9.861s
	sys     0m4.200s
 

→所要時間1分49秒

6)その他

スプリットするファイルサイズの指定

オプション"–multipart-chunk-size-mb=<SIZE>"で指定可能、
最小サイズは5MB、最大サイズは5GBとのこと。

  • s3cmdのヘルプより抜粋
     --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
                 traditional method. SIZE is in Mega-Bytes, default
                 chunk size is noneMB, minimum allowed chunk size is
                 5MB, maximum is 5GB.

そのほかにもオプションが多数あるので、今後いろいろとお試しで。

 
 

 

-AWS, infra, 運用
-,

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


関連記事

[ただのメモ] Amazon_Linux_yumでのupdate不具合を解消

09/01にAmazon LinuxにてGitのアップデートがリリースされたのでyum updateしようとしたら、”No packages marked for update&#8221 …

no image

[パッケージ管理]porgのインストール

テスト環境にpacoを入れておこうと、久々に本家サイトへアクセスしたら "This project is no longer active."とのこと。あらら・・・ つづけて、&q …

no image

net-snmp v3設定

自分用メモです。 v3に対応していないアプライアンスもあるので、使い道は限定されますが・・・ なんとなくOverview snmp v1、v2でのコミュニティによる認証をしていたが、 v3はユーザー認 …

no image

[MySQL] Percona xtrabackupを試す(Ver2.0.8)リストア編

percona xtrabackupを使って作成したバックアップファイルをリストアする方法。 バックアップを取ったらリストアを検証しなくちゃね、ということで早速インスタンスをコピーして試してみることに …

no image

rsync実行時に”Argument list too long.”で叱られた時のメモ、ついでにxargsで渡してみた

アプリサーバーのログファイルが大量に増えたので、 ログ退避用にバックアップ用ホストを用意して転送をしようとしたら rsyncさんから"Argument list too long.&quot …