createSnapshot static method

Future<DatabaseSnapshot> createSnapshot(
  1. Client cloudApiClient, {
  2. required String projectId,
  3. String? name,
  4. Duration? expireIn,
})

Creates a manual snapshot of the project's database.

Throws FailureException if the project's plan does not include database backups, or if the request fails.

Implementation

static Future<DatabaseSnapshot> createSnapshot(
  final Client cloudApiClient, {
  required final String projectId,
  final String? name,
  final Duration? expireIn,
}) async {
  final expiresAt = expireIn == null
      ? null
      : DateTime.now().toUtc().add(expireIn);

  try {
    return await cloudApiClient.database.createSnapshot(
      cloudCapsuleId: projectId,
      name: name,
      expiresAt: expiresAt,
    );
  } on ProcurementDeniedException catch (e, s) {
    throw _backupDeniedFailure(e, s, projectId: projectId);
  } on Exception catch (e, s) {
    throw FailureException.nested(e, s, 'Failed to create snapshot');
  }
}