February 12, 20233 yr A while backup a user on Reddit gave me this script that I use in User Scripts to backup my mariadb database instances. I tried it today for the first time because I'm about to update my containers, and it's failing. Here is the script: #!/bin/bash # Check if array is started ls /mnt/disk[1-9]* 1>/dev/null 2>/dev/null if [ $? -ne 0 ] then echo "ERROR: Array must be started before using this script" exit fi BACKUP_DIR="/mnt/user/backups/SQL/mariadb" mkdir -p "$BACKUP_DIR" databases=`docker exec mariadb /usr/bin/mysql -rootuser -password -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql)"` for db in $databases; do echo "Backing up $db" mkdir -p "$BACKUP_DIR/$db" FOLDER=$BACKUP_DIR/$db mkdir -p $FOLDER FILENAME=$(date +%Y-%m-%d-%H.%M.%S).sql FILEPATH=$FOLDER/$FILENAME docker exec mariadb /usr/bin/mysqldump -u rootuser --password=****** $db > $FILEPATH tar czf $FILEPATH.tgz -C $FOLDER $FILENAME rm $FILEPATH done find $BACKUP_DIR/ -type f -name '*.tgz' -mtime +7 -exec rm {} \; The only parts he asked me to edit were the password and username parts, other than that, I changed the BACKUP_DIR variable, I gave it a new proper location. Notes, I checked via CLI, in /usr/bin, there is no "mysql" there so.. I don't know why Please guide me!
February 12, 20233 yr Community Expert Solution Is your mariadb container actually called "mariadb"? Theres a "db-backup" app in CA that can do the job more cleanly.
February 12, 20233 yr Author 32 minutes ago, Kilrah said: Is your mariadb container actually called "mariadb"? Theres a "db-backup" app in CA that can do the job more cleanly. db-backup, ok thank you I'll look. Yes my container is called "mariadb"
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.