Restore Manager

This section documents the restore management classes that provide data restoration capabilities.

RestoreManager

class matrixone.restore.RestoreManager(client, executor=None)[source]

Bases: object

Synchronous restore management for MatrixOne snapshots.

This class provides comprehensive restore functionality for recovering data from snapshots at various granularities (cluster, tenant, database, table). It enables disaster recovery, data rollback, and point-in-time data recovery scenarios with full support for cross-tenant restore operations.

Key Features:

  • Multi-level restore: Restore clusters, tenants, databases, or tables

  • Cross-tenant restore: Restore data from one tenant to another

  • Snapshot-based recovery: Restore from any existing snapshot

  • Transaction-aware: Full integration with transaction contexts

  • Executor pattern: Works with both client and session contexts

  • Atomic operations: All restore operations are transactional

  • Disaster recovery: Quick recovery from data loss or corruption

Restore Levels:

  • Cluster: Restore entire cluster state from a cluster-level snapshot

  • Tenant: Restore entire tenant (account) from an account-level snapshot

  • Database: Restore specific database from a database-level snapshot

  • Table: Restore specific table from a table-level snapshot

Executor Pattern:

  • If executor is None, uses self.client.execute (default client-level executor)

  • If executor is provided (e.g., session), uses executor.execute (transaction-aware)

  • This allows the same logic to work in both client and session contexts

  • All operations can participate in transactions when used via session

Usage Examples:

from matrixone import Client

client = Client(host='localhost', port=6001, user='root', password='111', database='test')

# Restore entire cluster from snapshot
success = client.restore.restore_cluster('cluster_backup_snapshot')
if success:
    print("Cluster restored successfully")

# Restore tenant/account from snapshot
client.restore.restore_tenant(
    snapshot_name='daily_backup',
    account_name='production_account'
)

# Restore tenant to a different account (cross-tenant restore)
client.restore.restore_tenant(
    snapshot_name='prod_backup',
    account_name='production',
    to_account='staging'  # Restore prod data to staging account
)

# Restore specific database
client.restore.restore_database(
    snapshot_name='daily_backup',
    account_name='production',
    database_name='analytics'
)

# Restore database to different account
client.restore.restore_database(
    snapshot_name='prod_db_backup',
    account_name='production',
    database_name='orders',
    to_account='test_environment'
)

# Restore specific table
client.restore.restore_table(
    snapshot_name='table_backup',
    account_name='production',
    database_name='orders',
    table_name='customers'
)

# Using within a transaction
with client.session() as session:
    # Restore multiple objects atomically
    session.restore.restore_database('backup1', 'acc1', 'db1')
    session.restore.restore_table('backup2', 'acc1', 'db2', 'table1')
    # Both restore operations commit together

Prerequisites:

  • Snapshots must exist before restore operations can be performed

  • Use SnapshotManager to create snapshots before restoring

  • Appropriate permissions are required for cross-tenant restore operations

See also

  • SnapshotManager: For creating snapshots

  • CloneManager: For cloning from snapshots

  • PitrManager: For point-in-time recovery operations

__init__(client, executor=None)[source]

Initialize restore manager.

Parameters:
  • client – MatrixOne client instance

  • executor – Optional executor (e.g., session) for executing SQL. If None, uses client.execute

restore_cluster(snapshot_name: str) bool[source]

Restore entire cluster from snapshot.

Parameters:

snapshot_name – Name of the snapshot to restore from

Returns:

True if restore was successful

Return type:

bool

Raises:

RestoreError – If restore operation fails

Example:

>>> success = client.restore.restore_cluster("cluster_snapshot_1")
restore_tenant(snapshot_name: str, account_name: str, to_account: str | None = None) bool[source]

Restore tenant from snapshot.

Parameters:
  • snapshot_name – Name of the snapshot to restore from

  • account_name – Name of the account to restore

  • to_account – Optional target account name (for cross-tenant restore)

Returns:

True if restore was successful

Return type:

bool

Raises:

RestoreError – If restore operation fails

Example:

>>> # Restore tenant to itself
>>> success = client.restore.restore_tenant("acc1_snap1", "acc1")
>>>
>>> # Restore tenant to new tenant
>>> success = client.restore.restore_tenant("acc1_snap1", "acc1", "acc2")
restore_database(snapshot_name: str, account_name: str, database_name: str, to_account: str | None = None) bool[source]

Restore database from snapshot.

Parameters:
  • snapshot_name – Name of the snapshot to restore from

  • account_name – Name of the account

  • database_name – Name of the database to restore

  • to_account – Optional target account name (for cross-tenant restore)

Returns:

True if restore was successful

Return type:

bool

Raises:

RestoreError – If restore operation fails

Example:

>>> success = client.restore.restore_database("acc1_db_snap1", "acc1", "db1")
restore_table(snapshot_name: str, account_name: str, database_name: str, table_name: str, to_account: str | None = None) bool[source]

Restore table from snapshot.

Parameters:
  • snapshot_name – Name of the snapshot to restore from

  • account_name – Name of the account

  • database_name – Name of the database

  • table_name – Name of the table to restore

  • to_account – Optional target account name (for cross-tenant restore)

Returns:

True if restore was successful

Return type:

bool

Raises:

RestoreError – If restore operation fails

Example:

>>> success = client.restore.restore_table("acc1_tab_snap1", "acc1", "db1", "t1")