Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Automated sql backup and email

Options
  • 25-04-2007 4:02am
    #1
    Closed Accounts Posts: 19,080 ✭✭✭✭


    I have a cpanel hosting account. I have a couple of mysql databases. I'd like to set up a cronjob to back them up (separately) and send them via email every morning.

    Does anyone have a script that would zip up the sql database and email it?

    Thanks.


Comments

  • Closed Accounts Posts: 68 ✭✭nuada


    Ok I'm not sure or the command switches for any of this but the basic idea would be

    (my)sqldump -u user -ppassword 'database names' | zip -someswitch > backup.sql
    mutt -s 'Backup' -a? backup.sql youremailaddress@gmail.com


    If you read up on the man pages for (my)sqldump, zip and mutt you'll figure out the switches


    Eidt: this might help too http://www.tamba2.org.uk/wordpress/cron/


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    I'm having a look at what you've suggested. Thanks


  • Closed Accounts Posts: 10 IT guy


    thanks i had the same problem,


  • Closed Accounts Posts: 19,080 ✭✭✭✭Random


    *bump*

    Sorta left this drop by the wayside for a while but really need the script now.

    I'm looking for something (ideally in PHP) that I can just add the DB details to and the email address to send to. I'd then set it to run as a daily CRON Job.

    If anyone knows of any ready made scripts that do this that would be great!

    Also, do I need special permissions from my host or on my hosting account to run a .sh file as a CRON?

    Thanks.


  • Closed Accounts Posts: 2,046 ✭✭✭democrates


    I massaged one from d'internet and run it on kubuntu:

    #!/bin/bash

    alias mysqldump=”/usr/bin/mysqldump”
    alias gzip=”/bin/gzip”

    backup_dir="/home/whoever/db_backups/"$(/bin/date +%Y%m%d)"_"$(/bin/date +%H%M%S)
    mkdir $backup_dir

    db="mydatabasename"
    dbdump=$backup_dir"/"$db".sql"
    mysqldump -uroot -ppassword $db > $dbdump

    gzip $dbdump

    exit 0

    Then just insert the mutt lline from nuada before the exit.


  • Advertisement
Advertisement