1

I want to backup my database in MySQL(which is on my local pc) everyday, so I am using Task Scheduler of Windows7 to run this command everyday:

mysqldump -u root -p pwd mydbname > backup-2014-06-10.sql

But the problem is the .sql file's name cannot be dynamically specified based on the date of executing.

Is there any way to solve that?

Thanks in advance!

VincentZHANG
  • 757
  • 1
  • 13
  • 31
  • See: http://superuser.com/questions/47885/windows-command-line-create-a-file-with-the-current-date-in-its-name – Marc B Jun 11 '14 at 14:50
  • Thanks, but I don't figure it out, I tried this: `mysqldump -u root -p test > backup-%date:/=-%.sql`, but it didn't work. – VincentZHANG Jun 11 '14 at 15:01
  • you do set a variable `set d=%date etc...`, then use that variable in your mysql command, exactly how it's done in the accepted answer in the linked question. – Marc B Jun 11 '14 at 15:13
  • @MarcB, Thank you a lot, I made it work by doing this `mysqldump -u root -p clubs_report > backup-"%DATE:/=-%.sql"`, but what I got was a .sql file with name "backup-12-06-2014 Thursday.sql", is there a way to get rid of the day-in-week string? – VincentZHANG Jun 12 '14 at 01:51
  • http://stackoverflow.com/questions/10945572/windows-batch-formatted-date-into-variable – Marc B Jun 12 '14 at 14:30

0 Answers0