We Do the Work, You Earn the Cash! 20% off Basic/Pro Reseller Plans!

How To Automatically Backup MySQL Database using Cron Job on Go Daddy Linux Shared Hosting

Below is an image of the created shell script using FTP Manager

Below is another image of the created shell script using the  Notepad++ editor. I had all kinds of problems using Notepad and WordPad inserting special characters into the script. If you are getting emails from Cron Job with the message "^M:bad interpreter:No such file or directory" you most likely have special characters embedded into your shell script. Using Notepad++ with the option SH turned on will solve any headache you encounter or using Go Daddy FTP File Manager will work.  Here is a download link of the sample shell script file  Mybackupdemo.zip

This script runs the mysqldump using the information that you collected for the MySQL database connection.

  • -h hostname
  • -u username
  • -ppassword (important no space between the option and password)

I also wanted the mysqldump zipped up into one file and a date and time stamp for each dump file.

Pages: 1 2 3 4

12 Responses to How To Automatically Backup MySQL Database using Cron Job on Go Daddy Linux Shared Hosting

  • edwardh says:

    Thank you so much for this! They should really link to great guides like these in their docs. I was afraid it may not even be possible to do automated MySQL backups with at least non-deluxe GoDaddy accounts.

  • Xander says:

    Hi, Curt.  Thanks for this – after a close call almost losing my DB I had to go looking for an automated option.
     
    I didn't have any trouble with the bash script (windows-savvy, not linux) and it seems to have run on schedule.  However, I am getting the email but it's a permissions error.  I've got that folder set to R/W/E for Owner and Group but not for Everyone.  What permissions does it need?

  • Derrick Wills says:

    Great Help!  Thanks!  But is having the db info and Password Inside the Shell Script SAFE?  Can it be easily read by hackers?
    I'm a little new to scripting, as I use a bunch of scripts that have already been developed rather than using custom scripts.  But was wondering.
     

    • Derrick Wills says:

      Also, what if I don't want it zipped, but only want it to create the sql file, how do I code the shell script to do that?

      • Curt Cadwell says:

        Edit the bash script file where the “|” symbol is take it out and everything to the right and replace with “> $HOME/html/_db_backups/putnameofscript.sql”  This will just create a .sql file but depending on your database this could be quite large and of course could get corrupted.

  • Sara says:

    I'm receiving the following error. The password is correct and the file is set to execute so I can't figure out what I'm doing wrong.  I'm new at this so excuse me if it's something really obvious! Thanks!
    Also, why is the same code in the file twice?
    Enter password: mysqldump: Got error: 1045: Access denied for user 'gui1215001524905'@'184.168.27.146' (using password: NO) when trying to connect

    • Sara says:

      This is an earlier error: 
      mysqldump: Got error: 1045: Access denied for user 'gui1215001524905'@'184.168.27.146' (using password: YES) when trying to connect

  • AKTed says:

    Great write-up! I used your shell script from the command-line, and it works perfectly. One problem I came across is when I saved your script I had a stray line-break at the end of the file. So in FileZilla the outputted .gz file <em>looks</em> normal, but it throws a <code>no such file or directory</code> error when you try to access it. That stray line-break becomes a question-mark (?) appended to the end of the filename – which isn't visible in FileZilla. Found this out through SSH.

  • Great post. I have the same problem with a production site I developed and now maintain for a local Tennis Club. Not having daily backups has been a big issue for me. I now have a head start!

    Just as an aside, a good editor for things like config files and scripts  is an efficient,  lightweight, and free editor known as Geany. It works the same both for linux and windows. It is also a good editor for HTML, CSS and javascript and other languages.

    URL for windows binaries is: http://www.geany.org/Download/Releases

    Example linux install commands:

    Ubuntu? sudo apt-get install geany

    Fedora, Centos: sudo yum install geany

    This way you can get away most if not all the Windows/Linux text character translation issues. Also, Geany has great plugins. A good example is the color chooser if you are working with CSS. You are presented with a color wheel select the color and the hex codes for the color will appear in the editor.

    Anyway, thanks a million for the tip on the linux scripts.

    Rgds,

    Bud

  • Lisa says:

    I was trying to use your script to create a cron for db backup, I too do not want it zipped, but I am getting the bad interpreter script.  I was trying to follow along with checking in notepad++ but did not see anything related to SH.  Any other recommendations?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Build your Wesite, Online Store, Blog and More - 10% off Your Order at GoDaddy.com

Copyright © 2012. All Rights Reserved.