Search by Keyword
Forum's Comments
  • Here is the script I use, in my case 6 times a day via cron. It automatically removes older than 7 days. The directory is included in the directory and I save everything via rsync 6 times a day as well.
    Do not put quotes for "NameDB" - "user" - "password"

    #!/bin/bash
    
    #
    
    ## we place ourselves in the directory where we want to save the databases
    
    #
    
    cd /var/www/exemple/backup/bd/
    
    for i in "NameDB"; do
    
    ## Backup of databases in .sql files (with date as name)
    
    mysqldump -u "user" -p"password" $i > ${i}_`date +"%d%m%Y"`_`date +"%H"`h`date +"%M"`m.sql
    
    
    ## Compression of exports in tar.bz2 (the best compression rate)
    
    tar jcf ${i}_`date +"%d%m%Y"`_`date +"%H"`h`date +"%M"`m.sql.tar.bz2 ${i}_`date +"%d%m%Y"`_`date +"%H"`h`date +"%M"`m.sql
    
    
    ## Elimination of uncompressed exports
    
    rm ${i}_`date +"%d%m%Y"`_`date +"%H"`h`date +"%M"`m.sql
    
    ## Deletes backups older than 7 days
    
    
    find /var/www/exemple/backup/bd/ -type f -mtime +7 -delete
    
    ## Sent an email confirmation
    
    echo "Sauvegarde BDD vers var/www/exemple/backup/bd et nettoyage effectue avec succes !" | mail -s "Save BDD Meetsee" -a "From: sender@yoursite.com" recipient@yoursite.com
    
    done