# Define mongodb\_backup volume

## Overview

Helmut4 features a dedicated Docker container named 'mongobackup,' designed to generate a comprehensive backup of the configuration, i.e., the database. This backup process is scheduled using a cron timer.

A predefined number of backups, such as 60, will be retained. When the container attempts to create the 61st backup, it will automatically remove the oldest backup to maintain the specified limit.

In the event of a fatal error, the Helmut4 configuration can be restored promptly within a few minutes.

{% hint style="warning" %}
It's advisable to choose a backup path directed towards a network share rather than the local host. This precaution is important because, in the event of a host crash, relying solely on local backups could lead to data loss.

Additionally, we suggest saving the backups to a folder with appropriate access rights. This ensures that the backups are safeguarded from accidental deletion by unauthorized users.
{% endhint %}

## Host backup folder

Please create a new folder titled 'backup' on your designated target destination.

It's crucial to verify that the host possesses adequate read and write permissions for optimal functionality.

* Example folder path: */mnt/demo-h4/backup*

## Docker backup folder

Navigate Portainer, which runs on port 9000 and log in:

{% hint style="info" %}
**Portainer web GUI**\
<http://ip-helmutserver:9000>
{% endhint %}

Further informations about Portainer / login navigate to [Portainer / Helmut4-Docker configuration](https://docs.helmut.de/helmut4-releases/v4.8.1/installation-guide/helmut4-server/helmut4-single-server#portainer-helmut4-docker-configuration)

### Map volume into container

General informations about this task can be found here: [Mount network shares into Docker](https://docs.helmut.de/helmut4-releases/v4.8.1/installation-guide/helmut4-server/helmut4-single-server#mount-network-shares-into-docker)

To add a volume to the 'mongobackup' container, follow these steps:

* click on “primary”
* click on “stacks”
* click on “helmut4”
* click on the tab “Editor"

Locate the following service 'mongobackup' and adjust the volume entry accordingly:

* Example folder path: */mnt/demo-h4/backup*

<pre class="language-yaml"><code class="lang-yaml">  #Example configuration
  mongobackup:
    image: repo.moovit24.de:443/mcc_mongodb_backup:4.1.0.4
    restart: always
    networks:
      - mcc
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - <a data-footnote-ref href="#user-content-fn-1">/mnt/demo-h4/backup:/backup</a>
    depends_on:
      - mongodb
    environment:
      MONGODB_HOST: mongodb
      MONGODB_PORT: 27017
      MONGODB_USER: #hidden
      MONGODB_PASS: #hidden
      CRON_TIME: "<a data-footnote-ref href="#user-content-fn-2">0 */4 * * *</a>"
      MAX_BACKUPS:  <a data-footnote-ref href="#user-content-fn-3">180</a>
      INIT_BACKUP: "true"
</code></pre>

{% hint style="danger" %}
It's crucial to note that the **target** should be **explicitly defined** as **/backup** on the right side, *rather than /Volumes/demo-h4/backup*.&#x20;

Not following this guideline could lead to issues with the automated backup process.
{% endhint %}

## Define backup intervall and amout

### Schedule backup via cron

To familiarize yourself with cron, please head to [crontab.guru](https://crontab.guru/), which provides a user-friendly GUI for setting up a cron.

Defining a cron time is a straightforward task. For instance, if a [Houskeeeper cron job](https://docs.helmut.de/helmut4-releases/v4.8.1/helmut4-components/helmuthk/cron) is intended to run every Saturday at 4:30, the corresponding cron expression would be: `30 4 * * SAT`.

The visual reference below describes the [parameters of this string](https://crontab.guru/#30_4_*_*_SAT).

<figure><img src="https://content.gitbook.com/content/SQcKMi1ekwU1M8tCIPPd/blobs/xU21IusNESNzkxJKcisf/image.png" alt=""><figcaption><p>Example cron time from crontab.guru</p></figcaption></figure>

If we consider to take this cron, the 'mongobackup' configuration would look like this:

```yaml
  #Example configuration
  mongobackup:
    image: repo.moovit24.de:443/mcc_mongodb_backup:4.1.0.4
    ......
    environment:
      MONGODB_HOST: mongodb
      MONGODB_PORT: 27017
      MONGODB_USER: #hidden
      MONGODB_PASS: #hidden
      CRON_TIME: "30 4 * * SAT"
      MAX_BACKUPS:  180
      INIT_BACKUP: "true"
```

### Maximum amount of backups

The number of backups can be configured using the key for the value "MAX\_BACKUPS."&#x20;

Setting this to 180 means that this specific quantity of backups will be retained. Subsequent backup processes will generate a new backup (number 181) and, upon completion, delete the oldest backup instance, ensuring that the total count remains at 180.

### Time span and backup size

Please keep in mind that the number of backups and their intervals will directly impact your retention period.

The size of backups will gradually increase over time, as they are associated with the number of projects, assets, and jobs in your database.

#### Example 1

* Size of one backup: 500mb
* Max Backups: 180
* Cron: every hour

180 (backups) / 24 (hours a day) = **7,5 days**

180 (backups) \* 500mb / 1000 (mb to gb) = **90GB**

#### Example 2

* Size of one backup: 500mb
* Max Backups: 180
* Cron: every 4 hours

180 (backups) / 6 (one sixth of a day) = **30 days**

180 (backups) \* 500mb / 1000 (mb to gb) = **90GB**

#### Example 3

* Size of one backup: 500mb
* Max Backups: 90
* Cron: every 4 hours

90 (backups) / 6 (one sixth of a day) = **15 days**

90 (backups) \* 500mb / 1000 (mb to gb) = **45GB**

{% hint style="info" %}
Every time mongobackup is restarted, it will generate a new (unscheduled) backup.
{% endhint %}

[^1]: Left side: host\
    Riggt side: docker

[^2]: Defined cron time

[^3]: Max amount of backups
