Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Default cron job to backup database and email the attachment

    Hi, I'm trying to backup my database and send the attachment to my hotmail account. Everything goes well using the following script, but the file doesn't get attached. Instead, I get a message of completely garbled text and squares. It's like the email was trying to read the bits from the .gz file. Here's the cron command I use:

    mysqldump --user MY_USERNAME -pMY_PASSWORD --databases MY_DATABASE_NAME | gzip -cq9 > /home/MY_USERNAME/database_backup.sql.gz && mail -s "database backup" MY_EMAIL_ADDRESS < /home/MY_USERNAME/database_backup.sql.gz

  2. #2
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Hi,

    I want to warn against sending the backup of your database as an email attachment through possibly insecure email.

    It would be far better to have it FTP securely to some location for you rather than emailing the fle, which I don't consider to be a very secure mechanism for transmission of data. Additionally, you could end up with a very large file when the database becomes large and FTP (or SCP) are better methods to transfer large files rather than email.

    If you want to use FTP, you could just use the Backup method that already exists in cPanel's Backup area and call it from a cron.

    Just wanted to provide those points to keep in mind.

  3. #3
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    Quote Originally Posted by gatzke View Post
    Here's the cron command I use:

    mysqldump --user MY_USERNAME -pMY_PASSWORD --databases MY_DATABASE_NAME | gzip -cq9 > /home/MY_USERNAME/database_backup.sql.gz && mail -s "database backup" MY_EMAIL_ADDRESS < /home/MY_USERNAME/database_backup.sql.gz
    This is very unwise on a great many levels!

    You have opened up quite a few security holes if that really is your cron command and that is before even mentioning your sending your database backup by email which is a whole other Pandora's box of problems itself.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Default

    OK, I think I'll take your word for it - FTP it is.

    Cheers.

Similar Threads & Tags
Similar threads

  1. Cron Job for DB Backup
    By wasimansha in forum cPanel Developers
    Replies: 3
    Last Post: 07-19-2010, 05:28 AM
  2. Cron Job to back up MySQL database
    By BMR777 in forum New User Questions
    Replies: 1
    Last Post: 01-30-2010, 06:24 PM
  3. Replies: 0
    Last Post: 01-22-2010, 04:53 PM
  4. How do I backup a database using a cron job and send it by mail?
    By nic_net in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 11-29-2006, 12:35 PM
  5. cron job - command to backup a database ?
    By king007 in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 08-17-2006, 05:11 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube