0

it's the first time that I write a little script in batch, I need to create a folder named like the date, then I want to go in that directory and run the dump of my database. Here my code:

cd C:\Users\Administrator\Documents\db_backup

FOR /f "tokens=2-4 delims=/ " %%a in ('date /t') do mkdir %%a-%%b-%%c

cd C:\Program Files\MySQL\MySQL Server 5.6\bin

mysqldump -uroot -proot emc > C:\Users\Administrator\Documents\db_backup\*here goes the folder created before*\backup.sql

I know that probably is a stupid question, but i never work whith batch. Thanks to everybody.

1 Answer 1

1

The date format changes by region settings and machine - it's wiser to use Wmic to get it in a stable format.

But this should work:

cd /d "C:\Users\Administrator\Documents\db_backup"

FOR /f "tokens=2-4 delims=/ " %%a in ('date /t') do set d=%%a-%%b-%%c

md "%d%"

cd /d "C:\Program Files\MySQL\MySQL Server 5.6\bin"

mysqldump -uroot -proot emc > "C:\Users\Administrator\Documents\db_backup\%d%\backup.sql"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.