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
# 2016-08-12
TIMESTAMP=$(date +"%F")
MYSQL_PASSWORD="$(cat /etc/psa/.psa.shadow)"

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"

Put this in a file: vim make it executable: chmod +x and run it ./

This will take some time, in some cases 15 minutes or even more. It will backup to: /tmp/db-dump/$TIMESTAMP

Cloud & Open-Source magician 🧙‍♂️

I try to find the KISS in complex systems and share it with the world.

comments powered by Disqus