copySnapshot method
Copies a manual snapshot of an instance or disk as another manual snapshot, or copies an automatic snapshot of an instance or disk as a manual snapshot. This operation can also be used to copy a manual or automatic snapshot of an instance or a disk from one Amazon Web Services Region to another in Amazon Lightsail.
When copying a manual snapshot, be sure to define the source
region, source snapshot name, and target
snapshot name parameters.
When copying an automatic snapshot, be sure to define the
source region, source resource name,
target snapshot name, and either the restore
date or the use latest restorable auto snapshot
parameters.
May throw AccessDeniedException.
May throw AccountSetupInProgressException.
May throw InvalidInputException.
May throw NotFoundException.
May throw OperationFailureException.
May throw RegionSetupInProgressException.
May throw ServiceException.
May throw UnauthenticatedException.
Parameter sourceRegion :
The Amazon Web Services Region where the source manual or automatic
snapshot is located.
Parameter targetSnapshotName :
The name of the new manual snapshot to be created as a copy.
Parameter restoreDate :
The date of the source automatic snapshot to copy. Use the get auto
snapshots operation to identify the dates of the available
automatic snapshots.
Constraints:
-
Must be specified in
YYYY-MM-DDformat. -
This parameter cannot be defined together with the
use latest restorable auto snapshotparameter. Therestore dateanduse latest restorable auto snapshotparameters are mutually exclusive. - Define this parameter only when copying an automatic snapshot as a manual snapshot. For more information, see the Amazon Lightsail Developer Guide.
Parameter sourceResourceName :
The name of the source instance or disk from which the source automatic
snapshot was created.
Constraint:
- Define this parameter only when copying an automatic snapshot as a manual snapshot. For more information, see the Amazon Lightsail Developer Guide.
Parameter sourceSnapshotName :
The name of the source manual snapshot to copy.
Constraint:
- Define this parameter only when copying a manual snapshot as another manual snapshot.
Parameter useLatestRestorableAutoSnapshot :
A Boolean value to indicate whether to use the latest available automatic
snapshot of the specified source instance or disk.
Constraints:
-
This parameter cannot be defined together with the
restore dateparameter. Theuse latest restorable auto snapshotandrestore dateparameters are mutually exclusive. - Define this parameter only when copying an automatic snapshot as a manual snapshot. For more information, see the Amazon Lightsail Developer Guide.
Implementation
Future<CopySnapshotResult> copySnapshot({
required RegionName sourceRegion,
required String targetSnapshotName,
String? restoreDate,
String? sourceResourceName,
String? sourceSnapshotName,
bool? useLatestRestorableAutoSnapshot,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'Lightsail_20161128.CopySnapshot'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'sourceRegion': sourceRegion.value,
'targetSnapshotName': targetSnapshotName,
if (restoreDate != null) 'restoreDate': restoreDate,
if (sourceResourceName != null)
'sourceResourceName': sourceResourceName,
if (sourceSnapshotName != null)
'sourceSnapshotName': sourceSnapshotName,
if (useLatestRestorableAutoSnapshot != null)
'useLatestRestorableAutoSnapshot': useLatestRestorableAutoSnapshot,
},
);
return CopySnapshotResult.fromJson(jsonResponse.body);
}