2015/01/04

さくらのクラウドとBase Storageを繋ぐスタートアップスクリプト



Base Storage使ってますか?
ベータ期間中は無料で利用可能です。
さくらのBASE Storage | ストレージならさくらインターネット


ということで「さくらのクラウド」とBase Storageを繋ぐs3cmdのセットアップできるスタートアップスクリプトを書いてみました。
ちなみに記載内容はさくらのクラウドニュースに書いてありました;-p
「さくらのBASE Storage」ベータテストを開始しました | さくらのクラウドニュース


やってることはs3cmdをインストールしてさくらのBase Storage向けに書き換えたConfigファイルを作成するというものです。



BaseStorageのユーザ名やトークン名をクラウドのコンパネ上から入力することでログインすることなく設定完了です!
利用できるOSはCentOS 6.6のみとなります。


#!/bin/bash

# @sacloud-once

# @sacloud-text required maxlen=100 Username "ユーザ名を入力"
# @sacloud-text required maxlen=100 Token "トークンを入力"

# @sacloud-desc S3cmdをさくらのオブジェクトストレージの設定済みでインストールします。
# @sacloud-desc (このスクリプトは、CentOS6.XもしくはScientific Linux6.Xでのみ動作します)

#---------START OF S3CMD---------#
yum -y install s3cmd || exit 1

cat < /root/.s3cfg
[default]
access_key = @@@Username@@@
access_token =
add_encoding_exts =
add_headers =
bucket_location = US
cache_file =
cloudfront_host = cloudfront.amazonaws.com
default_mime_type = binary/octet-stream
delay_updates = False
delete_after = False
delete_after_fetch = False
delete_removed = False
dry_run = False
enable_multipart = True
encoding = ANSI_X3.4-1968
encrypt = False
expiry_date =
expiry_days =
expiry_prefix =
follow_symlinks = False
force = False
get_continue = False
gpg_command = /usr/bin/gpg
gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passph  rase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passph  rase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
gpg_passphrase =
guess_mime_type = True
host_base = b.storage.sakura.ad.jp
host_bucket = %(bucket)s.b.storage.sakura.ad.jp
human_readable_sizes = False
ignore_failed_copy = False
invalidate_default_index_on_cf = False
invalidate_default_index_root_on_cf = True
invalidate_on_cf = False
list_md5 = False
log_target_prefix =
max_delete = -1
mime_type =
multipart_chunk_size_mb = 15
preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
put_continue = False
recursive = False
recv_chunk = 4096
reduced_redundancy = False
restore_days = 1
secret_key = @@@Token@@@
send_chunk = 4096
server_side_encryption = False
simpledb_host = sdb.amazonaws.com
skip_existing = False
socket_timeout = 300
urlencoding_mode = normal
use_https = False
use_mime_magic = True
verbosity = WARNING
website_endpoint = http://%(bucket)s.s3-website-%(location)s.amazonaws.com/
website_error =
website_index = index.html

EOT
#---------END OF S3CMD---------#

導入方法はさくらのナレッジに書いているので参考にしてみてください。

s3cmdのコマンドと使ってみるとちゃんと使えます。
ホスト名がGhostなのは気にしない;-p

Cronでバックアップのサーバにしたり、最近すっかり定着したFluentdのログサーバにしたりいろいろ使えるのではないかと思います。