Datenbanken#
MariaDB#
Execute these commands in the shell of the MariaDB Container.
Logging into the database:
Show all databases:
Show permiissions for user:
Create database:
Create user with password:
Create user without password, but only allowed from specific networks:
Delete user:
Backup#
The backup for MariaDB in this setup is handled using mariadb-backup
and restic
. mariadb-backup creates a physical backup and restic stores the file in a repository, providing compression and deduplication.
mariadb-backup --host mariadb.databases.svc.cluster.local --user=root --password=$MARIADB_ROOT_PASSWORD --backup --target-dir=/backup --stream=xbstream > /backup/mariadb.xb
Restore Process#
The restoration of backups involves retrieving backup snapshots from restic, deserializing, and preparing for database usage.
- List Backups: Get available backups stored in the restic repository
- Restore Snapshot: Extract the latest snapshot to a target directory
- Unserialize the Backup: Use
mbstream
to deserialize the backup file
- Prepare the Recovery: Prepare the backup for use. If possible, use the same mariadb-backup version with which the backup was created
More information about the process in the following fosdem presentation: mariabackup restic
Kubernetes CronJob for Automated Backups#
A Kubernetes CronJob is used to automate the MariaDB backups. At first it creates the backup with mariadb-backup and then stores it in a restic repository. To ensure that the processes run sequential and not parallel, the backup creation runs as init container and afterwards restic as normal container. For best compatibility the mariadb-backup command must be the same version as the MariaDB server. So the init Container of the cronjob executes the mariadb-backup binary within the mariadb container. This way I always get the correct mariadb-backup version.
Explanation:
-
Service Account and Role: A service account
mariadb-backup-serviceaccount
is used, bound with a rolemariadb-backup-role
that has necessary permissions to get the pod name and exec into the container -
CronJob Configuration: The CronJob is set to run every hour, except 2 o'clock in the night
"0 0-1,3-23 * * *"
-
Backup Initialization:
mariadb-backup
runs as aninitContainer
to ensure backups are taken before any other process begins -
Restic:
restic
stores the backup in a restic repository which is accessible via an s3 bucket -
Storage: A
PersistentVolumeClaim
(longhorn-pvc-mariadb-backupvolume
) is used to store the current backup temporarily
The backup strategy is designed to ensure that mariadb-backup
uses a version compatible with the running MariaDB server by executing it within the MariaDB container.
Redis#
Database | Application |
---|---|
1 | authelia |
2 | paperless |
Get all keys from a database: