再写一个脚本windows mysql自动备份脚本7天的脚本的程序
时间: 2023-05-26 07:04:31 浏览: 87
mysql备份脚本并保留7天
@echo off
setlocal enableextensions
set MYSQL_PATH="C:\Program Files\MySQL\MySQL Server 5.7\bin\"
set BACKUP_PATH="C:\mysql\backup"
set MYSQL_HOST=localhost
set MYSQL_PORT=3306
set MYSQL_USERNAME=root
set MYSQL_PASSWORD=password
rem Creates backup directory if it does not exist
if not exist %BACKUP_PATH% mkdir %BACKUP_PATH%
rem Deletes backups older than 7 days
forfiles /p %BACKUP_PATH% /s /m *.* /d -7 /c "cmd /c del @path"
rem Executes backup
for /f "tokens=1-3 delims=/" %%d in ("%date%") do (
set today=%%f-%%e-%%g
)
set now=%time:~0,2%%time:~3,2%%time:~6,2%
set backupfile=%BACKUP_PATH%\backup_%today%_%now%.sql
"%MYSQL_PATH%\mysqldump.exe" -h %MYSQL_HOST% -P %MYSQL_PORT% -u %MYSQL_USERNAME% -p%MYSQL_PASSWORD% --all-databases > "%backupfile%"
rem Shows success message
echo Backup completed successfully: %backupfile%
pause
exit
阅读全文