0

I'm trying to take a backup of a mysql database using the following code:

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%b-%%a-%%c)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a-%%b)
mysqldump -uroot -pas imed_dbsys > "D:\IMED CMS BACKUP\%mydate%_%mytime%.sql"

I want to name database backups using date and time.

My Expected Output:

2021-12-13_03-42 PM.sql

The output that shows in the folder (Date was not shown):

2021-12-_03-42 PM.sql

Can you help me to fix this problem? Thank you so much :D And I'm sorry to my English Grammar :)

4
  • What have you tried to resolve the problem? Is this even related to mysqldump if you specify the output file in your batch script? Commented Dec 13, 2021 at 7:50
  • @NicoHaase the code was working, but sql database name was incomplete. I want to name the sql backups in time and date. But all I can see was Year, Month, and Time only (No Date). Commented Dec 13, 2021 at 7:54
  • The string you use does not contain the database name after all. Why not add it when you need it? Also, the expected output does not contain any database name Commented Dec 13, 2021 at 7:58
  • youtube.com/watch?v=lo30JnlRVEU this is the link that I followed to do my code above. Commented Dec 13, 2021 at 8:09

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.