Trying to create a batch (cmd) file for backing up each database into a separate file. Databases are created/deleted often, so batch file needs to grab current db names everytime it runs and backup each one of them.
Here is how I want it to be:
mysql -e "show databases" -u root --password=1234
mysqldump %dbname% -u root --password=1234 > S:\Backup\MySQL\%dbname%.sql
Is it possible to do in a batch file?
Please help. Thanks.
Im no DOS hacker,but I added one correction to my copy of the batch file to account for the whitespace character in the curtime variable if time is before 10 am. I added this line to my batch file after the for loops:
hey rolando i combined your code with some other code from the internet to dump all databases to different files and compress it in one file with date-time stamp and finally delete files older than 60 days cheers
You can try this straight forward approach:
steps:
1. type the above code in your text editor and save it as batch file e.g. mybatch.bat
2. change directory(cd) to d location you save the batch file to, from your command prompt
3. type the name of your batch file and hit enter e.g. mybatch.bat
4. check the location for your DB schema i.e. path
This can be run directly in cmd (I wrapped the line but it should not be wrapped):
In a batch file you will need to escape % with an additional %, that is use
%%D
.Batch File
OK, First... It's possible that I'm using a different version of SQL than you, and im sorry if thats the case, you didn't list your version in your question so I'm just going to give you what works with mine.
I have the first part of this done, but I'm still working on the backing up of the DB's.
There are other triggers that can be used, but it sounds like you're going to be on the actual machine that has SQL installed, correct? If this is the case, it should default the IP to connect to SQL to 127.0.0.1 or localhost, etc.
What I'm thinking I'm going to have to do for this is create a file in the batch script that I will call further down that will send the commands line by line, similar to what is done in the FTP process with Batch Scripts.
I'll update this when I get it.
This script is a bit more "professional" in the sense that it notifies someone when one DB dump failed and which one failed. Though, I had it not backing up all databases but only chosen ones. This can be fixed easily by changing the
SET DBS=
content by a command getting all databases.EDIT: New version remove the warning message