#!/usr/bin/env bash # Declare the name of the folder which will be used as a marker when backup proccess started TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S") # Declare the directory where the temporary back files will be stored BACKUP_DIR="/backup/$TIMESTAMP/mysql" # State the username for your MySQL / MariaDB instace that can access the neccessary databases MYSQL_USER="" # Point this script to mysql executable file MYSQL=/usr/bin/mysql # State the password to the username above # Be aware that using plain password is unsecure MYSQL_PASSWORD="" # Point this script to mysqldump executable file MYSQLDUMP=/usr/bin/mysqldump # Declare the name of the remote that will be used as a remote storage REMOTE="" # Create the temporary backup directory in case it doesn't exist mkdir -p "$BACKUP_DIR" # Get the list of all databases in your local MySQL / MariaDB instance databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` # Start a cycle for db in $databases; do # Echo the starting notice echo -e "===\nStarted working with the $db." # Use mysqldump to create and actual backup of your database $MYSQLDUMP --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db > "$BACKUP_DIR/$db.sql" # Use rclone to upload files to the remote backup server rclone copy $BACKUP_DIR $REMOTE:$BACKUP_DIR # Echo the result echo -e "===\nFinished backup process for $db. Check your remote folder or watch for errors." done