39 lines
1.0 KiB
Bash
39 lines
1.0 KiB
Bash
#!/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"
|