+ Reply to Thread
Results 1 to 10 of 10

Thread: How to Backup Site HTML Files and MySql Databases and have them emailed to me daily

  1. #1
    Join Date
    Jun 2009
    Posts
    5

    Question How to Backup Site HTML Files and MySql Databases and have them emailed to me daily

    So it is apparent that bluehost does not do backups, and that if you do backups you cannot store them on your server.

    Looking at a few other threads I am trying some cron jobs to backup my site daily. These are the two cron jobs I am trying (first try tonight):

    date=`date -I` ; tar -zcf backup_$date.tgz ./public_html

    That should backup the whole public_html folder into a .tgz file with the backup date in the filename.

    mysqldump --opt --user=dbusername --password=dbuserpw dbname | gzip > /home/homeuser/mysqldbbackup.`date +\%F`.gz

    That should backup the whole mysql database into a .gz file with the backup date in the filename.

    Anyone know if this will work??

    Anyone know an easy way to get these files from my hosting server space to my local computer? by email or by automated ftp?

    IS THERE A BETTER WAY TO MAKE A RESTORABLE BACKUP OF MY WEBSERVER FILES AND DATABASE?

  2. #2
    Join Date
    Nov 2006
    Location
    Sydney, Australia
    Posts
    4,533

    Default

    The database backups I run basically use cron to run that command to create a backup copy of the database and I then have another cron that emails that file to me a few minutes later (so as to allow time for the file to be created). The next time I read my emails the file gets automatically downloaded to my own computer. I had already written my own PHP mail script that can handle attachments so I used that (see http://www.felgall.com/php2.htm for more info)

    I only backup the database since all the other files are copied from my computer to the hosting in the first place and so I take backup copies of the originals on my computer for those files.

    The only thing that I have had problems with is that a couple of times BlueHost have deleted my crons (both times where they were upgrading something) and the only way I have found to keep a backup of those is as entries in a text file that I need to copy and paste back into the crons option in cpanel if they disappear.

  3. #3
    Join Date
    Jun 2009
    Location
    in your computer, messin with your stuff.
    Posts
    249

    Default

    If you're feeling very ambitious you should do this :
    1. Get a home server up and running with either FreeBSD or CentOS on it.
    2. Get a dedicated IP from your ISP.
    3. Read (and understand) this entire page: http://www.manpagez.com/man/1/rsync/
    4. Once you have an rsync command that is working set it in a cron job to run every week at 2 am MST.

    You can set it up to where after the first rsync it will only update files that have changed since the last backup.

    As for databases, you're on the right track with that cron job.. here is what mine looks like, I just have it set up to go to an email address that i have setup with POP, so my backups are only on the server for ~24 hours at a time if that.

    My SQLdump Cron Job:

    Code:
    mysqldump -ce --user=<user_name> --password=******** <database_name> | mail *********@mydomain.org
    I also set up a special mysql user with only the necessary permissions for doing a mysqldump, (the only needed permissions are SELECT and LOCK TABLES).. and i can just use my backup user for all of my db's. not having to keep track of all the different users and passwords that you would need for lots of databases.
    Last edited by EricJ; 07-01-2009 at 04:16 PM. Reason: added (and understand)

  4. #4
    Join Date
    Jun 2009
    Posts
    5

    Default

    You know, all I want to do is have a simple way to backup my public html files and the associated database.

    I did not think it should be that complicated.

    My files backup worked fine last night. So I've added your mail command to my files backup, it looks like this now:

    Code:
    date=`date -I` ; tar -zcf backup_$date.tgz ./public_html | mail myemail@yahoo.com
    I have no clue if this will work but I don't want to have to go check it every night and download and delete it so if I can get it to email to me that would be great.

    My database backup did not work. I have changed it to what you suggested:

    Code:
    mysqldump -ce --user=zzzzzzzzzzzz --password=yyyyyyyyyyyyy vvvvvvvvvvvv | mail myemail@yahoo.com
    I don't know, I'm probably missing something important.

    Unfortunately one of the features of the website we've created includes a cool cms system. The users are adding inventory items, and if they lose their work because something happens and it is not backed up, I'm on the line.


    Last edited by HughKazoo; 07-01-2009 at 08:12 PM.

  5. #5
    Join Date
    Jun 2009
    Location
    in your computer, messin with your stuff.
    Posts
    249

    Default

    Your SQL dump string looks good, it should work as long as the user has the appropriate permissions, and as long as you didn't make any typing errors.

    Sorry if I offended you with pushing rsync, thats just what I would do if i was in your situation. rsync is complicated at first, but once you have it setup it is one of the most efficient systems for backing up files that has ever been devised by man.

  6. #6
    Join Date
    Jun 2009
    Posts
    5

    Default

    No insult taken. I am paying 3 times as much to host with BlueHost than I do most of our client's websites. Yet my less expensive host provides regular backups. I want to design websites and have my site backed up regularly, not deal with crazy technical things like cron jobs utilizing geeky unix commands just to keep my data safe. This is just kind of becoming a pet peeve for me, I did not mean to take it out on you.

  7. #7
    Join Date
    Jun 2009
    Location
    in your computer, messin with your stuff.
    Posts
    249

    Default

    Well at least you have a team of helpful customers here to help you out ..
    sorry you feel that way though..
    Last edited by EricJ; 06-01-2010 at 08:18 PM.

  8. #8
    Join Date
    May 2008
    Posts
    3

    Default

    Quote Originally Posted by HughKazoo View Post
    My files backup worked fine last night. So I've added your mail command to my files backup, it looks like this now:

    Code:
    date=`date -I` ; tar -zcf backup_$date.tgz ./public_html | mail myemail@yahoo.com
    I have no clue if this will work but I don't want to have to go check it every night and download and delete it so if I can get it to email to me that would be great.
    Hi, did you get your script to work?
    Last edited by redsox9; 03-01-2010 at 11:47 AM. Reason: Fixed quote

  9. #9
    Join Date
    Feb 2006
    Location
    North of Boston, MA
    Posts
    1,471

    Default

    Quote Originally Posted by telefone View Post
    Hi, did you get your script to work?
    Apparently not; he updated his original post to state that the database backup did not work.
    redsox9 - Go Red Sox!!! 2004 and 2007 World Series Champions!
    Visit FenwayFanatics.com, home to Boston Red Sox baseball fans everywhere

  10. #10
    Join Date
    May 2006
    Posts
    12

    Default

    Quote Originally Posted by redsox9 View Post
    Apparently not; he updated his original post to state that the database backup did not work.
    Thought I would share the cron job that DOES email the bzipped db backup successfully as a file attached to an email.

    Code:
    mysqldump -ce --user=USERNAME --password=PASSWORD database_name | bzip2 > ~/DBBackup.`date +\%F`.tar.bz2; uuencode ~/DBBackup.`date +\%F`.tar.bz2 DBBackup.`date +\%F`.tar.bz2 | mail -s "The new DB Backup" Sendtoemail@address.com; rm ~/DBBackup.`date +\%F`.tar.bz2
    I.e. three steps separated by semicolons: mysqldump; uuencode and send mail; delete the file once it has been sent. Hope this comes in handy.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts