Starter Guide Charmed MongoDB Snap

A Snap is a packaging format distributed as a single file (squashfs), similar to a dmg on OSX. Snaps run in a security-confined environment and gain only the necessary access they need through a mechanism known as ‘plugs’ and ‘slots’, which allow the specification of fine-grained permissions over the host system on a per-application basis.

Contrary to traditional packaging formats, such as debs, where maintainer scripts run depending on specific actions but can do anything they want with their root privileges, snapsrun on hooks that are also confined.

Having a MongoDB snap can be beneficial for multiple reasons.

First, the Charmed MongoDB Snap package is an enhanced, source-available, fully-compatible, drop-in replacement of the packaged software - MongoDB 5.0.13 Community version. In addition, the Charmed MongoDB snap package offers more features than the MongoDB Community version, such as backup and restore, monitoring and security features.

Second, Charmed MongoDB provides a simple installation for any snap-enabled Linux system.

Third, various channels can be used for the different states of the development workflow, for example:

  • PRs can be published for every proposal to a branch like latest/edge/pr-<###>. This feature enables easier QA and collaboration throughout the development process.
  • Each merge to the main can be built, uploaded and released to the edge automatically.
  • Each tagged revision can be built, uploaded and released to the candidate.

This provides a quick way to test and keep track of the latest changes in the product. In addition, the Charmed MongoDB snap would appear on the Ubuntu Software centres

Lastly, the Charmed MongoDB snap package bundles MongoDB with other tools in its ecosystem to be used in a Charmed Operator. One of the operators that use this snap package is the Charmed MongoDB (VM Operator).

snapststore

Get started

To get started install the snap with: sudo snap install charmed-mongodb --channel=edge

To start the mongod service with Percona Server for MongoDB you can run the snap start command: sudo snap start charmed-mongodb.mongod

You can view the logs associated with mongod by entering: sudo snap logs charmed-mongodb.mongod

To access your now running MongoDB instance enter the command: charmed-mongodb.mongo

Here you can run commands such as creating databases, users, adding config options, etc. When you are ready to return to the terminal enter: exit.

Backup and restore

Percona Backup for MongoDB (pbm) is packaged within the snap. To use it you can follow these instructions.

Percona Backup for MongoDB has a set of pre-requisites, to function properly. These can be found here: https://docs.percona.com/percona-backup-mongodb/initial-setup.html

It is up to you to add the pbm user to your MongoDB database. But we will explain how to configure the uri and the configurations.

The URI can only be configured via snap set with: sudo snap set charmed-mongodb pbm-uri="<uri here>"

Snaps are strictly confined by nature, meaning that they cannot access directories outside of the predefined snap dirs. Hence the config file is configured to a readonly file system. Instead of editing the config file directly use config set to change configurations: charmed-mongodb.pbm config --set key.subkey="value"

Similarly, if you plan to store your backup to the local filesystem (not AWS, Azure, etc), you will have to set the filesystem to this exact directory (otherwise the snap will not have access to write the associated backup): charmed-mongodb.pbm config --set storage.filesystem.path="/var/snap/percona-backup-mongodb/x1/pbm-agent-dir/data/local_backups"

Starting pbm-agent: The pbm-agent is a daemon that performs the backup and restore operations. You can start the pbm-agent and view its logs as follows: sudo snap start charmed-mongodb.pbm-agent sudo snap logs charmed-mongodb.pbm-agent

You can stop the agent by using the stop command: sudo snap stop charmed-mongodb.pbm-agent

Backups and more: Once you’ve configured everything appropriately and started the agent you may now perform backups and restores. Performing a backup can be done with: charmed-mongodb.pbm backup

Check out the rest of the supported operations with: charmed-mongodb.pbm --help

And much more

The snap also packages other useful tools like mongodb-exporter, mongodump, mongorestore, and many other tools. You can read more about the tools packaged in the snap by entering charmed-mongodb.<tool name> --help