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.
-
Log into the server via RDP
-
Create the directory
%plesk_dir%DatabasesMySQLbackup
to store the backups in -
Create
backup.bat
file in directory created in step 2. with the following content:
"%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"
"%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"
-
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 -
Log into Plesk
-
Go to Tools & Settings > Scheduled Tasks and click Add Task
-
Specify the path
%plesk_dir%DatabasesMySQLbackupbackup.bat
in the Command field: -
Configure desired execution time for backups to be created in Run field
-
Save the task by clicking OK