Cygwin Rsync
Contents
Rsync Remote Backup
This page details how to backup a Windows XP machine to another Windows XP machine over the internet.
I have this configured in a Server and Clients scenario, that is the clients backup (or Archive in this case) to the server. Nothing is ever deleted off the server with the configuation I have enabled (a few hundred Gig I dont mind keeping just incase..)
Server End
(I'm assuming your running a Win XP box as the server)
Install Cygwin, ensure Rsync and OpenSSH packages are included.
Create a Windows account for the 'remote users' to use
Create a password file
Get openSHH running
Now assuming you have a little background with SSH and Linux servers, ensure you can connect and login to your 'server' from the internet. To circumvent some workplace firewalls - open port 443 to the world and configure (sshd.conf) sshd to listen on port 443
Configure Rsync
First you will need to create /etc/rsyncd.conf - heres an example that is configured to allow two directories (an the sub directories from there, to be backed up to F:\user1\Docs and F:\user1\Photos
use chroot = false strict modes = false log file = /var/log/Rsyncd.log [[user1_docs]] path = /cygdrive/f/user1/Docs comment = user1 Document Backup read only = false transfer logging = yes [[user1_photos]] path = /cygdrive/f/user1/Photos comment = user1 Photo Backup read only = false transfer logging = yes
Ensure the directories above exist before going further
Create a Services entry to run Rsync.exe as a servie. Ensure the service once created runs as an admistrator account and not SYSTEM as the file permissions of files created will get wierd.
Something like (assuming c:\cygwin\bin is part of the windows path)
cygrunsrv.exe -I "Rsync" -p /cygdrive/c/cygwin/bin/rsync.exe -a "--config=/cygdrive/c/cygwin/etc/rsyncd.conf --daemon --no-detach" -f "Rsync daemon service" -u Administrator -w password
Change the services file to specify port 873 as Rsync (windows and cygwin)
Try telnetting to 873 , if the connection isnt refused - success - remember the windows firewall will need to allow this service + port
Do not allow this port to be open to the internet - IT HAS NO SECURITY!!!
Client End
Get the folder / zip file I have uploaded Upload:Rsync.zip Rsync Client Rsync.zip 1.9Mb
Now this has all the files required for a Win XP / Win 7 desktop to SSH to yourserver, login, portforward 873 and start backing up directories.
Simply run tunnelandsync.bat
It will
- Start and Open a seperate SSH session window
- the seperate window will ssh to housedns.domain.com on port 22, once logged in
- it will port forward port 873 from the server to port 873 on the local machine (client)
- The user goes backto the orgional window now
- Hits a key and rsync is called firstly to backup 'c:\users\user1login\Document' to 'user1docs' dir on the server
- It will then quickly check to see it Rsync exited cleanly or not (successful or if there was a failure)
- It will then backup 'c:\users\user1login\Pictures' to 'user1photos' on the server
- It will then quickly check to see it Rsync exited cleanly or not (successful or if there was a failure)
- Prompt the window to gracefully exit the ssh connection window (type exit)
- and close
How to customise
Server
Rsyncd.conf - add more [[]] sections detailing other 'target' backup directories
Client
tunnelandsync.bat
- change housedns.domain.com to be you static IP or DNS name
- change the ssh port from 22 to 443 or other
- change the path and target settings
- user_name is the windows user the clients will ssh to the server using
- user1 is the client desktop username
- duplicate between 'Section 1 Start' and 'Section 1 End' and repeat for as many distinct directories you have to backup (ensure you change references to end1 to be endX in each section)
Ensure the rsync command is called with the '--chmod=+rwx' setting else, no one will be able to access the files that are backed up
tunnelandsync.bat
@ECHO off REM -- REM Open the tunnel and authenticate, port forward 873 so Rsync can connect. REM -- date /T >> log.txt ECHO ============================================ ECHO Welcome to the Windows Rsync file backup system ECHO ============================================ START "OPEN_TUNNEL" ssh -C -L 873:localhost:873 user_name@housedns.domain.com -p 22 ECHO Enter the password in the other screen, once successfully logged in continue ECHO N.B your logged in when the windows shows the following: ECHO user_name@server ~ ECHO . pause ECHO connected >> log.txt REM Duplicate Section 1 for the number of directories you plan to backup (if they dont have a common root) REM -- Section 1 Start REM -- REM Run the Backup REM -- REM Last folder of SRC (no trailing /) will end up named in DST REM -- REM OPTIONS ALLOW ALL [SRC] [USER]@[HOST]::[DST] ECHO ----- ECHO BACKING UP Documents ECHO ----- rsync -vrtzp --exclude='My Music' --exclude='My Pictures' --exclude='My Videos' --chmod=+rwx /cygdrive/c/users/user1_login/Documents user_name@localhost::user1_docs IF ERRORLEVEL 3 ( ECHO . ECHO . ECHO ====================================================================== ECHO ERROR 3 - %ERRORLEVEL% ERROR BACKING UP DOCS DIRECTORY NOT SUCCESSFUL ECHO Transfer error, please check the config file. ECHO ====================================================================== ECHO . ECHO . ECHO - ERROR - Documents DIRECTORY failed - %ERRORLEVEL% - >> log.txt GOTO end1 ) REM 0 == Success IF ERRORLEVEL 0 ( ECHO . ECHO . ECHO Transfer succeeded! ECHO . ECHO . ECHO DOCS DIRECTORY Successful >> log.txt GOTO end1 ) REM UNKNOWN ERROR ECHO . ECHO . ECHO ================================================================== ECHO ERROR %ERRORLEVEL% ERROR BACKING UP FONTS DIRECTORY NOT SUCCESSFUL ECHO Unknown error, please check the config file. ECHO ================================================================== ECHO . ECHO - ERROR - DOCS DIRECTORY failed - %ERRORLEVEL% - >> log.txt ECHO . :end1 REM - Section 1 End REM pause ECHO ----- ECHO BACKING UP PICTURES DIRECTORY ECHO ----- rsync -vrtzp --chmod=+rwx /cygdrive/c/users/user1_login/Pictures user_name@localhost::user1_photos IF ERRORLEVEL 3 ( ECHO . ECHO . ECHO =============================================================================== ECHO ERROR 3 - %ERRORLEVEL% ERROR BACKING UP PICTURES DIRECTORY NOT SUCCESSFUL ECHO Transfer error, please check the config file. ECHO =============================================================================== ECHO . ECHO . ECHO - ERROR - PICTURES failed - %ERRORLEVEL% - >> log.txt GOTO end2 ) REM 0 == Success IF ERRORLEVEL 0 ( ECHO . ECHO . ECHO Transfer succeeded! ECHO . ECHO . ECHO PICTURES Successful >> log.txt GOTO end2 ) REM UNKNOWN ERROR ECHO . ECHO . ECHO ========================================================================== ECHO ERROR %ERRORLEVEL% ERROR BACKING UP PICTURES NOT SUCCESSFUL ECHO Unknown error, please check the config file. ECHO ========================================================================== ECHO . ECHO . ECHO - ERROR - PICTURES failed - %ERRORLEVEL% - >> log.txt :end2 REM - Section 2 End REM pause ECHO ========================================================= ECHO -- Type 'exit' in the other window and allow it to close -- ECHO ========================================================= pause ECHO Finished and logging out >> log.txt DATE /T >> log.txt REM replace ~ with what your ssh window displays when its open ECHO ========================================================== ECHO -- Do not worry about INFO - Warnings below this banner -- ECHO ========================================================== TASKKILL /T /F /FI "WINDOWTITLE eq ~" TASKKILL /T /F /FI "WINDOWTITLE eq OPEN_TUNNEL"