Batch File to Backup Your Windows Server Database

This is a quick batch file that will create a date based backup. The file created will be backup_dbname_year_month_day.sql This is to backup one database. You cold change one line to backup all databases if you choose.

Here it is. As with the other file it is attached to this post.

@ECHO OFF
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:\path\to\backups
SET mysqldir=C:\path\to\mysql\bin
SET dbname=databasename
SET dbuser=databaseusername

@ECHO Beginning backup of %dbname%…

%mysqldir%\mysqldump -B %dbname% -u %dbuser% > %bkupdir%\BackUp_%dbname%_%yy%%mm%%dd%.sql
@ECHO Done. New File: dbBkup_%dbname%_%yy%%mm%%dd%.sql

That’s it. Just change the path variables and run the batch file from the command line. You can place it anywhere you like. I place it in the backup dir and run it from there.

If you have any questions you can post a comment to this article. If you want one o one help start a thread on the forum.

 

Files:
Backup to FTP Batch File
Date Based Database Backup Batch File

 

 

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz