How to Backup your Website Automatically with cPanel

July 26th, 2009 · 14 Comments

In my last post, I released my Simple FTP Backup Script (v0.9b). This Perl script allows you to perform a backup of your files and MySQL databases as well and upload it to a remote FTP server (read this post for some FTP backup services).

Since the release of this backup script, I’ve made some small adjustments to some minor preference parameters you can now set. Click here to download the Simple FTP Backup Script v0.9c

How to a Schedule a Backup Task using cPanel

This tutorial has been written assuming you’ve already got a remote ftp storage. I will be using my BlueHost control panel (cPanel) so yours may look slightly different.

  1. Rename the backup script file name to “ftp-backup-script.pl” and upload it to your website account through FTP. Make sure you’re uploading it in a non-public folder if possible. If not, make sure to protect this directory so that nobody else invokes the script from a web browser. Personnally, I suggest you create a directory at the same level as /public_html
  2. Use your web browser to access cPanel (http://www.yourwebsite.com/cpanel).
  3. Click the Cron Jobs icon :

    BlueHost cPanel - Cron Jobs

  4. On the next page, click the Standard button.
  5. Enter the command to run :

    /usr/bin/perl /path/to/backup/script/ftp-backup-script.pl

  6. Scheduling the task like shown below would run the backup script once a day at 3 AM :

    BlueHost Cron Jobs

  7. Hit the Save Crontab button and you’re done!

If it doesn’t work, try the following :

  • On the Crontab page, enter an email address where the cron output will be sent to. This might give you valuable information as to why the backup task didn’t run properly.
  • Try setting the permissions on ftp-backup-script.pl to 0755
  • Make sure the path to Perl is /usr/bin/perl. In case you don’t know, contact your web host’s support.

Stay tuned as I’ll show you how to schedule daily, weekly and yearly backup tasks.

Links

14 responses so far ↓

1. Response by : Damon Flowers on Aug 20, 2009 at 11:28 pm

Hey, thanks a bunch for posting your backup script… I just dropped it in and it works well (I’m on the same host as you), but couldn’t get the ftp piece to work (pointing to drivehq)…keeps saying connection timed out. My perl skills are a bit rusty, so may try debugging later.. If there is an easy suggestion for debugging, please let me know.. Thanks again for posting!

2. Response by : The Web Hosting Hero on Aug 21, 2009 at 7:23 am

Perhaps you may want to try using the IP address of your FTP server?

3. Response by : The Web Hosting Hero on Aug 21, 2009 at 7:24 am

(I meant using the IP address instead of the FQDN)

4. Response by : Damon Flowers on Aug 22, 2009 at 2:23 pm

Hmm, tried the IP as well as a different ftp site altogether, but continue to get a Connection Time Out error. I changed the Debug => 5 on line 78, hoping that would provide more info, but it didn’t.. Strange that yours works at bluehost and mine doesn’t..

5. Response by : Andy Clark on Sep 1, 2009 at 9:07 am

Great script, thanks. Worked first time with no problems :-) Would it be easy to add the time (as well as the date) to the file name that is created, we want to run the cronjob a couple of times as day without overwriting the file name? Thanks.

6. Response by : ali on Sep 28, 2009 at 6:10 am

can not extract mysql.gz with cpanel , says not a gzip file ??

7. Response by : The Web Hosting Hero on Sep 28, 2009 at 6:25 am

@ali: have you tried extracting the content locally to your pc to make sure the archive is not corrupted?

8. Response by : ali on Sep 28, 2009 at 6:33 am

I just loged in ssh and tried on remote machine

gunzip mysql_databases-28-8-2009.sql.gz

gunzip: mysql_databases-28-8-2009.sql.gz: not in gzip format

9. Response by : The Web Hosting Hero on Oct 2, 2009 at 7:14 am

@ali: What is the size of the file? Is it null?

10. Response by : ali on Oct 2, 2009 at 7:32 am

I solve it now.

in script I choose backup ALL DB..

that should be no so I create a user and assign it to all DB.

that fixed..

11. Response by : eric on Nov 25, 2009 at 6:29 pm

I tried to ftp the full bakcup file, form hostmonster to drivehq, but even with time out of 300 it’s still getting time out, what should the problem be..?

12. Response by : The Web Hosting Hero on Nov 27, 2009 at 8:08 am

Do you have an idea what is the approximate size of your website?

13. Response by : Tony on Mar 31, 2010 at 9:07 am

Will this back/restore also work if Innodb is place?

14. Response by : The Web Hosting Hero on Mar 31, 2010 at 9:16 am

@Tony : if there are some foreign key constraints, you’ll have to add this line manually at the beginning of the SQL dump file :

SET FOREIGN_KEY_CHECKS=0;

And also add this line at the very end of the same file :

SET FOREIGN_KEY_CHECKS=1;

Hope this helps.

Leave a Comment




 

Top 10 cPanel Web Hosts

InMotion Hosting - $5.95
WebHostingHub - $4.95
JustHost - $3.45
HostGator - $4.95
GreenGeeks - $4.95
DowntownHost - $7.95
HostDime - $18.33
HostMonster - $5.95
BlueHost - $6.95
10 Arvixe - $4.00
 
 
 
 

Tutorials by Category

 
 

Recent Comments

 
© Copyright 2010 - TheWebHostingHero.com