Posts

Showing posts with the label MySql

How to take MySql backup with schedule and success and failure notification

Image
  Following script can be used to take MySql Backup: @echo on For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%b-%%a-%%c) For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a-%%b) mysqldump --protocol=TCP -P8081 -uusername -ppassword databasename> "C:\backup\backupfilename_%mydate%_%mytime%.sql" if %ERRORLEVEL%==0 ( //Send your success notification ) else if %ERRORLEVEL%==2 ( //Send your failure notification ) Here first two line is to get date and time after that we use mysqldump to backup the database, providing protocol, username, password and database name and phisical address of the backup file. See mysqldump documentation for more information.  After backup process completed ERRORLEVEL variable contains the status of the backup if backup is success the value will be 0, for error it will be 2 and if there is any warning then 1. So you can easily send the ...