メインコンテンツへスキップ
snapshot は、特定の時点でのアプリケーションまたはデータベースのバックアップです。必要に応じて、アプリケーションやデータベースを以前の状態に復元できます。Square Cloud は自動の日次バックアップとともに、無制限の snapshot を提供します。

アプリケーションの snapshot を作成する

client.snapshotSnapshot オブジェクトを返します。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    snapshot = await client.snapshot(app_id='application_id')
    
    print(snapshot.url)  # Download URL for the snapshot
    print(snapshot.key)  # Snapshot key identifier

snapshot をダウンロードする

Snapshot オブジェクトには、snapshot を zip ファイルとしてダウンロードするメソッドが用意されています。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    snapshot = await client.snapshot(app_id='application_id')
    
    # Download snapshot to current directory
    zip_file = await snapshot.download()
    
    # Download snapshot to specific directory
    zip_file = await snapshot.download(path='./backups')

アプリケーションの snapshot 一覧を取得する

client.all_app_snapshotsSnapshotInfo オブジェクトのリストを返します。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    snapshots = await client.all_app_snapshots(app_id='application_id')
    
    for snapshot in snapshots:
        print(f"Snapshot ID: {snapshot.id}")
        print(f"  Size: {snapshot.size}")
        print(f"  Created at: {snapshot.created_at}")

snapshot を復元する

client.restore_snapshotResponse オブジェクトを返します。アプリケーションとデータベースの両方について snapshot を復元できます。
import squarecloud as square

client = square.Client(api_key='API_KEY')

async def example():
    # Restore an application snapshot
    response = await client.restore_snapshot(
        application_type='app',
        app_id='application_id',
        snapshot_id='snapshot_id',
        version_id='version_id'
    )
    
    print(f"Snapshot restored: {response.status}")
    
    # Restore a database snapshot
    response = await client.restore_snapshot(
        application_type='database',
        app_id='database_id',
        snapshot_id='snapshot_id',
        version_id='version_id'
    )
    
    print(f"Database snapshot restored: {response.status}")

snapshot のデータ構造

Snapshot

Snapshot オブジェクトは、作成された snapshot を表します。
PropertyTypeDescription
urlstrsnapshot のダウンロード URL
keystrsnapshot の一意な識別子

SnapshotInfo

SnapshotInfo オブジェクトは、snapshot のメタデータを表します。
PropertyTypeDescription
idstrsnapshot の一意な識別子
sizestrsnapshot のサイズ
created_atstrsnapshot の作成タイムスタンプ (ISO 8601)

ベストプラクティス

  • 自動バックアップ: Square Cloud は、アプリケーションとデータベースの日次 snapshot を自動的に作成します。
  • 無制限の snapshot: 追加費用なしで、必要な数だけ手動 snapshot を作成できます。
  • 保持期間: snapshot は 30 日間保持されます。
  • 復元時間: 復元処理は、すべてのデータが安定した状態になるまで約 60 秒かかります。
  • テスト: snapshot を復元する前に、まず新しいアプリケーションまたはデータベースを作成して復元処理をテストすることを検討してください。

snapshot の制限

  • プランごとの日次 snapshot 数: 各プランは 1 日あたり (RAM / 256) * 2 個の snapshot を生成できます
    • 例: 2048MB の Hobby プランでは、1 日あたり 16 個の snapshot(月間 480 個)
  • 保持: すべての snapshot は直近 30 日間保持されます
  • 費用: snapshot に追加費用はかかりません