Backup all databases on a plesk server
This is not the fastest not the safest and not the most eficient, but it does work. and unless you have a realy bussy database this is a pretty oke way to backup your database. It uses mysqldump and the internal plesk credentials so no need to type passwords at all.
It can ofcourse be used on any other mysql server as long as you set the right credentials.
#! /bin/bash
# aapjeisbaas.nl
# 2016-08-12
TIMESTAMP=$(date +"%F")
BACKUP_DIR="/tmp/db-dump/$TIMESTAMP"
MYSQL_USER="admin"
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD="$(cat /etc/psa/.psa.shadow)"
MYSQLDUMP=/usr/bin/mysqldump
mkdir -p "$BACKUP_DIR"
databases=$($MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)")
for db in $databases; do
$MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db.sql.gz"
done
Put this in a file: vim backup-db.sh
make it executable: chmod +x backup-db.sh
and run it ./backup-db.sh
This will take some time, in some cases 15 minutes or even more.
It will backup to: /tmp/db-dump/$TIMESTAMP