I have been looking at the issue of backups quite a lot recently. I am going to jump straight into the problem that I have faced:
Most webmasters used shared hosting on Linux servers but want to backup their webserver to their Windows computer.
It sounds like a pretty simple problem to be solved, but unfortunately there are very few methods available to perform a backup in this situation. Most solutions you come across will happily give you instructions to create a compact, archived version of your site and then save it back on your web server. This is all well and good, but what do we do with these? If the server fails we will lose the backups too!
Likewise, there are plenty of solutions that work perfectly if you are backing up onto a local Linux installation, but most people are running Windows and want to get a local copy of the backup on their own PC. These are the people who this tutorial is aimed at.
This tutorial is for people who wish to backup any particular path on their server. You need to have SSH access. You also need to be running Windows.
Cygwin is a program for Windows that emulates a Linux-like environment. It provides Windows users with a colllection of tools to perform various tasks commonly performed on Linux installations. This is the software we will be using. Visit www.cygwin.com and download straight from the homepage.
Next, run the setup.exe file you just downloaded.
At the introduction screen, click next then select Install from Internet and click next.
On the next screen, choose a directory to install Cygwin. Make sure you choose a path that doesn’t contain any spaces. A good choice is C:\cygwin. Then click next. The next screen will ask you where to store the installation files. You can set this to the same directory you chose for installation on the previous screen. Then click next.
One more screen will appear for you to choose your internet connection method. The default choice of “Direct connection” is usually fine. Cygwin will download a list of mirrors. Choose one that is close to you and then click next. It will take a few seconds to download the list of files.
The next screen is a bit busy and might seem confusing, but it just lists every application that you can install in Cygwin. By default they are grouped by category. You can click + next to each category to view the individual applications.
Click the View button at the top right of the screen and the view will change from “Category” to “Full.” This will allow us to select the specific applications we want to install.
We need to be careful which applications we choose here. Some will be chosen by default. Choose the applications listed below by clicking on the word “Skip” for each one. The word skip will change to the version number to signify it will be installed. The applications are all listed alphabetically.
The program will automatically choose any other files that are required, so just accept anything else that Cygwin chooses for you. Click Next to start download.
You may have to wait several minutes while the files are downloaded and installed (see below).
Once installation has completed click Finish. We now have a working installation of Cygwin in which to perform our backup.
Cygwin has now installed the tools to perform our backup. This is what our backup script looks like. It assumes that you have installed Cygwin in c:\cygwin. Save it as backup.bat so it can be executed.
@echo off C: chdir c:\cygwin echo set date format........................ echo ... echo ... echo ... echo ... rem get date, make if file name friendly FOR /F "tokens=1-4 delims=/ " %%i in ('date/t') do set d=%%k-%%j-%%i echo Running rsync........................ echo ... echo ... echo ... echo ... c:\cygwin\bin\rsync -aze c:\cygwin\bin\ssh firstname.lastname@example.org:/home/user/public_html "/cygdrive/d/bk/%d%"
So what does this script actually do? It connects to your server at example.com and backs up the public_html folder to the folder D:\bk. The folder name will be based on the date, for example D:\bk\2009-06-21.
Cygwin lists all your drives in a folder called /cygdrive. So the C: drive will be located in /cygdrive/c and the D: drive will be located in /cygdrive/d.
This is the line that you need to edit:
c:\cygwin\bin\rsync -aze c:\cygwin\bin\ssh email@example.com:/home/user/public_html "/cygdrive/d/bk/%d%"
Edit all these variables as is necessary.
Since you have saved the file as a backup.bat file, you can simply double-click it in Windows and it will execute. Ensure your backup directory exists and double-click backup.bat to execute it.
The way the script is setup, it will always ask you for your SSH password. It is possible to set up your server so SSH access is always granted.
You can use the Windows task manager to execute your backup regularly.
Let me know how you get on with it or if you run into any problems.