Applicable to:
- Plesk for Linux
Question
How to backup all MySQL/MariaDB databases via a command-line interface in Plesk for Linux?
Answer
-
Connect to a server via SSH.
-
Create a directory where backup files will be stored:
# mkdir /root/mysql_dumps_all
-
Get a list of all databases:
# cd /root && /usr/sbin/plesk db -e "show databases" | grep -v -E "^Database|information_schema|performance_schema|phpmyadmin" > dblist.txt
-
Create a dump of each MySQL/MariaDB database:
# cat /root/dblist.txt | while read i; do /usr/sbin/plesk db dump "$i" > /root/mysql_dumps_all/"$i".sql; done
-
List all database dumps:
# ls -l /root/mysql_dumps_all
To restore all databases from dump files created above, run the command:
# for i in `cat /root/dblist.txt`; do MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql -u admin < /root/mysql_dumps_all/"$i".sql; done