This batch file maybe used to create a daily backup of a mysql database. Oh and I keep mysqldump.exe in the same folder as this script.
@ECHO OFF
for /F "tokens=2,3,4 delims=/- " %%a in ("%DATE%") do ( set fdate=%%c%%a%%b ) Set /P dbname=Please enter the database name e.g. appdb: IF "%dbname%"=="" GOTO ERROR_MISSINGPARAM SET /P host=Please enter database hostname/ip, press enter for localhost: IF "%host%"=="" SET host=127.0.0.1 SET /P user=Please enter database username, press enter for root: IF "%root%"=="" SET user=root
Echo Backup database %user%@%host%/%dbname% "%~dp0\mysqldump.exe" -u%user% -h%host% -p %dbname% > "%~dp0\%dbname%_%fdate%.sql" IF %ERRORLEVEL% EQU 0 ( ECHO Database backup execution complete. ) ELSE ( ECHO Database backup failed. ) GOTO END :ERROR_MISSINGPARAM ECHO You did not enter one or more required values. GOTO END GOTO END Echo end :END ECHO Press any key to quit! PAUSE > nul
No comments:
Post a Comment