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%Databases\MySQL\backup\
to store the backups in -
Create
backup.bat
file in directory created in step 2. with the following content:
"%plesk_dir%\MySQL\bin\mysqldump.exe" -uadmin -ppassword_for_mysql -P3306 --all-databases --events -r "%plesk_dir%Databases\MySQL\backup\backup_databases.sql"
MOVE "%plesk_dir%Databases\MySQL\backup\backup_databases.sql" "%plesk_dir%Databases\MySQL\backup\backup_databases_%time:~0,2%%time:~3,2%%time:~6,2%_%date:~-10,2%%date:~-7,2%%date:~-4,4%.sql"
"%plesk_dir%\MySQL\bin\mysql.exe" -uadmin -ppassword_for_mysql -P3306 -Ne"SHOW DATABASES" > "%plesk_dir%\Databases\MySQL\backup\db_list.txt"
cd %plesk_dir%\Databases\MySQL\backup
for /F "tokens=1,2* " %%j in (db_list.txt) do "%plesk_dir%\MySQL\bin\mysqldump.exe" -uadmin -ppassword_for_mysql -P3306 --routines --databases %%j > "%plesk_dir%\Databases\MySQL\backup\%%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 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%Databases\MySQL\backup\backup.bat
in the Command field: -
Configure desired execution time for backups to be created in Run field
-
Save the task by clicking OK
Comments
2 comments
I don't have the option 'with arguments' available when I select command. If I select php script, the option with arguments does come available
@Lucas van Rooij
That is because the article is for Windows and you are using Linux.
In that case, you may create a script like as follows (you should be logged via SSH):
# vi /root/script.sh
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -u admin -A --events -r /root/backup_`date +%F.%s`.sql;
Do not forget to make it executable:
# chmod +x /root/script.sh
After that, go to Plesk > Tools & Settings and create a Scheduled Task like on the screenshot: https://prnt.sc/gs8imr
Please sign in to leave a comment.