8343-New-machine-id #48

Merged
xavi merged 40 commits from 8343-New-machine-id into main 2025-01-10 13:29:15 +00:00
5 changed files with 148 additions and 0 deletions
Showing only changes of commit 3c2302ec39 - Show all commits

View File

@ -0,0 +1,30 @@
#!/bin/bash
# https://mariadb.com/kb/en/mariabackup/
set -e
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$myDir/config.sh"
todayDir="$(date +%Y-%m-%d)"
backupName="${todayDir}_$(date +"%H-%M")_full"
backupFile="$backupDir/$backupName.gz"
if [ -d "$backupDir" ]; then
rm -rf "$backupDir/"*
fi
ulimit -n 8192
mariabackup \
--defaults-extra-file="$myDir/my.cnf" \
--backup \
--extra-lsndir="$backupDir/$backupName" \
--history="$todayDir" \
2>> "$logFile" \
| gzip \
> "$backupFile"
if [ $? != "0" ]; then
echo "An error ocurred during backup, please take a look at log file: $logFile"
exit 1
fi

View File

@ -0,0 +1,20 @@
#!/bin/bash
# Destination file for backup logs
logFile=/var/log/vn-mariabackup.log
# Temporary local directory to save backups
backupDir=/mnt/local-backup
# Directory for backup history
historyDir=/mnt/backup4mariadb
# Number of days for backup rotation
cleanDays=90
# Directory for temporal restore data
restoreDir=/mnt/mysqldata/mysql-restore
# Directory of MySQL data
dataDir=/mnt/mysqldata/mysql

View File

@ -0,0 +1,38 @@
#!/bin/bash
# https://mariadb.com/kb/en/incremental-backup-and-restore-with-mariabackup/
set -e
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$myDir/config.sh"
todayDir="$(date +%Y-%m-%d)"
todayPath="$historyDir/$todayDir"
pattern="$todayPath/${todayDir}_??-??_full.xb.gz.enc"
files=($pattern)
backupFile="${files[0]}"
backupBase=$(basename -- "$backupFile")
backupName="${backupBase%%.*}"
incrementalName="${todayDir}_$(date +"%H-%M")_incremental"
incrementalFile="$backupDir/${incrementalName}.xb.gz.enc"
ulimit -n 24098
mariabackup \
--defaults-extra-file="$myDir/my.cnf" \
--backup \
--incremental-basedir="$backupDir/$backupName" \
--extra-lsndir="$backupDir/$incrementalName" \
--incremental-history-name="$todayDir" \
2>> "$logFile" \
| gzip \
| openssl enc -aes-256-cbc -pbkdf2 -kfile "$myDir/xbcrypt.key" \
> "$incrementalFile"
if [ $? != "0" ]; then
echo "An error ocurred during backup, please take a look at log file: $logFile"
exit 1
fi
cp "$incrementalFile" "$todayPath"
cp -r "$backupDir/$incrementalName" "$todayPath"

View File

@ -0,0 +1,7 @@
[mariabackup]
host = localhost
user = {{ user_mariabackup }}
password = {{ password_user_mariabackup }}
use-memory = 1G
parallel = 2
stream = mbstream

View File

@ -0,0 +1,53 @@
#!/bin/bash
# https://mariadb.com/kb/en/using-encryption-and-compression-tools-with-mariabackup/
set -e
myDir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$myDir/config.sh"
backupFile=$1
if [ -z "$backupFile" ]; then
echo "Backup file not defined."
exit 1
fi
if [ ! -f "$backupFile" ]; then
echo "Backup file does not exist: $backupFile"
exit 2
fi
echo "Restoring MySQL data from backup."
rm -rf "$restoreDir"
mkdir -p "$restoreDir"
echo "Decompresing backup."
gzip --decompress --stdout "$backupFile" \
| mbstream -x --directory="$restoreDir"
echo "Preparing backup."
mariabackup \
--defaults-extra-file="$myDir/my.cnf" \
--prepare \
--target-dir="$restoreDir"
echo "Stopping service."
service mariadb stop
if pgrep mariadbd; then pkill -9 mariadbd; fi
echo "Restoring data."
rm -rf "$dataDir"
mariabackup \
--defaults-extra-file="$myDir/my.cnf" \
--move-back \
--target-dir="$restoreDir" \
2>> "$logFile"
chown -R mysql:mysql "$dataDir"
rm "$dataDir/mysql/slow_log."*
rm "$dataDir/mysql/general_log."*
echo "Removing restore data."
rm -r "$restoreDir"