Plesk

How to automatically create backups of all databases of customer MySQL/MariaDB server in Plesk?

Applicable to:

  • Plesk for Windows

Question

How to automatically create backups of all databases of customer MySQL/MariaDB server in Plesk?

Answer

Note: All customers data including the databases can be backed up using Plesk Server Backup. This article describes how to automatically backup only all databases of customer MySQL/MariaDB server on port 3306 and nothing more.

  1. Log into the server via RDP

  2. Create the directory %plesk_dir%DatabasesMySQLbackup to store the backups in

  3. Create backup.bat file in directory created in step 2. with the following content:

To store databases in a single file

"%plesk_dir%MySQLbinmysqldump.exe" -uadmin -ppassword_for_mysql -P3306 --all-databases --events -r "%plesk_dir%DatabasesMySQLbackupbackup_databases.sql"
MOVE "%plesk_dir%DatabasesMySQLbackupbackup_databases.sql" "%plesk_dir%DatabasesMySQLbackupbackup_databases_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.sql"

To store databases in separate files

"%plesk_dir%MySQLbinmysql.exe" -uadmin -ppassword_for_mysql -P3306 -Ne"SHOW DATABASES" > "%plesk_dir%DatabasesMySQLbackupdb_list.txt"
cd %plesk_dir%DatabasesMySQLbackup
for /F "tokens=1,2* " %%j in (db_list.txt) do "%plesk_dir%MySQLbinmysqldump.exe" -uadmin -ppassword_for_mysql -P3306 --routines --databases %%j > "%plesk_dir%DatabasesMySQLbackup%%j_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.sql"

  1. Replace password_for_mysql in backup.bat of step 3. with the password of MySQL/MariaDB server. If password is unknown, it can be reset via Tools & Settings > Database Servers > localhost (3306) > Change password

  2. Log into Plesk

  3. Go to Tools & Settings > Scheduled Tasks and click Add Task

  4. Specify the path %plesk_dir%DatabasesMySQLbackupbackup.bat in the Command field:

  5. Configure desired execution time for backups to be created in Run field

  6. Save the task by clicking OK