自宅のPCをUbuntuに換装したので、s3qlを使ってみようと思います。
s3qlはGoogle Cloud StorageやAmazonのS3をローカルドライブとしてマウント出来るというツールです。
ローカルのバックアップとしてなど使えるといいなと言う所で試してみます。
目次
s3qlのインストール
以下の通り、apt-getでインストールする。
https://bitbucket.org/nikratio/s3ql/wiki/installation_ubuntu
必要なのは以下の2つのみ
sudo apt-get install s3ql
以下、実行ログです。
ayatoshi@ayatoshi-UBU:~$ sudo add-apt-repository ppa:nikratio/s3ql
[sudo] password for ayatoshi:
Ubuntu packages of S3QL (http://code.google.com/p/s3ql/). The PPA also contains backported versions of all dependencies for which the version in the Ubuntu archive is too old for use with S3QL.
詳しい情報: https://launchpad.net/~nikratio/+archive/ubuntu/s3ql
[ENTER] を押すと続行します。ctrl-c で追加をキャンセルできます
gpg: 鍵輪「/tmp/tmpa0ycy7gy/secring.gpg」ができました
gpg: 鍵輪「/tmp/tmpa0ycy7gy/pubring.gpg」ができました
gpg: 鍵9958C967をhkpからサーバーkeyserver.ubuntu.comに要求
gpg: /tmp/tmpa0ycy7gy/trustdb.gpg: 信用データベースができました
gpg: 鍵9958C967: 公開鍵“Launchpad S3QL”を読み込みました
gpg: 処理数の合計: 1
gpg: 読込み: 1 (RSA: 1)
OK
ayatoshi@ayatoshi-UBU:~$sudo apt-get install s3ql
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
s3ql
アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 1 個。
513 kB 中 0 B のアーカイブを取得する必要があります。
この操作後に追加で 1,678 kB のディスク容量が消費されます。
以前に未選択のパッケージ s3ql を選択しています。
(データベースを読み込んでいます ... 現在 202495 個のファイルとディレクトリがインストールされています。)
Preparing to unpack .../s3ql_2.10.1+dfsg-3~29~ubuntu14.04.1_amd64.deb ...
Unpacking s3ql (2.10.1+dfsg-3~29~ubuntu14.04.1) ...
Processing triggers for man-db (2.6.7.1-1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 1 added doc-base file...
s3ql (2.10.1+dfsg-3~29~ubuntu14.04.1) を設定しています ...
ドライブとしてマウント
drive-mountというGoogle Cloud Storageを作成してマウントしてみます。
- Google Cloud Storageでバケットを作成
- mkfsでファイルシステムを作成
- マウントする
の3段階です。
1.Google Cloud Storageでバケットを作成
バケットの作成は普通に作成するだけなので省略します。
Developers Consoleのストレージ Cloud Storage プロジェクト ダッシュボード
で旧APIコンソールに移動し。
Interoperable Access からGenerate new key
で作成したAccess Key とSecretをメモしておいてください。
2.mkfs.s3qlでマウント
s3qlのインストールが正常に行われていれば、mkfs.s3qlというコマンドがインストールされています。
以下は基本的にrootで実行です。
root@ayatoshi-UBU:/home/ayatoshi# mkfs.s3ql gs://drive-mount
Enter backend login:
Enter backend passphrase:
Before using S3QL, make sure to read the user's guide, especially
the 'Important Rules to Avoid Loosing Data' section.
Enter encryption password:
..inodes..
..inode_blocks..
..symlink_targets..
..names..
..contents..
..ext_attributes..
Compressing and uploading metadata...
Wrote 153 bytes of compressed metadata.
root@ayatoshi-UBU:/home/ayatoshi#
3.マウントする
事前に適当なマウント用フォルダを作成し、とりあえずchmod 777しておきましょう。
ここでは/mnt/s3qlとしました。
root@ayatoshi-UBU:/mnt# mount.s3ql --allow-other gs://drive-mount /mnt/s3ql
Using 8 upload threads.
Autodetected 4040 file descriptors available for cache entries
Enter backend login:
Enter backend passphrase:
Enter file system encryption passphrase:
Using cached metadata.
Setting cache size to 16033 MB
Mounting filesystem...
マウントが正常に行われると、以下のようにいくつかのファイルがバケット内に作成されます。

ファイルコピーを試してみる
試しに、26ファイル6Gバイトのファイルをコピーしてみます。
ayatoshi@ayatoshi-UBU:/mnt$ time cp -r /tmp/6G26files /mnt/s3ql
real 2m51.452s
user 0m0.108s
sys 0m8.520s
30MB/s?うーん、そもそもうちの回線の速度を超えてないか?意味がわからないです。。
完全に普通にファイルシステムとして使って、問題無いようなイメージの速度感です。
普通にデータフォルダとして使うもよし、バックアップとしてsyncして使うもよし、アーカイブ用途もよし。ネットワーク接続さえ問題ならなければ何でも行けるんじゃ無いでしょうか。
次回はS3との比較や、MySQLのデータフォルダとして使ってみてベンチマークでもとってみたいと思います。
補足
以下にあるように、Multiple MountsはNGなので、ご注意ください。
https://code.google.com/p/s3ql/wiki/other_s3_filesystems
Wiki
https://bitbucket.org/nikratio/s3ql/wiki/Home
ユーザガイド
http://www.rath.org/s3ql-docs/index.html
自動マウントの設定
せっかくなので、initに追加して自動でマウントされるように設定しましょう。
/root/.s3ql/authinfo2
の作成
authinfo2を以下の内容で作成し、chmod 600としてください。
[drive-mount]
storage-url: "gs://drive-mount"
backend-login: "Access Key"
backend-password: "Secret"
fs-passphrase: "適当な文字列でOK"
そうして、以下のような初期化ファイルを作成すると、自動でマウントしてくれます。
以下のようなファイルを作成し、gsmount.conf で/etc/init に配置する。
env で設定している箇所を環境別に修正ください。
description "S3QL Backup File System for Google Cloud Storage"
author "Ayatoshi Yoshidumi "
# This assumes that eth0 provides your internet connection
start on (filesystem and net-device-up IFACE=eth0)
# We can't use "stop on runlevel [016]" because from that point on we
# have only 10 seconds until the system shuts down completely.
stop on starting rc RUNLEVEL=[016]
# Time to wait before sending SIGKILL to the daemon and
# pre-stop script
kill timeout 300
env STORAGE_URL="gs://drive-mount"
env MOUNTPOINT="/mnt/s3ql"
env USER="root"
env AUTHFILE="/root/.s3ql/authinfo2"
expect stop
script
# Redirect stdout and stderr into the system log
DIR=$(mktemp -d)
mkfifo "$DIR/LOG_FIFO"
logger -t s3ql -p local0.info < "$DIR/LOG_FIFO" &
exec > "$DIR/LOG_FIFO"
exec 2>&1
rm -rf "$DIR"
# Check and mount file system
su -s /bin/sh -c 'exec "$0" "$@"' "$USER" -- \
fsck.s3ql --batch --authfile "$AUTHFILE" "$STORAGE_URL"
exec su -s /bin/sh -c 'exec "$0" "$@"' "$USER" -- \
mount.s3ql --upstart --allow-other --authfile "$AUTHFILE" "$STORAGE_URL" "$MOUNTPOINT"
end script
pre-stop script
su -s /bin/sh -c 'exec "$0" "$@"' "$USER" -- umount.s3ql "$MOUNTPOINT"
end script
自動起動の確認
root@ayatoshi-UBU:/etc/init# initctl reload-configuration
root@ayatoshi-UBU:/etc/init# initctl list | grep gs
gsmount stop/waiting
root@ayatoshi-UBU:/etc/init# initctl start gsmount
gsmount start/running, process 3552