We help IT Professionals succeed at work.

automating mysqldump on windows

andrew67
andrew67 asked
on
4,976 Views
Last Modified: 2008-01-09
Hi i have the following mysqldump running in a .bat file on a windows server.

mysqldump --user user --password=password db >C:\mysqlbackups\output.sql

however i want to run this daily and keep all the dumps so what i want to do is instead of naming the output output.sql i want to name it "todaydate" + output.sql

but i have no idea how to script this on windows

can any one help

thanks in advance
Comment
Watch Question

Aleksandar BradarićSoftware Developer
CERTIFIED EXPERT

Commented:
What you need is to enter the date variable into that output filename. See here for an example: http://www.tech-recipes.com/computer_programming_tips956.html

Let me know if you have any more problems...

Author

Commented:
hi thanks for that.  i know this mite sound really stupid but im using it like this to start with

echo on
@REM Seamonkey's quick date batch (MMDDYYYY format)
@REM Setups %date variable
@REM First parses month, day, and year into mm , dd, yyyy formats and then combines to be MMDDYYYY

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET dd=%%B
FOR /F "TOKENS=2,3 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%mm%%dd%%yyyy%
mkdir C:\mysqlbackups\date

and its greate it creates a directory but names it data not "currentdate" can you tell me where im going wrong

thanks
Aleksandar BradarićSoftware Developer
CERTIFIED EXPERT

Commented:
Try:
---
mkdir C:\mysqlbackups\%date%
---

Author

Commented:
tried that it creates a dir but calls it "10on"

then in the mysqldump script that runs straight after i have the path to put the file as

 C:\mysqlbackups\%date%\dump.sql

but it doesnt create it

thanks
Aleksandar BradarićSoftware Developer
CERTIFIED EXPERT

Commented:
You might have a different date format on your computer. Could you tell me what is it (e.g. 2007/10/11 or 11.10.2007 etc.)?

Author

Commented:
i know this might sound really stupid but how would i find out?
Aleksandar BradarićSoftware Developer
CERTIFIED EXPERT

Commented:
Go to command prompt and type:
---
date /t
---

Author

Commented:
comes back "11/10/2007"
Aleksandar BradarićSoftware Developer
CERTIFIED EXPERT

Commented:
OK. Here's your script then:
---
echo on
FOR /F "TOKENS=1* DELIMS=/ " %%A IN ('DATE/T') DO SET CDATE=%%B
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dd=%%A
FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %%A IN ('echo %CDATE%') DO SET mm=%%A
FOR /F "TOKENS=1,2 DELIMS=/ " %%A IN ('echo %CDATE%') DO SET yyyy=%%B
SET date=%yyyy%%mm%%dd%
mkdir C:\mysqlbackups\%date%
---

Author

Commented:
sorry about this but its now creating the dir "on.10" and still i presume fining an error because the script ends then, and doesnt run the mysqldump command


thanks

andrew
Software Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
C:\>mysqlbackup.bat

C:\>echo on

C:\>FOR /F "TOKENS=1* DELIMS= " %A IN ('DATE/T') DO SET CDATE=%B

C:\>SET CDATE=

C:\>FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %A IN ('DATE/T') DO SET mm=%B

C:\>SET mm=10

C:\>FOR /F "TOKENS=1,2 DELIMS=/ eol=/" %A IN ('echo ') DO SET dd=%B

C:\>SET dd=

C:\>FOR /F "TOKENS=2,3 DELIMS=/ " %A IN ('echo ') DO SET yyyy=%B

C:\>SET yyyy=on.

C:\>SET date=on.10

C:\>mkdir C:\mysqlbackups\on.10

C:\>mysqldump --user paineurope --password=rocky packerforbes  1>C:\mysqlbackups
\on.10
Access is denied.

C:\>

Author

Commented:
ok ive sorted out the name creation

it needed the / after DELIMS mine didnt have it  "DELIMS=/"

but im still getting access is denied

andrew

Author

Commented:
sorted thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.