Skip to content

Instantly share code, notes, and snippets.

@joviczarko
Last active March 28, 2023 08:13
Show Gist options
  • Save joviczarko/363027b2bdd32125d0390ec13d97e029 to your computer and use it in GitHub Desktop.
Save joviczarko/363027b2bdd32125d0390ec13d97e029 to your computer and use it in GitHub Desktop.
Automatic MySQL database backup (dump) bat file for wamp server
@ECHO OFF
For /f "tokens=2-4 delims=. " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=.:," %%a in ("%TIME%") do (set mytime=%%a-%%b-%%c)
set TIMESTAMP=%mydate%_%mytime%
REM Export all databases into file E:\wamp64\backup\database_backup.[year][month][day].sql
"E:\wamp64\bin\mysql\mysql5.7.14\bin\mysqldump.exe" --all-databases --result-file="E:\wamp64\backup\database_backup_%TIMESTAMP%.sql" --user=root
REM Change working directory to the location of the DB dump file.
E:
CD \wamp64\backup\
REM Compress DB dump file into CAB file (use "EXPAND file.cab" to decompress).
MAKECAB "database_backup_%TIMESTAMP%.sql" "database_backup_%TIMESTAMP%.sql.cab"
REM Delete uncompressed DB dump file.
DEL /q /f "database_backup_%TIMESTAMP%.sql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment