DOS again

August 10, 2011

Have not touched DOS command line for many years.

I set up an intranet running XAMPP under XP recently. The hardware is pretty aged so I have to backup the database just in case. I use XP’s scheduler to run a batch file daily during lunch time. The batch file looks like this

title backup database by mysqldump
for /f "tokens=1-4 delims=/ " %%a in ('date/t') do (
set dw=%%a
set mm=%%b
set dd=%%c
set yy=%%d

SET bkupdir=c:\xampp\htdocs\dump
SET mysqldir=c:\xampp\mysql
SET dbname=my_database_name
SET dbuser=root
SET dbuserpwd=my_db_user_pwd
SET dumpfile=%bkupdir%\backup_%dbname%_%yy%_%mm%_%dd%.sql

@ECHO Beginning backup of database %dbname%...

%mysqldir%\bin\mysqldump --opt --user=%dbuser% --password=%dbuserpwd% %dbname% > %dumpfile%
FOR %%A IN (%dumpfile%) DO SET FileSize=%%~zA
@ECHO Done!
@ECHO New File: %dumpfile% %FileSize%bytes

This is just for one database so instead of looping through databases in a single batch file I did the lazy way of using another batch file to CALL a series of batch files with one batch file for each database.

Restoring the mysql dump file should be (in my To-Do list) straight forward. I’ll try this manually at command line.

mysql -u root -p[root_password] [database_name] < dumpfilename.sql


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: