{ 36 comments… read them below or add one }

Joe Hernandez March 17, 2009 at 7:28 AM

Will,

Excellent job with the explanation. I didn’t realize it was so easy to backup your files. Going to have to try this. Recently I upgraded my phplist through Fantastico, and it caused major havoc. This would have come in handy. I was able to get it restored, but what if I hadn’t.

Thanks.

JdotA April 13, 2009 at 10:39 PM

Thanks again for the great info. I am on OSX and I cannot find an app like AutoFTP to pull down a specific file type. I can use Automator to pull the contents of a folder but if I use that, Automator tries to pull all of the files in the home directory. But since HostGator does not let you change the save location I have to try find some other way of doing it. Any info that you might have would be of great help!

Wilson Mattos April 13, 2009 at 10:58 PM

@JdotA: Here is what you can do to get around this problem:

1. Create a folder in the root directory called “backupfolder”

2. Create a cron job as shown in the video with the following command: mv ~/*.gz backupfolder

3. Make sure you schedule this for about 30 minutes or so after the backup runs to make sure you backup completes before this runs.

What this will do is use the Linux/Unix “mv” command to move the backup file from the root directory to the “backupfolder” so your FTP client can just download those files.

Don’t forget to also remove the files from the server, otherwise you will eventually run out of disk space and if your FTP client is not smart enough to realize that the old files have already been downloaded, each day your downloads will take longer as more files will get downloaded.

Wil

Adam April 14, 2009 at 12:14 AM

I automate my backups to amazon S3 using s3sync. I have a tutorial to it in the url i left ^

Wilson Mattos April 14, 2009 at 12:23 AM

@Adam, thanks for the link (click on Adam’s name above).

Looks like your s3sync solution can easily be used with the tutorial I show here in order to only have 1 file to upload.

In looking at your script, I learned something VERY cool that I was not aware of….the mysqldump switch to dump all existing databases at once. VERY cool!

Wil

JdotA April 14, 2009 at 7:08 AM

Thanks for all the info. I am setting it up right now, will post the results later today!

JdotA April 14, 2009 at 7:13 PM

After trying a few times, I am still not having much success. The cron job that backup the site is not running no matter what i try. I tested cron by using the mv command above and that worked fine so cron is functioning. Its just not generating the backup. Any other ideas? Thanks.

Wilson Mattos April 14, 2009 at 9:43 PM

@JdotA Here are a few things to check:

1. Did you leave the USERNAME and PASSWORD in the cron command inside quotes? You should surround those values with quotes (the video does not show this, but the example code does). This is required in case you have special characters such as “&,?,” or others in your password.

2. Did you copy and paste the the backup.sh script exactly as above? The entire script is one single line. If you pasted it elsewhere and used another text editor then uploaded the file, that may be your issue. Make sure you create the file exactly as I showed on the video using cPanel so that there are no special characters (line feeds, carriage returns, etc) in the file. Copy the code, go into the cPanel editor and paste the whole script exactly as it is show in the sample code above.

Wil

JdotA April 14, 2009 at 11:33 PM

@Wil Checked both and they are fine, Username & Password each inside their own set of quotes and email without quotes. The script was copied directly from this page. Does host gator require any special permissions in order to run the scripts?

Wilson Mattos April 14, 2009 at 11:53 PM

@JdotA No, Hostgator does not require any special permissions.

Can you double check the file name of the script your created? Is the file called backup.sh?

Is it in the root directory of your account? (at the same level as the public_html directory, not within it, for example)? Can you post a screen shot of your directory somewhere and send me a link on Twitter?

Also, the filename is case sensitive, as is your username and password.

Wil

JdotA April 15, 2009 at 9:32 AM

Success!!!! It looks like there were a couple of things causing the backup to fail.

1st: After I pasted and saved the script into the HostGator text editor, some of the “-” were being auto converted into the ascii code for the symbol “–”. The only ones that actually changed were the first “-” in the following: “–http-user=$1″ , “–http-password=$2″ and in “–post-data=”. So I disabled the auto Disable Character Encoding for the HostGator text editor and then it saved correctly.

After that I finally started receiving error msgs when the backup was run. I had not been receiving any msgs before this.

2nd: Once I received the error msgs, I looked up a list of options for wget and realized that I needed to have “–” instead of “-” in front of “–http-user=$1″ , “–http-password=$2″ and in “–post-data=”. Once I made those changes the Backup was successful!

Thanks for all your help and the tutorial!

Wilson Mattos April 15, 2009 at 10:27 AM

@JdotA I see what happened. The problem was with WordPress. It converted the -- into — above, so when you pasted it, it cause the problem. I have hard coded -- in the above example, so this will no longer happen to anyone else. Thanks for the update and congrats on getting this going! Now you can sleep better at night knowing your data is safe!

Eric Nagel July 4, 2009 at 6:21 AM

So many people think their hosting provider backs up their data… it should be standard, but many have found out the hard way, isn’t.

I have my FTP or Amazon S3 server backup script available for free on my webiste. It’s configured for GoDaddy, but can be changed for any dedicated server.

Wilson Mattos July 4, 2009 at 2:14 PM

Eric, thanks for posting a link to your script!

Paul September 7, 2009 at 8:10 PM

Hey Will

Excellent info.
Q? Will this backup include Add on Domains and/or Subdomains?

Thanks
Paul

Wilson Mattos September 7, 2009 at 9:03 PM

Paul,

Glad you enjoyed it. To answer your question, yes, this process will back you entire account (including all the data). Since add-on domains are simply folders inside the public_html directory, it will indeed back those up.

You can see this by downloading the backup file and extracting it on your local machine, so you can see all the data.

Wil

Jason September 21, 2009 at 11:29 AM

I cant get this to work no matter what i try…i followed you instructions perfectly, and the script never executes.

Jason September 21, 2009 at 11:38 AM

I finally got emailed this from the script :

/home/********/backup.sh: line 1: {rtf1ansiansicpg1252deff0deflang1033{fonttbl{f0fswissfcharset0: command not found
/home/********/backup.sh: line 1: }}: command not found
/home/********/backup.sh: line 2: {*generator: command not found
/home/********/backup.sh: line 2: }viewkind4uc1pardf0fs20: command not found
/home/********/backup.sh: line 3: syntax error near unexpected token `}’
/home/********/backup.sh: line 3: `}’

Wilson Mattos September 21, 2009 at 11:42 AM

@Jason,

Please copy the scripts again from above and recreate on your server. It looks like my new template messed up the double quotes and I had not noticed. This is probably the issue. They are fixed now.

Sorry for the trouble you had with it. Let me know how it goes.

Wil

Wilson Mattos September 21, 2009 at 11:48 AM

@Jason,

Do what I suggested above (recopying the scripts), but this is a different problem all together. In the video I showed you how to use the file editor in cPanel. It looks to me like you pasted it into MS Word or some other word processor and then uploaded because my script is one single line (not 3) and those commands it is complaining about are control characters that your word processing application is adding in. Please delete the scripts on your server and try again using the cPanel web-based file editor as shown in the video.

Wil

Jason September 21, 2009 at 11:58 AM

Thanks for the reply, i will try it through the Cpanel text editor…but it is asking what character encoding i want to use and i dont know what to select…sorry, im not a programmer.

Wilson Mattos September 21, 2009 at 12:17 PM

@Jason,

Just use the default setting for character encoding in the cPanel text editor, which is probably UTF-8.

Wil

Jason September 21, 2009 at 12:21 PM

I am now being emailed this error :

wget: missing URL
Usage: wget [OPTION]… [URL]…

Try `wget –help’ for more options.

Jason September 21, 2009 at 12:55 PM

Ugh…i am SO close i can taste it…been trying to do automated backups for 2 weeks and just cant get it. I think this site is the answer though.

Wilson Mattos September 21, 2009 at 1:08 PM

@Jason,

Make sure the entire script is on one line. Open two browser tabs and copy the script from above and paste it into the editor. Do NOT paste it anywhere else first the copy/paste again.

Wil

Jason September 21, 2009 at 1:15 PM

Thats exactly what i did…i copied it directly from this page into the cpanel text editor.

Jason September 21, 2009 at 1:25 PM

Let me try using IE instead of Firefox.

Jason September 21, 2009 at 1:27 PM

That didnt work either, when i did all the copying in IE, it just emailed me a blank email. I think im just gonna give up.

Wilson Mattos September 21, 2009 at 1:31 PM

@Jason,

Sorry it is not working for you. A LOT of people have used this procedure and got it working without hitches. I am not sure why it is not working for you. When you create the cron job, are you leaving the double quotes in place? If you want to download and zip the two files (change you password in the files, of course), I will be glad to look at them for you. Just upload the zip file to a web accessible directory and post a link here…(I won’t approve the comment to nobody will see your URL).

Wil

Jason September 21, 2009 at 1:33 PM

I would be happy to send them to you…but which 2 files…i know you need the backup.sh but what is the other one? Thank you so much for helping me get this going.

Jason September 21, 2009 at 3:11 PM

Wow, it finally worked…thank you so much for your help with this. I was wondering….can this script be modified to only backup the public_html folder and NOT the entire home directory? I ask this because Hostgator caps Cpanl backups at 50,000 inodes. I had to whittle my site down a LOT to get it below 50,000. Once a site hosted by Hostgator reaches larger than 50,000 inodes, they wont allow full site backups anymore. So if this script was able to backup only the public_html folder, that would help the size limitation. Can this be done?

Wilson Mattos September 30, 2009 at 10:58 AM

@Jason,

This particular method is used for full cPanel backups. You can create a script that only backs up a certain directory and create a cron job to run that on a schedule. That’s pretty simple. The issue is that it will not get the MySQL backups, which the full backup does, so you would have to do something different to get the MySQL backups for each of your databases.

Wil

Malcolm December 15, 2009 at 6:02 AM

Excellent. Worked for me first time. No doubt you have saved my life, at some point in the future

Shaun Baird February 18, 2010 at 7:31 AM

Well this really IS a fantastic link, given to me by your friend May. I have been searching for an answer and it’s only thanks to dedicated people like this that people like us can breathe at night!

Funny really because some marketers rely on dozens if not hundreds of websites for their full time income, and at any point in time their site and income could be dropped at any time. This HAS happened to me 2 or 3 times in the past years so folks, bite the bullet and just do it.
Shaun

Flavius April 3, 2010 at 11:03 AM

I’ve ruin my website with jom sef … so the siteis having some problems…
I have backup my website exaclty like in this tutorial , i have the backup , if i ask the admin from hostgator to do a restore will hi be able to doi’t ( sorry for my english ) ? or what/how should i ask ? i need help pls …

If this help someone – it erase the archives older then 6 days …

find /home/username/ -name ‘backup-*’ -mtime +6 -exec rm {} \;

Wilson Mattos April 7, 2010 at 12:17 AM

Flavius,

Yes, if you ask the admins at Hostgator, they should be able to restore the backup for you. Their helpdesk is really good!

Wil

Leave a Comment

Next post: