CronJob for backing up and emailing a database

Discussion in 'Programming' started by joet1110, Jun 9, 2010.

  1. #1
    Hello.

    Im trying to setup a cron job which backs up all the databases and zips them up then emails me, then deletes the backup zip on the server.

    Ive been trying everything, I have come to use this script which seems most logical out of all the scripts ive tried, except once again I cannot get it to work.

    Can someone please advise me on where Im going wrong?

    Thanks for your time!

    Here is the script below:

    #!/bin/sh
    ######
    # first make a mysqldump of all databases, and tar and zip it
    ######
    mysqldump --add-drop-table -u username -p password --all-databases | tar -cvzf > backup.sql.tar.gz
    ######
    # next email it
    # The echo at the start of the last line adds a blank into the body of the 
    # mail being set out.
    ######
    echo | mutt -a backup.sql.tar.gz -s “daily backup of database” emailaddress@domain.com
    ####
    # finally, delete the backup from your server
    ####
    rm backup.sql.gz
    Code (markup):
     
    joet1110, Jun 9, 2010 IP