Create snapshots of a Managed MongoDB® database with Serverless Jobs and the Scaleway CLI
Scaleway Serverless Jobs 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 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 for more information.
Before you start
To complete the actions presented below, you must have:
- A Scaleway account logged into the console.
- Owner status or IAM permissions allowing you to perform actions in the intended Organization.
- Created a Managed MongoDB® database.
Creating the job definition
-
In the Scaleway console, click Jobs in the Serverless section of the side menu. The jobs page displays.
-
Click Create job. The job creation wizard displays.
-
For Container Image, select External, and in Image URL, set:
scaleway/cli:latest
. -
Enter a name or use the automatically generated one.
-
Select the region in which your job will be created.
-
Keep the default resources values, as this job requires little compute capability.
-
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 for more information. -
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.
For more details about variables used by
cli
, refer to the CLI config documentation. -
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:
/scw mongodb snapshot create <MONGO_INSTANCE_ID> name="snapshot_$(date +%Y%m%d_%H%M%S)" expires-at=30d
-
Click Create job.
Your job will automatically create a snapshot named snapshot_<DATE_TIME>
with a 30-day retention period every day at 18:00.
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 more icon 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 for advanced automation examples
Additional resources
- Serverless Jobs Documentation
- Other methods to deploy Jobs
- API keys documentation
- CRON schedule reference
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center