Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

POLICY-3000 - Getting issue details... STATUS


Recover from corruption of policy database. [Possibly a bug in mariadb: MDEV-23119]

High Level Design

A Kubernetes cron will run a docker container once every 24 hours.

The docker container will call a shell script to do the backup.

The backups will be stored remotely.

Dockerfile

Dockerfile
FROM mariadb:latest

RUN apk update
COPY db_backup.sh .

ENTRYPOINT [ "/bin/sh" ]
CMD [ "./db_backup.sh" ]

Shell script

db_backup.sh
#!/bin/sh

FILENAME=$(basename $0 .sh)_$(date +%F-%T)
ARCHIVE=${FILENAME}.tar.gz
LOG=${FILENAME}.log
LOG_DIR=/c/mariadb/logs
BACKUP_WORKDIR=/c/mariadb/backup
BACKUP_ARCHIVEDIR=/c/mariadb/backup_archives
MARIADB_BACKUP_EXE_DIR="/C/Program Files/MariaDB 10.5/bin"
USER=p#####
PWD=******
OK_MSG="completed OK!"

# if the backup directory doesn't exist, create it
if [ ! -d $BACKUP_WORKDIR ]; then
        mkdir -p $BACKUP_WORKDIR
fi

# if the archive directory doesn't exist, create it
if [ ! -d $BACKUP_ARCHIVEDIR ]; then
        mkdir -p $BACKUP_ARCHIVEDIR
fi

# if the log directory doesn't exist, create it
if [ ! -d $LOG_DIR ]; then
        mkdir -p $LOG_DIR
fi

echo "Backup Started"
echo "Backing up to $BACKUP_WORKDIR"

# check if directory is empty, if not delete it's contents
if [ "$(ls -A $BACKUP_WORKDIR)" ]; then
     rm -rf $BACKUP_WORKDIR/*
fi

# redirect output to log file
{
"$MARIADB_BACKUP_EXE_DIR"/mariabackup --backup --target-dir=$BACKUP_WORKDIR --user=$USER --password=$PWD
} >$LOG_DIR/$LOG 2>&1
echo >&2 "Backup Complete"

# create a tar archive from the backup directory
tar cvzf $BACKUP_ARCHIVEDIR/$ARCHIVE $BACKUP_WORKDIR >/dev/null 2>/dev/null

# remove he backup directory
rm -rf $BACKUP_WORKDIR >/dev/null 2>/dev/null

# check the log for the "completed OK!" message
grep -q "$OK_MSG" $LOG_DIR/$LOG
if [ $? -eq 0 ]; then
        exit 0
else
        exit 1
fi

Backing Up and Restoring Databases

mariabackup is an open source tool for doing back ups on MariaDB.

Incremental Backup and Restore with Mariabackup

Back up databases using Kubernetes CronJobs

Replication as a Backup Solution

Notes

  • No labels