﻿# Back up and recover databases

> [HTML Version](database-backup-and-recovery.html)

**brix365-Backupper** is a utility that allows for backup of BRIX application data.



Backup of BRIX should include:

- PostgreSQL. The database stores the main system data: users, application items, application settings, workspaces, processes, pages, widgets, tasks, events, and other configuration settings.

- MongoDB. This database contains unstructured system settings, chat data, and activity streams.

- S3 Object Storage. The object storage holds uploaded and created files in BRIX of any type and size, such as documents, photographs, audio, and video files.

The utility for database backup and recovery is compatible with the following operating systems: Debian 11, Debian 12, Debian 13, Ubuntu 22.04, Ubuntu 24.04, Ubuntu 26.04, and Oracle Linux 9.

The process of database backup and recovery consists of four steps:

1. [Install brix365-Backupper](#install-elma365-backupper).

2. [Configure brix365-Backupper](#setting-elma365-backupper).

3. [Database backup](#backup-database).

4. [Database recovery](#recovery-database).

You can also use [interactive mode](#interactive-mode) to backup and recover databases. This replaces steps 3 and 4 above.

## Step 1: Install brix365-Backupper

1. Install the packages:

````
sudo apt install -y apt-transport-https ca-certificates curl gpg sudo lsb-release

2. ````
Import the keys:

````
sudo curl -fsSL https://repo.brix365.com/deb/brix365-keyring.gpg | gpg --dearmor > /etc/apt/trusted.gpg.d/brix365-keyring.gpg

3. ````
 Add the BRIX repository:

````
echo "deb \[arch=amd64\] https://repo.brix365.com/deb \$(lsb\_release -cs) stable" | sudo tee /etc/apt/sources.list.d/brix365.list  
sudo apt update

4. ````
Install **brix365-Backupper**:

````
sudo apt install brix365-backupper

````
Installation for Red Hat-like operating systems

1. Add the BRIX repository:

````
cat <<EOF | sudo tee /etc/yum.repos.d/brix365.repo  
\[brix365\_repo\]  
name=brix365 Repository  
baseurl=https://repo.brix365.com/rpm/ol/releases/9.2/x86\_64  
gpgcheck=1  
gpgkey=https://repo.brix365.com/rpm/brix365-keyring.gpg  
EOF

````
  
Please note that an rpm package is available only for Red Hat Enterprise Linux 9.

2. Install **brix365-Backupper**:

````
dnf install brix365-backupper
````

## ````
Step 2: Configure brix365-Backupper

1. Open configuration file \[OBJECT\]:

````
nano /opt/brix365/backupper/etc/config

2. ````
In the opened window, fill out the parameters:

- \[OBJECT\] is the path to the kubeconfig file, used for selecting the Kubernetes cluster and connecting to the Kubernetes API server. If not specified, \[OBJECT\] is used by default.

- \[OBJECT\] is the directory where the backup will be saved. Available options are: 

	- \[OBJECT\] is backup is saved to the local file system at the path specified in  \[OBJECT\].

	- \[OBJECT\] is backup is saved to an S3 storage, using settings specified in parameters \[OBJECT\], \[OBJECT\], \[OBJECT\], \[OBJECT\], \[OBJECT\], \[OBJECT\].

- \[OBJECT\] is the namespace where the BRIX application is installed.

- \[OBJECT\] is the namespace where the built-in databases are installed, set up in the Kubernetes cluster. For more information, see [Prepare embedded databases](embedded-databases-settings.md).

Ensure ports 7000, 7001, 7002 are available for port forwarding to access databases in the Kubernetes cluster. If necessary, ports can be overridden in \[OBJECT\], \[OBJECT\], \[OBJECT\].

- \[OBJECT\] is the period in days for storing backup copies. Copies older than this value will be deleted during the next backup.

- \[OBJECT\] is the directory for storing temporary backups. There should be enough space for one backup. The backup is assembled in this directory before being moved to the storage location specified in  \[OBJECT\].

Example of a configured file

````
  
\# KUBECONFIG parameter —  The path to the kubeconfig file, used for connecting to the Kubernetes cluster.  
KUBECONFIG=""  
\# parameter BACKUP\_DST — The directory where the backup will be saved.   
\# Available options are: s3, filesystem  
\# s3 — The backup will be saved to an S3 storage  
\# filesystem — he backup will be saved to the local file system at the path specified in the BACKUP\_PATH parameter.  
BACKUP\_DST=filesystem  
  
\# The namespace where the BRIX application is installed  
K8S\_NS\_APP=brix365  
\# The namespace where the built-in databases are installed  
K8S\_NS\_DBS=brix365-dbs  
  
\# The period in days for which the backup is stored  
BACKUP\_LIFE=7  
  
\# The directory for storing temporary backup copies  
TMP\_DIR="/opt/brix365/backupper/tmp"  
\# The directory where backup copies will be stored  
BACKUP\_PATH="/opt/brix365/backupper/backup/"  
  
\# Parameters for configuring sonnection to the S3 Storage for the backups to be stored  
\# S3\_BUCKET\_NAME — The name of the bucket where backup copies will be stored. Reserved (unavailable) bucket names have the format (mask) "s3brix365\*"  
\# S3\_HOST — URL of the S3 storage  
\# S3\_PORT — Port for connecting to the S3 storage  
\# S3\_ROOT\_USER — The name of the user with read or write rights to the bucket specified in S3\_BUCKET\_NAME  
\# S3\_ROOT\_PASSWORD — Password for the user S3\_ROOT\_USER  
\# S3\_SSL\_ENABLED — Whether encryption is used when connecting to the external S3 storage (true/false)  
S3\_BUCKET\_NAME=""  
S3\_HOST=""  
S3\_PORT=""  
S3\_ROOT\_USER=""  
S3\_ROOT\_PASSWORD=""  
S3\_SSL\_ENABLED=true  
  
\# Port forwarding parameters for accessing databases in the Kubernetes cluster:  
\# ВLocal ports specified in the following parameters will be forwarded to the Kubernetes cluster:  
\# S3\_SRC\_PORT — Port for connecting to the S3 storage  
\# PG\_SRC\_PORT —  Port for connecting to PostgreSQL  
\# MONGO\_SRC\_PORT —  Port for connecting to MongoDB  
S3\_SRC\_PORT=7000  
PG\_SRC\_PORT=7001  
MONGO\_SRC\_PORT=7002
````

## ````
Step 3: Database backup

You can back up and recover databases using the commands in steps 3 and 4, or use [interactive mode](#interactive-mode).

````
начало внимание

````
When creating a backup copy, the BRIX services are stopped, and the application itself becomes unavailable.

````
конец внимание

````
Perform a backup of the BRIX application databases:

````
brix365-backupper backup <<db-type>>

````
Where \[OBJECT\] is the name of the database for which you want to perform the backup. The possible values for the argument are:

- \[OBJECT\] for MongoDB.

- \[OBJECT\] for PostgreSQL.

- \[OBJECT\] for S3 storage.

- \[OBJECT\] for all databases (MongoDB, PostgreSQL, S3).  
  
To specify two databases, you can combine the `mongo`, `postgres`, and `s3` values by separating them with commas. For example,` postgres,s3` or `mongo,postgres`.

Additional backup command keys

- \[OBJECT\]. This key is used for backing up databases to a local directory. When using this key, the parameters set in the configuration file are adjusted as follows:  \[OBJECT\]=\[OBJECT\] and \[OBJECT\]="path specified in the argument". 

Example of the command:

````
  
brix365-backupper backup <<db-type>> --storage /opt/brix365/backupper/backup/

- ````
\[OBJECT\]. This key allows overriding the path to the **brix365-Backupper** configuration file. The default path is: \[OBJECT\]. 

Example of the command:

````
  
brix365-backupper backup <<db-type>> --config /opt/brix365/backupper/etc/config
````

## ````
Step 4: Database recovery

You can restore databases from the latest or a specific version of the backup.

````
Начало внимание

````
Before restoring data from a backup, clear the databases and S3 storage or use the \[OBJECT\] key.

````
Конец внимание

````
For more details on how to prepare databases for restoration, refer to the following articles: [PostgreSQL](postgresql.md#prepare-to-restore) and [MongoDB](mongodb.md#prepare-to-restore).

### Restoration from the latest backup

Execute the command:

````
brix365-backupper restore <<db-type>>

````
Where \[OBJECT\] is the name of the database for which you need to retrieve the list of backups. The argument values can be:

- \[OBJECT\] for MongoDB.

- \[OBJECT\] for PostgreSQL.

- \[OBJECT\] for S3 storage.

- \[OBJECT\] for all databases (MongoDB, PostgreSQL, S3).  
  
To specify two databases, you can combine the `mongo`, `postgres`, and `s3` values by separating them with commas. For example,` postgres,s3` or `mongo,postgres`.

With this command, you can restore databases to the latest backup found in the storage. 

### Restoration from a specific backup

1. Get the list of backups from the storage:

````
brix365-backupper backup-list <<db-type>>

````
Where \[OBJECT\]  is the name of the database for which you need to retrieve the list of backups. The argument values can be:

- \[OBJECT\] for MongoDB.

- \[OBJECT\] for PostgreSQL.

- \[OBJECT\] for S3 storage.

- \[OBJECT\] for all databases (MongoDB, PostgreSQL, S3).  
  
To specify two databases, you can combine the `mongo`, `postgres`, and `s3` values by separating them with commas. For example,` postgres,s3` or `mongo,postgres`.

Additional keys for the backup-list command

- \[OBJECT\]: searching for database backups in a local directory. 

Example of the command:

````
  
brix365-backupper backup <<db-type>> --storage /opt/brix365/backupper/backup/

- ````
\[OBJECT\]: overriding the path to the **brix365-Backupper** configuration file, the default path is: \[OBJECT\]. 

Example of the command:

````
  
brix365-backupper backup <<db-type>> --config /opt/brix365/backupper/etc/config
````

````
Depending on the backup storage method indicated in the \[OBJECT\] parameter, the backup-list command will return:

- For \[OBJECT\]: names of directories with dumps in S3 storage.

- For \[OBJECT\]: absolute paths to directories with dumps in the file system.

2. Execute database restoration from a specific backup:

````
brix365-backupper restore <<db-type>> --backup-path /path/to/backup

````
The backup for database restoration is taken from the storage specified in the \[OBJECT\] parameter:

- If S3 storage is indicated:

````
brix365-backupper restore <<db-type>> --backup-path brix365\_YYYY.MM.DD-HH.MI.SS

- ````
If a local directory is indicated:

````
brix365-backupper restore <<db-type>> --backup-path /opt/brix365/backupper/backup/brix365\_YYYY.MM.DD-HH.MI.SS/

````
Additional keys for the restore command

- \[OBJECT\]: a flag for automatic database clearing before restoring from a backup. 

Example of the command:

````
  
brix365-backupper restore <<db-type>> --backup-path /path/to/backup --cleanup-databases

- ````
\[OBJECT\]: overriding the path to the **brix365-Backupper** configuration file, the default path is: \[OBJECT\]. 

Example of the command:

````
  
brix365-backupper restore <<db-type>> --backup-path /path/to/backup --config /opt/brix365/backupper/etc/config
````

## ````
Interactive mode

You can use the utility for database backup and recovery in interactive mode instead of steps 3 and 4 above. To do this, run the script with the following command:

brix365-backupper

This will display the available operations:

````
\### Select an option ###  
\> backup  
  restore  
  backup-list  
  backup-manager  
\[ENTER\] - confirm

````
Select a command using the following keys on your keyboard: **Down** and **Up** to navigate the list, **Space** to select, and **Enter** to apply the command. Then follow the instructions in the window.

