borgmatic

MongoDB

πŸ”

New in version 1.5.22 To backup MongoDB with borgmatic, use the mongodb_databases: hook. For example:

mongodb_databases:
    - name: messages

Full configuration

Here's an example configuration with all of the available options for this feature in the most recent version of borgmatic. If you're using an older version, some of these options may not work, and you should instead generate a sample configuration file specific to your borgmatic version.

# List of one or more MongoDB databases to dump before creating a
# backup, run once per configuration file. The database dumps are
# added to your source directories at runtime and streamed directly
# to Borg. Requires mongodump/mongorestore commands. See
# https://docs.mongodb.com/database-tools/mongodump/ and
# https://docs.mongodb.com/database-tools/mongorestore/ for details.
mongodb_databases:
    # Database name (required if using this hook). Or "all" to
    # dump all databases on the host. Note that using this
    # database hook implicitly enables read_special (see
    # above) to support dump and restore streaming.
    - name: users

      # Label to identify the database dump in the backup.
      label: my_backup_label

      # Container name/id to connect to. When specified the
      # hostname is ignored. Requires docker/podman CLI.
      container: debian_stable

      # Container name/id to restore to. Defaults to the
      # "container" option.
      restore_container: restore_container

      # Database hostname to connect to. Defaults to connecting
      # to localhost.
      hostname: database.example.org

      # Database hostname to restore to. Defaults to the
      # "hostname" option.
      restore_hostname: database.example.org

      # Port to connect to. Defaults to 27017.
      port: 27018

      # Port to restore to. Defaults to the "port" option.
      restore_port: 5433

      # Username with which to connect to the database. Skip it
      # if no authentication is needed. Supports the
      # "{credential ...}" syntax.
      username: dbuser

      # Username with which to restore the database. Defaults to
      # the "username" option. Supports the "{credential ...}"
      # syntax.
      restore_username: dbuser

      # Password with which to connect to the database. Skip it
      # if no authentication is needed. Supports the
      # "{credential ...}" syntax.
      password: trustsome1

      # Password with which to connect to the restore database.
      # Defaults to the "password" option. Supports the
      # "{credential ...}" syntax.
      restore_password: trustsome1

      # Authentication database where the specified username
      # exists. If no authentication database is specified, the
      # database provided in "name" is used. If "name" is "all",
      # the "admin" database is used.
      authentication_database: admin

      # Database dump output format. One of "archive", or
      # "directory". Defaults to "archive". See mongodump
      # documentation for details. Note that format is ignored
      # when the database name is "all".
      format: directory

      # Additional mongodump options to pass directly to the
      # dump command, without performing any validation on them.
      # See mongodump documentation for details.
      options: --dumpDbUsersAndRoles

      # Additional mongorestore options to pass directly to the
      # dump command, without performing any validation on them.
      # See mongorestore documentation for details.
      restore_options: --restoreDbUsersAndRoles

      # Command to use instead of "mongodump". This can be used
      # to run a specific mongodump version (e.g., one inside a
      # running container). If you run it from within a
      # container, make sure to mount the path in the
      # "user_runtime_directory" option from the host into the
      # container at the same location.  Defaults to
      # "mongodump".
      mongodump_command: docker exec mongodb_container mongodump

      # Command to run when restoring a database instead of
      # "mongorestore". This can be used to run a specific
      # mongorestore version (e.g., one inside a running
      # container). Defaults to "mongorestore".
      mongorestore_command: docker exec mongodb_container mongorestore

Improve this documentation

Have an idea on how to make this documentation even better? Use our issue tracker to send your feedback!