1. November, 2013

mysqldump windows command line only databases with prefix

Von webfraggle

Here’s a little snippet which mysqldumps only the databases with a specific prefix or another wildcard expression under windows command line or windows batch.

@echo off
setlocal enabledelayedexpansion
set myvar=
for /f %%i in ('c:xamppmysqlbinmysql -uroot -pmysql -e "SHOW DATABASES LIKE 'prefix_%%'"') do set myvar=!myvar! %%i
echo %myvar:~10%
@echo on
c:xamppmysqlbinmysqldump.exe -u root --password=mysql --databases %myvar:~10% | "c:Program Files (x86)gzipgzip.exe" > "C:WHEREEVERYOUWANTmysqlbackup-%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%.gz"