If you are hosting your own website(s) or if you are hosting websites for customers, do you have an actual offsite copy of each website in case disaster strikes? Imagine your backend web host/data center/colo going belly up. Imagine a non-recoverable web server crash and a set of outdated backups that are 3 months old. Such a situation is not sexy. Entire businesses have been wiped out due to the lack of a having a good backup copy.
I recently added 2 additional VPS (Virtual Private Servers) to my own portfolio and once everything was configured to my liking, I went on to get those 2 VPS added to my remote backup strategy. In the past I have been using BQBackup, but since I am writing a lot about web hosting I decided to use this opportunity to a) try a new backup service and b) to go into more detail how you can setup your own remote backup solution.
First of all, I like to reiterate how important it is to have an offsite backup copy of all your important data – be it business or personal data. Anything that you need to restart your personal life in case your house or apartment burns down would be considered critical and you should have copies offsite. In regards to your business – if your data is critical for you to earn money, then it needs to be backed up. If data is critical to bring your business back from a disaster, then it needs to be backed up. And if data is worth a backup, then you should not only have a copy onsite eventually, but definitely have a copy offsite. So, as mentioned I just added 2 new VPS servers to my infrastructure and I implemented a different remote backup solution. Here is what I did in detail.
I signed up with a different remote backup service to diversify my setup. For me it is important not having “all eggs in one basket”. After doing some research I decided to go with the Webbycart Remote Backup solution. If you do a search on Webhostingtalk.com you will see that Bobby from Webbycart is a very active and respected member in the forums. In addition I got lucky and was able to sign for a new account using one of their promotions and so it was a great deal for me. Initially I had problems getting my order completed as apparently the sign-up emails bounced back and got caught in a SPAM folder. I contacted Bobby directly through the forums at Webhostingtalk.com and we straightened it all out very quickly.
Important: This type of solution only works if you have root access to your system. You can make it work with reseller accounts too, but you will need additional software or scripts to achieve the same results. I am not going into too much detail on 3rd party software or scripts for now (maybe in a follow-up article down the road). This remote backup tutorial is about using Rsync to backup your system to the remote backup service account. Rsync is a copy or synchronization software that syncs data between 2 locations on Unix and Linux systems. In my case I want to use Rsync to backup/sync my cpanel backups to the Webbycart remote service. Cpanel/WHM makes daily backups of all websites on my 2 VPS (Virtual Private Servers). From there Rsync will maintain a daily updated copy for disaster recovery purposes. Important: The instructions below will work with most remote backup services that allow Rsync.
To make this work we need to establish authentication between each VPS and the remote backup account. In addition we need to setup a cronjob that executes the Rsync command. I also want the Rsync job to email me so that I know it executed properly. Here are the steps in more detail:
1) Create the RSA authentication key to make sure that only this server or VPS can log into the remote backup account. Log into your server or VPS via SSH. Switch to the root user. 2) Next we need to check if your system already has an existing RSA key. Run the following command:
If you already have a valid RSA key on the system you will see a cryptic number/letter screen output. If the key already exists, ignore the next step. 3) Now let’s create the RSA encryption key by running the following command:
ssh-keygen -t rsa -N ” (please note: these are 2 single quotes at the end of the command)
4) Now that the key has been created, we need to copy it to the remote backup account. Execute the following command:
scp ~/.ssh/id_rsa.pub [email protected]:keys/serverinstance (please note that the information for your account needs to be provided by your remote backup web host)
5) Depending on how many servers of yours copy data to this specific remote account, you will need to merge the RSA authentication keys into a single file. Execute the following command:
ssh [email protected] keymerge
6) That’s it for part 1. If all went well you have setup the authentication piece between the server/VPS and the remote backup service account.
In these steps we have not really touched Rsync by itself. What we did was to setup authentication between the source and the target. By using RSA authentication the source server can safely login to the remote backup account without the need for a user ID or password. In addition, by requiring RSA authentication we make sure that nobody else can login and access the data. Now we will configure Rsync on the source server and setup a cronjob, too. Ideally this is actually done in one single step. I am going to show you the command for backing up the cpanel backups (default location).
1) Unless you are still connected to your server, log back into the server via SSH and switch to the root user. 2) Execute the following command
echo “0 15 * * * root rsync -avz -e ssh /cpbackup [email protected]:targetfoldername” >> /etc/crontab
The command above enters a cronjob to the crontab file. This cronjob executes at 15 minutes past minute every single day and will use rsync to synchronize the cpbackup folder to your remote backup account. By default on a Unix or Linux system the cronjob will send an email to the server admin (if that setting is correctly configured). You can open the crontab file and check for the mail entry accordingly.
That’s it. Just check for the email once the rsync job completes and make sure to check that this solution is working accordingly. As an example if you misspell the source backup folder the email error message might look something like this:
sending incremental file list rsync: change_dir “/backup” failed: No such file or directory (2)
sent 18 bytes received 12 bytes 8.57 bytes/sec total size is 0 speedup is 0.00 rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
If you are interested in setting up such a backup solution, I highly recommend WebbyCarts Remote backup solution. The implementation was super easy and Bobby was super helpful in getting me going.