Reputation: 5331
I am unix man, and I really don't like work on windows. I am asking You for help.
I am trying to make regular backups of mysql database in microsoft windows cmd. Here is my current script for that:
C:\xampp\mysql\mysqldump.exe -hlocalhost -uroot -ppass stp > V:\backup_3.2.2.6__%date:/=%.sql
I would like to file name have structure like that:
backup_3.2.2.6__2015-06-02_10:25:35.sql
where is:
name__currentDate_currentTime.sql
So I just need to add current time to file name.
Please help
Upvotes: 5
Views: 10884
Reputation: 5331
Here is working solution:
C:\xampp\mysql\mysqldump.exe -hlocalhost -uroot -ppass stp > V:\backup_3.2.2.6__%date:/=%_%time:~0,2%-%time:~3,2%-%time:~6,2%.sql
Where "pass" is Your password for root user
Upvotes: 7
Reputation: 533
You can not have :
as a part of the file name on Windows.
Try the following batch file, it will create file with the name in the format such as: backup_3.2.2.6__2015-06-02_17-50-44.sql
:
@echo off
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set datetime=%%I
set datetime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2%_%datetime:~8,2%-%datetime:~10,2%-%datetime:~12,2%
"C:\xampp\mysql\mysqldump.exe" -hlocalhost -uroot -ppass svp > "V:\backup_3.2.2.6__%datetime%.sql"
I have used wmic example from the answer at: https://stackoverflow.com/a/18024049/4947851
Upvotes: 4