The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Way to email databses nightly?

Discussion in 'E-mail Discussions' started by myusername, Aug 12, 2003.

  1. myusername

    myusername Well-Known Member
    PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    691
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Does anyone have any suggestions on a script/cron job that will email or ftp mysql databases on a daily basis as an added step of protection?

    I recently had a database corrupted by mysql and sometimes i worry about the reliablity of cpanels nightly backup feature.

    Any thought are welcomed.

    Thanks!

    cPanel.net Support Ticket Number:
     
  2. ciphervendor

    ciphervendor Well-Known Member

    Joined:
    Aug 26, 2002
    Messages:
    1,052
    Likes Received:
    0
    Trophy Points:
    36
    Code:
    #!/bin/sh
    
    #
    # Change all of the variables in CAPS.
    #
    
    # List DBs you want backed up.  Separate DB names with a space.
    databases="FIRST_DB_NAME SECOND_DB_NAME"
    
    # Backup directory.  This will be created for you.
    backupdir=/home/USERNAME/db-backup
    
    # mysqldump binary location.
    mysqldumpcmd=/usr/bin/mysqldump
    
    # MySQL Username and password.  User should have access to all DBs listed above.
    userpassword=" --user=USERNAME --password=PASSWORD"
    
    # MySQL dump options.
    dumpoptions=" --quick --add-drop-table --add-locks --extended-insert --lock-tables"
    
    gzip=/bin/gzip
    uuencode=/usr/bin/uuencode
    mail=/bin/mail
    
    # Set to "y" if you want your database backups emailed to you.
    sendbackup="y"
    subject="MySQL DB Backup"
    mailto="YOU@DOMAIN.COM"
    
    #
    # Do not edit anything below this line.
    #
    
    mkdir -p ${backupdir}
    if [ ! -d ${backupdir} ] 
    then
       echo "Not a directory: ${backupdir}"
       exit 1
    fi
    
    for database in $databases
    do
       $mysqldumpcmd $userpassword $dumpoptions $database > ${backupdir}/${database}.sql
    done
    
    for database in $databases
    do
       rm -f ${backupdir}/${database}.sql.gz
       $gzip ${backupdir}/${database}.sql
    done
    
    if [ $sendbackup = "y" ]
    then
       for database in $databases
       do
          $uuencode ${backupdir}/${database}.sql.gz > ${backupdir}/${database}.sql.gz.uu
          $mail -s "$subject : $database" $mailto < ${backupdir}/${database}.sql.gz.uu
       done
    fi
    
    exit
    
     
    #2 ciphervendor, Aug 12, 2003
    Last edited: Aug 12, 2003
  3. myusername

    myusername Well-Known Member
    PartnerNOC

    Joined:
    Mar 6, 2003
    Messages:
    691
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    chown -R us.*yourbase*
    cPanel Access Level:
    DataCenter Provider
    Twitter:
    Alrighty, Thanks I will give it a go.

    Cheers!

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page