Issue
A POST request to the Backups API v2 endpoint that creates a snapshot archive returns 500 Internal Server Error. The request is sent immediately after the snapshot creation request. The snapshot creation request itself succeeds. A deployment pipeline that relies on the archive fails at this step.
The failing endpoint has the following format:
POST /api/v2/apps/<ProjectId>/environments/<EnvironmentId>/snapshots/<SnapshotId>/archives
The following message appears in the backups service logs:
Invalid SnapshotId: <SnapshotId> for envId: <EnvironmentId> received for archive creation
Environment
Applications hosted in Mendix Cloud
Cause
Snapshot creation is an asynchronous job. The request that creates a snapshot returns a snapshot_id before the job finishes. The job starts in the queued state, moves to running, and ends in the completed or failed state. Processing a snapshot can take around thirty seconds.
The Backups API v2 accepts an archive creation request only for a snapshot that has finished processing. When the archive creation request arrives while the snapshot is still in the queued or running state, the backups service rejects the snapshot identifier as invalid and the API returns 500 Internal Server Error.
This behavior occurs in pipelines and scripts that call the archive creation endpoint directly after the snapshot creation endpoint, without checking the snapshot state.
Solution / Workaround
Check the state of the snapshot before the archive creation request. Proceed only when the snapshot state is completed. Add the check to the pipeline or script with the following steps:
Create the snapshot with the Request Creation of a Snapshot endpoint and store the returned
snapshot_id.Call the Request Status of Creation of a Snapshot endpoint with
GET /api/v2/apps/<ProjectId>/environments/<EnvironmentId>/snapshots/<SnapshotId>.Read the
statevalue in the response. Repeat step two at a fixed interval, for example every ten seconds, while the value isqueuedorrunning.Stop the pipeline with an error when the value is
failed.Send the archive creation request
POST/api/v2/apps/<ProjectId>/environments/<EnvironmentId>/snapshots/<SnapshotId>/archives, when the value iscompleted.
Set a maximum wait time in the polling loop to prevent the pipeline from waiting indefinitely.
Internal information related
- 293242, 292955
- BAK-2895
- C01615RD4NN/p1795766998824759
Additional information
Mendix documentation:
0 Comments