From fd374e967695b82b4fd62dc6ca16b2bfa4f01167 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Tue, 17 Jun 2025 13:40:57 +0200 Subject: [PATCH 1/3] docs(srv): mongoDB backups using jobs tutorial MTA-6155 --- tutorials/backup-mongodb-jobs/index.mdx | 82 +++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tutorials/backup-mongodb-jobs/index.mdx diff --git a/tutorials/backup-mongodb-jobs/index.mdx b/tutorials/backup-mongodb-jobs/index.mdx new file mode 100644 index 0000000000..7d910aad65 --- /dev/null +++ b/tutorials/backup-mongodb-jobs/index.mdx @@ -0,0 +1,82 @@ +--- +meta: + title: &title Create snapshots of a Managed MongoDB® database with Serverless Jobs and the Scaleway CLI + 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 +content: + h1: *title + paragraph: *description +tags: serverless jobs instance snapshot backup image disk storage cli +categories: + - mongodb + - jobs +dates: + validation: 2025-06-17 + posted: 2025-06-17 +--- +[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. + +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. + + + +- A Scaleway account logged into the [console](https://console.scaleway.com). +- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization. +- Created a [Managed MongoDB® database](/managed-mongodb-databases/how-to/create-a-database-instance/). + +## Creating the job definition + +1. In the [Scaleway console](https://console.scaleway.com), click **Jobs** in the **Serverless** section of the side menu. The jobs page displays. + +2. Click **Create job**. The job creation wizard displays. + +3. For **Container Image**, select **External**, and in **Image URL**, set: `scaleway/cli:latest`. + +4. Enter a name or use the automatically generated one. + +5. Select the region in which your job will be created. + +6. Keep the default **resources** values, as this job requires little compute capability. + +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. + +8. Define the following environment variables: + - `SCW_ACCESS_KEY`: your API access key. + - `SCW_SECRET_KEY`: your API secret key. + - `SCW_DEFAULT_PROJECT_ID`: your Project ID. + - `SCW_DEFAULT_ORGANIZATION_ID`: your Organization ID. + - `SCW_DEFAULT_REGION`: concerned region. + + + We recommend using Secret Manager to store the `SCW_ACCESS_KEY` and `SCW_SECRET_KEY`. + + + 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). + +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: + ```sh + scw mongodb snapshot create name="snapshot_$(date +%Y%m%d_%H%M%S)" expires-at=30d + ``` + +10. Click **Create job**. + +Your job will automatically create a snapshot named `snapshot_` with a 30-day retention period every day at 18:00 p.m. + +## Running the job + +From the **Overview** tab of the Serverless job you just created, click **Actions**, then select **Run job** from the contextual menu. + +The execution appears in the **Job runs** section. You can access the logs of your job by clicking next to the job run ID, and selecting **See on Cockpit**. + +## Possible improvements + +This tutorial is a lightweight example of how to create recurring snapshots of a Database Instance. You can go further by: +- Using it to manage all your Database Instances' snapshots +- Setting up an alerting system in case of unexpected behavior +- Explore [scaleway/serverless-examples repository](https://github.com/scaleway/serverless-examples) for advanced automation examples + +## Additional resources + +- [Serverless Jobs Documentation](/serverless-jobs/how-to/create-job/) +- [Other methods to deploy Jobs](/serverless-jobs/reference-content/deploy-job/) +- [API keys documentation](/iam/how-to/create-api-keys/) +- [CRON schedule reference](/serverless-jobs/reference-content/cron-schedules/) From 790988919c6e3b96f467211243e2e9916d3c2741 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Wed, 18 Jun 2025 15:24:50 +0200 Subject: [PATCH 2/3] Update tutorials/backup-mongodb-jobs/index.mdx Co-authored-by: Thomas TACQUET --- tutorials/backup-mongodb-jobs/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/backup-mongodb-jobs/index.mdx b/tutorials/backup-mongodb-jobs/index.mdx index 7d910aad65..f23449b65d 100644 --- a/tutorials/backup-mongodb-jobs/index.mdx +++ b/tutorials/backup-mongodb-jobs/index.mdx @@ -1,7 +1,7 @@ --- meta: title: &title Create snapshots of a Managed MongoDB® database with Serverless Jobs and the Scaleway CLI - 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 + description: &description This step-by-step tutorial will help you automate the creation of snapshots of your MongoDB using Serverless Jobs and the Scaleway CLI content: h1: *title paragraph: *description From 22d6305cd3d8981b2ffa0941b72f175546d9a526 Mon Sep 17 00:00:00 2001 From: SamyOubouaziz Date: Mon, 30 Jun 2025 17:00:07 +0200 Subject: [PATCH 3/3] Update tutorials/backup-mongodb-jobs/index.mdx --- tutorials/backup-mongodb-jobs/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/backup-mongodb-jobs/index.mdx b/tutorials/backup-mongodb-jobs/index.mdx index f23449b65d..719ab28170 100644 --- a/tutorials/backup-mongodb-jobs/index.mdx +++ b/tutorials/backup-mongodb-jobs/index.mdx @@ -59,7 +59,7 @@ Serverless Jobs are perfectly adapted for these autonomous tasks, as we do not n 10. Click **Create job**. -Your job will automatically create a snapshot named `snapshot_` with a 30-day retention period every day at 18:00 p.m. +Your job will automatically create a snapshot named `snapshot_` with a 30-day retention period every day at 18:00. ## Running the job