How to do daily database backup automatically ?

  • Hi,


    yes. But I just notice a small improvement. Use this:

    Bash
    #!/bin/bash
    DATABASE=<enter the name of your database here>
    cd $(dirname $0)
    echo "$(date +%Y-%m-%d_%H-%M-%S) Backup start"
    mysqldump --defaults-file=$(pwd)/mysqldump-credentials--single-transaction --skip-lock-tables --net_buffer_length 16384 $DATABASE > $(pwd)/$DATABASE.sql
    rm $(pwd)/$DATABASE-3.sql
    mv $(pwd)/$DATABASE-2.sql $(pwd)/$DATABASE-3.sql
    mv $(pwd)/$DATABASE-1.sql $(pwd)/$DATABASE-2.sql
    mv $(pwd)/$DATABASE.sql $(pwd)/$DATABASE-1.sql
    echo "$(date +%Y-%m-%d_%H-%M-%S) Backup end"