MySQL Database backup automatically on a windows server

后端 未结 5 1560
一向
一向 2020-12-24 05:48

Is there a way to back up MySQL database automatically at certain times of the day for designated servers or send an email with an attachment.. Which ever do you think is th

5条回答
  •  醉酒成梦
    2020-12-24 06:45

    I did the work, similar to what other people explained through... but with little difference and extra work:

    1) I made a batch file
    2) Ran that batch file through windows scheduler
    3) Made appropriate schedule for that task
    4) Inside the batch file these steps are executed:

    • 4-1) Prepared a file name based on current date
    • 4-2) Got a backup by mysqldump.exe in the corresponding directory & file name
    • 4-3) Made a compress file through 7-Zip app(install it) & then delete the uncompressed backup
    • 4-4) Put a copy on our network File-Server

    Here is a script(.bat) sample:

    @echo off
    set current=%date:~10,4%%date:~4,2%%date:~7,2%
    set filename="E:\MySQL Backups\DBName-%current%.sql"
    set filename2="E:\MySQL Backups\DBName-%current%.zip"
    echo %filename%
    cd "E:\MySQL Backups"
    C:\"Program Files"\MySQL\"MySQL Server 5.5"\bin\mysqldump.exe db_name --user=root --password=rootpass --host="127.0.0.1" --port=instancePort --result-file=%filename% --default-character-set=utf8 --single-transaction=TRUE
    echo backup-finished
    
    if exist %filename% (
        "C:\Program Files\7-Zip\7z.exe" a %filename2% %filename%
        echo zip-finished
        del %filename%
    )
    if exist %filename2% (
        copy %filename2% "\\192.168.x.x\MySQL Backups"
        echo copy-finished
    )
    

提交回复
热议问题