Skip to content

Database

Ryan Govostes edited this page Apr 23, 2020 · 6 revisions

Sealog's database is a MongoDB.

Database Structure

The default database name is sealogDB, defined in db_constants.js.

Maintenance Notes

Working with Docker

Where are the database files?

The docker-compose.yml defines a named volume called database. Docker Compose prefixes the volume name with the project name (the directory's basename if not specified) to create a Docker volume called, for instance, sealog_alvin_database.

Docker manages volumes for you but if you need to know where the files for that volume are stored on the host filesystem, you can see that in the Mountpoint field in the output of

docker volume inspect sealog_alvin_database
Command output
[
    {
        "CreatedAt": "2020-04-23T20:29:37Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "sealog_alvin",
            "com.docker.compose.version": "1.25.5",
            "com.docker.compose.volume": "database"
        },
        "Mountpoint": "/var/lib/docker/volumes/sealog_alvin_database/_data",
        "Name": "sealog_alvin_database",
        "Options": null,
        "Scope": "local"
    }
]

To change where the volume data is stored on Linux, set the data-root setting in the Docker daemon configuration.

Running commands

Prefix commands with:

docker-compose [additional options] exec mongo ...

This can be understood as "execute the command ... inside the container used by the mongo service defined inside my docker-compose.yml file."

This assumes that Sealog is running (e.g., with docker-compose up -d). Pass the -T option after exec if you are piping data in.

Remember that this command is executed inside Mongo's container, which does not have the host filesystem mapped into it.

Backing up and Restoring

See the Mongo manual.

mongodump --db=sealogDB --archive > alvin.20200423.archive
mongorestore --archive < alvin.20200423.archive

To rename the database while restoring, include the arguments --nsFrom='sealogDB_alvin.*' --nsTo='sealogDB.*'.