OK, I have been very bad at posting here for a few weeks. It’s because quite a lot has been happening (to be revealed…)
Don’t worry though, I haven’t had Swine Flu…
OK, I have been very bad at posting here for a few weeks. It’s because quite a lot has been happening (to be revealed…)
Don’t worry though, I haven’t had Swine Flu…
This was done at Odenplan on the Stockholm Metro as viral advertising for Volkswagen.
Pretty cool!
Millions of websites are hosted on Bluehost, probably the biggest provider of shared hosting. One issue is that they do not guarantee backups of your data and anyway my hosting accounts always get too big for them to backup anyway.
Since Sunday, I have had a real scare that the server was down for about 24 hours and I didn’t know if I would have any data to come back to. Luckily, last week I made a backup of everything including the databases, so I would have been OK, but it was the first time I had backed up in 3 months so I was lucky.
Time to set up an automatic backup program!
The issue is that every time you run a backup, you need to enter the servers password which means that it is difficult to automate. To get around this you need to use RSA key authentication. Unfortunately, that is easier said than done and it’s difficult to find out how to set this up on Bluehost. I spent hours learning how, so I thought I would show here how you can set up automatic backups in less than 5 mins…
Setting up your keys:
(First make sure SSH is activated on your server, you can do this through CPanel on Bluehost).
On your client machine (assuming you are backing up to a linux box):
Open a terminal and type…
ssh-keygen -t rsa
It then asks you to enter a file in which to save the key. Just type in the filepath you want to use, I would suggest this: “/home/YOURLINUXMACHINESNAME/.ssh/my_server
Press enter.
It then asks you for a password for that key. As you want to connect automatically, just press enter twice to accept no password.
You will get some feedback that the key was successfully generated.
Now, in the terminal again type:
sudo gedit /home/YOURLINUXMACHINESNAME/.ssh/my_server.pub
Enter your linuxbox password and you will see a text editor with the full key!
Now, go over to Bluehost and use file manager to go into the root of your account. Create a folder and call it “.ssh” (with the dot).
Now in that folder create a file called “authorized_keys”. Edit that file and paste in the full key that you created from the client. Copy in the full file including any comments etc. Save the file on Bluehost.
That should be you good to go!
Test
Do a test by opening a terminal on your client machine and type:
ssh username@domain.com
See the command prompt for your server without being asked for your password? Congrats!
Download your files and backup your databases!
All you need now is a good backup program that will even backup your databases. Even better if it only downloads the things that have changed on your website instead of downloading all 100Gb of junk you have on there every time!
Try this one for size! (save it as a .sh and enable it to be run as an executable)
Remember and add your client IP address to the MySQL whitelist in Bluehost in order to back up your databases.
#!/bin/sh
### Edit Me ###
yourlogin=”somebody”
yourpass=”secret”
yourdomain=”example.com”
backups=”/mnt/somewhere/”
databases=”drpl1 copp1″
### Edit Me ###
old_cd=”$(pwd)”
cd “${backups}”
rsync -aHvcz –delete –progress -e ssh ${yourlogin}@${yourdomain}:public_html . # <– note the trailing dot “.”
for db in $databases
do
mysqldump -h ${yourdomain} -u ${yourlogin} -p${yourpass} ${yourlogin}_${db} >${db}.sql
done
cd “${old_cd}”
exit 0
######
Thanks to Homer on the Bluehost forum for this script.
Now you just have to set up a cron task to run this script once a day, or once a week or however often you want.
This took me a while to work out, so I hope it helps some others get there quicker. Once it’s up and running, it really works great!