Skip to content

ストレージシステム

SirrChat は、ローカルファイルシステムからクラウドオブジェクトストレージまで、複数のストレージバックエンドをサポートする柔軟なストレージオプションを提供します。

ストレージタイプ

ローカルストレージ

最もシンプルなストレージ方法で、単一サーバーデプロイに適しています。

toml
[storage]
type = "local"
local_path = "/var/mail"

S3 互換ストレージ

AWS S3 およびすべての S3 互換オブジェクトストレージをサポート。

toml
[storage]
type = "s3"

[storage.s3]
endpoint = "s3.amazonaws.com"
region = "us-east-1"
bucket = "sirrchat-storage"
access_key = "YOUR_ACCESS_KEY"
secret_key = "YOUR_SECRET_KEY"

MinIO

オープンソースの S3 互換ストレージ。

toml
[storage.s3]
endpoint = "minio.example.com:9000"
bucket = "sirrchat"
access_key = "minioadmin"
secret_key = "minioadmin"
use_ssl = false

データベースストレージ

PostgreSQL

本番環境に推奨。

toml
[database]
type = "postgres"
dsn = "postgresql://user:password@localhost:5432/sirrchat?sslmode=require"

# 接続プール設定
max_open_conns = 25
max_idle_conns = 5
conn_max_lifetime = "5m"

MySQL/MariaDB

広く使用されているリレーショナルデータベース。

toml
[database]
type = "mysql"
dsn = "user:password@tcp(localhost:3306)/sirrchat?parseTime=true&charset=utf8mb4"

SQLite

開発および小規模デプロイに適しています。

toml
[database]
type = "sqlite"
dsn = "/var/lib/sirrchatd/sirrchat.db"

メールストレージフォーマット

Maildir

標準のメールストレージフォーマット、メールごとに1つのファイル。

/var/mail/user@example.com/
  ├── cur/     # 既読メール
  ├── new/     # 新着メール
  └── tmp/     # 一時ファイル

ファイル命名

1642123456.M123456P12345.hostname,S=1234:2,S
  • タイムスタンプ
  • 一意の ID
  • サイズ
  • フラグ(既読、返信済みなど)

ストレージ最適化

圧縮

古いメールを自動的に圧縮してスペースを節約。

toml
[storage.compression]
enabled = true
algorithm = "gzip"  # gzip, bzip2, zstd
min_age_days = 30   # 30日後に圧縮

重複排除

重複メールを自動的に検出して削除。

toml
[storage.deduplication]
enabled = true
hash_algorithm = "sha256"

階層型ストレージ

アクセス頻度に基づいてデータを自動的に移行。

toml
[storage.tiering]
enabled = true

# ホットストレージ: 頻繁にアクセス
[storage.tiering.hot]
type = "local"
path = "/fast/ssd/mail"
max_age_days = 30

# コールドストレージ: アーカイブ
[storage.tiering.cold]
type = "s3"
bucket = "sirrchat-archive"

クォータ管理

ユーザークォータ

toml
[storage.quota]
default_quota = "1GB"
max_quota = "10GB"
warning_threshold = 90  # 90%で警告

ユーザークォータを設定

bash
sirrchatd quota set --user user@example.com --quota 5GB

クォータ使用状況を表示

bash
sirrchatd quota get --user user@example.com

バックアップとリカバリー

自動バックアップ

toml
[storage.backup]
enabled = true
schedule = "0 2 * * *"  # 毎日午前2時
retention_days = 30

[storage.backup.destination]
type = "s3"
bucket = "sirrchat-backups"

手動バックアップ

bash
# すべてのデータをバックアップ
sirrchatd backup create --output /backups/sirrchat-$(date +%Y%m%d).tar.gz

# 特定のユーザーをバックアップ
sirrchatd backup create --user user@example.com

データを復元

bash
# すべてのデータを復元
sirrchatd backup restore --input /backups/sirrchat-20250115.tar.gz

# 特定のユーザーを復元
sirrchatd backup restore --user user@example.com --input backup.tar.gz

データ移行

他のメールサーバーから移行

Postfix/Dovecot から

bash
sirrchatd migrate --from maildir --source /var/mail/vhosts

Exchange から

bash
sirrchatd migrate --from pst --source /exports/*.pst

ストレージバックエンドの移行

ローカルから S3 へ移行:

bash
sirrchatd storage migrate --from local --to s3

監視とメンテナンス

ストレージ使用統計

bash
sirrchatd storage stats

出力:

合計サイズ: 125.5 GB
ユーザー数: 1,234
ユーザーあたり平均: 104.2 MB
最大ユーザー: user@example.com (5.2 GB)

クリーンアップ操作

期限切れメールを削除

bash
sirrchatd cleanup --older-than 2y

ゴミ箱をクリーン

bash
sirrchatd cleanup --trash --older-than 30d

一時ファイルをクリーン

bash
sirrchatd cleanup --temp

パフォーマンス最適化

キャッシュ設定

toml
[storage.cache]
enabled = true
size_mb = 512
ttl = "1h"

インデックス最適化

toml
[storage.indexing]
enabled = true
full_text_search = true

並行制御

toml
[storage.concurrency]
max_workers = 10
queue_size = 1000

データセキュリティ

暗号化

転送暗号化

toml
[storage.encryption]
# S3 転送暗号化
s3_use_tls = true

保存時の暗号化

toml
[storage.encryption]
enabled = true
algorithm = "AES-256-GCM"
key_file = "/etc/sirrchatd/encryption.key"

アクセス制御

toml
[storage.access]
# アクセスパスを制限
allow_paths = ["/var/mail"]
deny_paths = ["/etc", "/root"]

高可用性

レプリケーション

マスタースレーブレプリケーション

toml
[storage.replication]
mode = "master"
slaves = ["slave1.example.com", "slave2.example.com"]

マルチマスターレプリケーション

toml
[storage.replication]
mode = "multi-master"
peers = ["peer1.example.com", "peer2.example.com"]

フェイルオーバー

toml
[storage.failover]
enabled = true
health_check_interval = "30s"
auto_failover = true

トラブルシューティング

診断ツール

bash
# ストレージ接続を確認
sirrchatd storage test

# データ整合性を検証
sirrchatd storage verify

# 破損したメールボックスを修復
sirrchatd storage repair --user user@example.com

一般的な問題

ディスク容量不足

bash
# 古いメールをクリーン
sirrchatd cleanup --older-than 1y

# メールを圧縮
sirrchatd storage compress

S3 接続が失敗

bash
# S3 接続をテスト
sirrchatd storage test --type s3

# 詳細なエラーを表示
sirrchatd storage test --debug

関連ドキュメント:

Released under the GPL 3.0 License.