I have the following batch-file on windows-10 which is very close to working with only one small problem.
The .sql
result file is written outside of the desired folder. The batch file properly creates the folder and the file, but fails to change into the desired directory when it creates the .sql
result file.
For example, it creates D:\Backups\MySQL\MyDatabase__04-27-2018-14-22
, and writes the file MyDatabase__04-27-2018-14-22.sql
in the MySQL
folder, rather than inside the folder with the exact same name.
I've tried variations of changing the directory with no success.
set dt=%date:~-10,2%-%date:~-7,2%-%date:~-4,4%-%time:~0,2%-%time:~3,2%
set dt=%dt: =0%
if exist "D:\Backups\" (mkdir D:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
CD /D D:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="D:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else if exist "H:\Backups\" (mkdir H:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
H:
CD H:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="H:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else if exist "G:\Backups\" (mkdir G:\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
G:
CD G:\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="G:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
) else mkdir C:\Users\Scotty\Desktop\Backups\MySQL\MyDatabase__%dt%
CD ..
CD ..
C:
CD C:\Users\Scotty\Desktop\Backups\MySQL\MyDatabase__%dt%
START /WAIT C:\xampp\mysql\bin\mysqldump.exe --user=root --password= --host=localhost --port=3306 --result-file="C:\Backups\MySQL\MyDatabase_%dt%.sql" --default-character-set=utf8 --single-transaction=TRUE --databases "MyDatabase"
CD..
CD..
CD C:\Users\Scotty\Desktop\BackupBatchFiles\
The actual result is that the mysqldump result file is placed outside the directory created with the same name. I am expecting the .sql
result file to be written INSIDE the directory that the batch file created with the same name.