使用批处理文件中的msqldump将时间戳添加到文件名

时间:2014-07-01 14:01:15

标签: mysql batch-file timestamp backup

我正在尝试使用.bat文件向mysql数据库转储文件添加时间戳,但它不太顺利。时间戳没有添加 - 我只是得到一个backup-.sql文件。有什么提示吗?

我的档案:

@echo off
cls
echo Date format = %date%
echo dd = %date:~0,2%
echo mm = %date:~3,2%
echo yyyy = %date:~6,4%
echo.
echo Time format = %time%
echo hh = %time:~0,2%
echo mm = %time:~3,2%
echo ss = %time:~6,2%
echo.
echo Timestamp = %date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%

pushd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysqldump --user=root --password=***** leaverequest>c:\backup\backup-%timestamp%.sql

1 个答案:

答案 0 :(得分:1)

快速编辑应修复它:

@echo off
cls
echo Date format = %date%
echo dd = %date:~0,2%
echo mm = %date:~3,2%
echo yyyy = %date:~6,4%
echo.
echo Time format = %time%
echo hh = %time:~0,2%
echo mm = %time:~3,2%
echo ss = %time:~6,2%
echo.
set timestamp=%date:~6,4%-%date:~3,2%-%date:~0,2%-%time:~0,2%-%time:~3,2%-%time:~6,2%

pushd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
mysqldump --user=root --password=***** leaverequest>"c:\backup\backup-%timestamp%.sql"