Skip to content

Commit fd374e9

Browse files
committed
docs(srv): mongoDB backups using jobs tutorial MTA-6155
1 parent 48c0770 commit fd374e9

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
meta:
3+
title: &title Create snapshots of a Managed MongoDB® database with Serverless Jobs and the Scaleway CLI
4+
description: &description This step-by-step tutorial will help you automate the creation of snapshots of your Instance using Serverless Jobs and the Scaleway CLI
5+
content:
6+
h1: *title
7+
paragraph: *description
8+
tags: serverless jobs instance snapshot backup image disk storage cli
9+
categories:
10+
- mongodb
11+
- jobs
12+
dates:
13+
validation: 2025-06-17
14+
posted: 2025-06-17
15+
---
16+
[Scaleway Serverless Jobs](/serverless-jobs/quickstart/) allows you to create and automate recurring tasks. This tutorial will guide you through the process of creating snapshots of a [Scaleway Managed MongoDB® database](/managed-mongodb-databases/quickstart/) on a recurring schedule using a Serverless Job.
17+
18+
Serverless Jobs are perfectly adapted for these autonomous tasks, as we do not need autoscaling or exposure via a web server. Refer to the [documentation on differences between jobs, containers, and functions](/serverless-jobs/reference-content/difference-jobs-functions-containers/) for more information.
19+
20+
<Macro id="requirements" />
21+
22+
- A Scaleway account logged into the [console](https://console.scaleway.com).
23+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization.
24+
- Created a [Managed MongoDB® database](/managed-mongodb-databases/how-to/create-a-database-instance/).
25+
26+
## Creating the job definition
27+
28+
1. In the [Scaleway console](https://console.scaleway.com), click **Jobs** in the **Serverless** section of the side menu. The jobs page displays.
29+
30+
2. Click **Create job**. The job creation wizard displays.
31+
32+
3. For **Container Image**, select **External**, and in **Image URL**, set: `scaleway/cli:latest`.
33+
34+
4. Enter a name or use the automatically generated one.
35+
36+
5. Select the region in which your job will be created.
37+
38+
6. Keep the default **resources** values, as this job requires little compute capability.
39+
40+
7. Set **cron schedule** to `0 18 * * *` and select the relevant time zone to run the job every evening at 18:00 p.m. Refer to the [cron schedules documentation](/serverless-jobs/reference-content/cron-schedules/) for more information.
41+
42+
8. Define the following environment variables:
43+
- `SCW_ACCESS_KEY`: your API access key.
44+
- `SCW_SECRET_KEY`: your API secret key.
45+
- `SCW_DEFAULT_PROJECT_ID`: your Project ID.
46+
- `SCW_DEFAULT_ORGANIZATION_ID`: your Organization ID.
47+
- `SCW_DEFAULT_REGION`: concerned region.
48+
49+
<Message type="note">
50+
We recommend using Secret Manager to store the `SCW_ACCESS_KEY` and `SCW_SECRET_KEY`.
51+
</Message>
52+
53+
For more details about variables used by `cli`, refer to the [CLI config documentation](https://github.com/scaleway/scaleway-cli/blob/master/docs/commands/config.md).
54+
55+
9. In the **Execution** tab, define the command below, and replace the placeholders with the ID of your Managed MongoDB® Database Instance ID and the name of your snapshot:
56+
```sh
57+
scw mongodb snapshot create <MONGO_INSTANCE_ID> name="snapshot_$(date +%Y%m%d_%H%M%S)" expires-at=30d
58+
```
59+
60+
10. Click **Create job**.
61+
62+
Your job will automatically create a snapshot named `snapshot_<DATE_TIME>` with a 30-day retention period every day at 18:00 p.m.
63+
64+
## Running the job
65+
66+
From the **Overview** tab of the Serverless job you just created, click **Actions**, then select **Run job** from the contextual menu.
67+
68+
The execution appears in the **Job runs** section. You can access the logs of your job by clicking <Icon name="more" /> next to the job run ID, and selecting **See on Cockpit**.
69+
70+
## Possible improvements
71+
72+
This tutorial is a lightweight example of how to create recurring snapshots of a Database Instance. You can go further by:
73+
- Using it to manage all your Database Instances' snapshots
74+
- Setting up an alerting system in case of unexpected behavior
75+
- Explore [scaleway/serverless-examples repository](https://github.com/scaleway/serverless-examples) for advanced automation examples
76+
77+
## Additional resources
78+
79+
- [Serverless Jobs Documentation](/serverless-jobs/how-to/create-job/)
80+
- [Other methods to deploy Jobs](/serverless-jobs/reference-content/deploy-job/)
81+
- [API keys documentation](/iam/how-to/create-api-keys/)
82+
- [CRON schedule reference](/serverless-jobs/reference-content/cron-schedules/)

0 commit comments

Comments
 (0)