Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create a MSDOS Batch Script to backup all mysql database into separate file for restoration

Posted on 2009-04-13
5
Medium Priority
?
1,708 Views
Last Modified: 2012-05-06
Hi,

I would like to request an assistant.

My mysql database mysqldump.exe file and bin folder is located at C:\Program Files\SWsoft\Plesk\Databases\MySQL\bin .

May i know how to create a MSDOS batch script to dump/backup hundreds of my database into a separate .sql backup file for restoration purposes ?

FYI, my database is located in C:\Program Files\SWsoft\Plesk\Databases\MySQL\data folder .

Appreciates if anybody can draw a script to backup all the database and also to restore the database on the other server.

Thank you.
0
Comment
Question by:smksa
  • 2
5 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24132020
You could use the vb script. It needs a file called databases.txt in the same directory which contain each database name on a new line.
It loops through each db, calling mysqldump for each one, and outputing to a names sql dump file
option explicit
 
dim shell, fso, txtDB, db, resp
set fso = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject("WScript.Shell")
 
' Open the Database file
set txtDB = fso.OpenTextFile("databases.txt")
 
' Read each line
while(not txtDB.AtEndOfStream)
  db = txtDB.ReadLine()
  if (trim(db) <> "") then
     resp = shell.run("mysqldump.exe -h <host> -u <user> -pPassword " + db + " > " + db + ".sql")
  end if
wend
 
txtDB.close()

Open in new window

0
 
LVL 8

Expert Comment

by:vinurajr
ID: 24132514
0
 
LVL 8

Accepted Solution

by:
vinurajr earned 2000 total points
ID: 24132526
0
 
LVL 2

Author Comment

by:smksa
ID: 24134422
Hi,

May i know how to restore using a script to restore all the database that has been backup ?

Appreciates if you can add some notes or scripts.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question