Is it possible to perform automatic backup in mysql? Example: I target a folder which Mysql will generate every day at 6:00 PM the database backup.
Is it possible to perform automatic backup in mysql? Example: I target a folder which Mysql will generate every day at 6:00 PM the database backup.
Hello,
I made an automation of this by creating a .bat file with the commands and configuring the execution in the Windows Task Scheduler, below my bat file:
@echo off
cls
REM Define o usuário e senha do banco de dados
set dbUser=xxx
set dbPassword=xxx
REM Define a pasta que será feito o backup no padrão ...\<dia do mês>\<hora atual>
set backupDir=C:\Backup\MySQL\%date:~0,2%\%time:~0,2%\
REM Nome do arquivo que será gerado
set file=xxx.sql
REM Caminho dos executáveis do mysqldump.exe, para executar o dump, e do 7z.exe, para compactar o arquivo
set mysqldump="C:\wamp64\bin\mysql\mysql5.7.14\bin\mysqldump.exe"
set zip="C:\Program Files-Zipz.exe"
REM Cria a pasta de backup caso não exista
if not exist "%backupDir%" (
mkdir "%backupDir%"
)
REM Executa o dump, aqui precisa configurar o host e o nome do banco de dados (locais com xxx)
%mysqldump% --host="xxx" --user=%dbUser% --password=%dbPassword% xxx > "%backupDir%\%file%"
REM Compacta o arquivo com o dump
%zip% a -tgzip "%backupDir%\%file%.gz" "%backupDir%\%file%"
REM Exclui o arquivo .sql original
del "%backupDir%\%file%"
In case, it creates a folder for the day of the month, dumps and compacts the file.