createSnapshot static method
Future<void>
createSnapshot(
- Client cloudApiClient, {
- required CommandLogger logger,
- required String projectId,
- String? name,
- Duration? expireIn,
- bool utc = false,
Creates a manual snapshot of the project's database.
When expireIn is provided the snapshot is scheduled for automatic
deletion after that duration, otherwise it is retained indefinitely.
Implementation
static Future<void> createSnapshot(
final Client cloudApiClient, {
required final CommandLogger logger,
required final String projectId,
final String? name,
final Duration? expireIn,
final bool utc = false,
}) async {
final expiresAt = expireIn == null
? null
: DateTime.now().toUtc().add(expireIn);
DatabaseSnapshot? snapshot;
try {
await logger.progress(
'Creating database snapshot for project "$projectId"',
() async {
snapshot = await cloudApiClient.database.createSnapshot(
cloudCapsuleId: projectId,
name: name,
expiresAt: expiresAt,
);
return true;
},
successMessage: 'Snapshot created.',
newParagraph: true,
);
} on Exception catch (e, s) {
throw FailureException.nested(e, s, 'Failed to create snapshot');
}
final created = snapshot;
if (created != null) {
_snapshotsTable([created], utc: utc).writeLines(logger.line);
}
}