Wednesday, November 28, 2012

SCHEDULING AUTOMATIC BACKUP OF DATABASE (MYSQL)

Steps :-
  1. Create a bath file(.bat extension)in notepad.
    • Open notepad and write the queries of MySQL and save it as file-name.bat
    • use Mysqldump statement to create a backup of your database. 
    • (ex. mysqldump database_name -u user -ppassword >backup.sql)
NOTE:If you want the file to be stored with current date, use the below mention code for extracting date particulars {yyyy_mm_dd}

@echo off

    set year=%date:~10,4%
    set mnth=%date:~4,2%
    set day=%date:~7,2%

    set d=%year%_%mnth%_%day%.sql
      mysqldump test -u root -pmysqlpassword >%d%

      2.Schedule task using windows task scheduler   
        • GOTO: Control Panel\System and Security\Administrative Tools
        • select task scheduler and create a new task
        • configure it according to the requirements
        • Under action select "start a new program" and open the batch file created.