Last active
September 5, 2023 17:22
-
-
Save Kline-/859cc351bf251598a8902146af12278c to your computer and use it in GitHub Desktop.
Backup MariaDB data running in a Docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BASE=`date -I`-mariabackup | |
CONT=mariadb | |
DEST=/home/matt/_gdrive/mariabackup/ | |
MAGE=365 | |
OWNER=matt:matt | |
TGZ=$DEST$BASE.tgz | |
# check if the container is running | |
if [ "$( docker container inspect -f '{{.State.Running}}' $CONT )" == "true" ]; then | |
docker exec $CONT mariabackup --backup --target-dir=/var/lib/mysql/$BASE --user=root | |
cd $DEST | |
tar -c -C /var/lib/mysql/$BASE/ . | gzip --rsyncable > $TGZ | |
chown $OWNER $TGZ | |
rm -rf /var/lib/mysql/$BASE | |
#cleanup older than max age | |
if [ "$(find $DEST -mtime +$MAGE | wc -l)" -ge 1 ]; then | |
echo "Cleaning up backups older than $MAGE days..." | |
find $DEST -mtime +$MAGE -delete -print | |
fi | |
else | |
echo "$CONT is not running. Exiting." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment