Thursday, November 21, 2013

Create daily mysql backup with task scheduler

Here is one example of creating daily backup of mysql database and keep the database file on another sever for later use.
creat one batch file mysql-backup.bat. and keep this code in the batch file.

@echo off
echo Running dump...
C:\wamp\bin\mysql\mysql5.5.20\bin\mysqldump.exe -e -uexampleuser -ppass123 --result-file="\\path-to-server\dbbackup\foo-db-%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%.sql" foodb
echo Done!

Then create a scheduled task and run this batch file. So it will take the daily backup and will keep different name depend on the server date.
You can ignore some tables if you like

@echo off
echo Running dump...

C:\wamp\bin\mysql\mysql5.5.20\bin\mysqldump.exe -e -uexampleuser -ppass123 --result-file="\\path-to-server\dbbackup\foo-db-%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%.sql" foodb --ignore-table=foodb .mdl_log --ignore-table=foodb .mdl_sessions

echo Done!

keep in mind that you have to give your mysqldump.exe path and also the path of the file, where you want to keep your db dump.

No comments: