Saturday, September 16, 2006

Rsync on Windows

When several computers are networked together, you can take advantage from this - you can setup rsync to synchronize data between computers. This can be particularly useful when you want to sync laptop with desktop

Note: Maybe this tutorial is over-verbose, but i'm used to assume nothing from the _user_.

I'll be talking about Rsync usage in Windows... Although i am currently writing this in Vim editor under Linux.

After you have them installed, follow the following steps:

First, you have to install both cwRsync packages from here . After you have them installed, modify the batch source below to suit your needs. :)
Don't worry, the batch file example is reasonably commented and places that have to be changed are marked by "CHANGE HERE" lines

-------Start Batch example-------

:: This is first to suppress command themselves echoing to the screen

:: Make environment variable changes local to this batch file

:: This command specifies directory cwRsync is installed to
:: Specify different path if different from default

:: Set CYGWIN variable to 'nontsec'. That makes sure that permissions
:: on your windows machine are not updated as a side effect of cygwin
:: operations.
SET CYGWIN=nontsec

:: Set HOME variable to your windows home directory. That makes sure
:: that ssh command creates known_hosts in a directory you have access.

:: Make cwRsync home as a part of system PATH to find required DLLs

:: Example : C:\WORK\* --> /cygdrive/c/work/*
:: Example 1 - rsync recursively to a unix server with an openssh server :
:: rsync -r /cygdrive/c/work/ remotehost:/home/user/work/
:: Example 2 - Local rsync recursively
:: rsync -r /cygdrive/c/work/ /cygdrive/d/work/doc/

:: Simple menu for choosing synchronization direction

:: You are free to change the computer's name from Foo to something more sensible
:: Do one search and replace run on this menu.
echo 1. Retrieve Wiki from Foo
echo 2. Send Wiki to Foo
CHOICE /C:12 /N Make your choice:

:: You must replace paths, IP adresses and usernames
:: An explanation for the clueless:
:: Replace user with user which was defined in secrets file
:: Replace IP with, well, Foo's IP adress
:: Replace path with your path
:: Note about cygwin's path: It consists from /cygdrive/x/Path
:: where x is your drive's letter, eg C drive
:: Another thing to note about UNIX paths in general
:: is that they use forward slashes, not backslashes
:: EG, C:\Windows\system32 in this format would be /cygdrive/WINDOWS/system32
:: Yet another difference is that path names are CASE SENSITIVE,
:: Meaning that Doc, doC and doc are three different filenames


rsync --del --progress -av "/cygdrive/c/Place/That/Needs/To/Be/in/sync/" user@


rsync --del --progress -av user@ "/cygdrive/c/Place/That/Needs/To/Be/in/sync/"

:: Here are the explanations of command line flags
:: used (taken from manual of course :):
:: -a, --archive archive mode; same as -rlptgoD (no -H)
:: --del an alias for --delete-during
:: --delete-during receiver deletes during xfer, not before
:: -v, --verbose increase verbosity
:: --progress show progress during transfer

echo -----------------
echo I hope the sync was succesful! :-)

-------End Batch example-------

When you're done with that batch file, you should save it as C:\Program Files\cwRsync\sync.bat and you're done with the client part...

The daemon (server, service) part needs two files for configuration:

rsyncd.conf and rsync.scrt

The first file contains configuration, folders for sync et cetera.

Rsyncd.scrt contains plaintext pairs of usernames/passwords. You can name rsync.scrt whatever you want to, as long as you don't forget to update pointer in rsyncd.conf.

-------Start rsyncd.conf example-------

use chroot = false
strict modes = false
hosts allow = *
log file = rsyncd.log
pid file =
secrets file = rsync.scrt

path = /cygdrive/c/The Place/Docs
read only = false
auth users = user
transfer logging = yes

-------End rsyncd.conf example-------

-------Start rsyncd.scrt example-------


-------End rsyncd.scrt example-------

These configuration files must be unique for both hosts. I.e., 1 host must target 2nd host in batch file, et cetera.

When all of the configuration is done and config files are in place... start the daemon:


sc config RsyncServer start= auto
net start RsyncServer

(Enter this to cmd prompt...)
(no, the weird space in "start= auto" is NOT a typo. That's actually correct syntax... Duh)

Or, if you prefer the tedious rodent-GUI way:

Go to Start>Settings>Control Panel>Administrative tools>Services, find RsyncServer, go to properties, make startup type automatic, start it.

When finished, launch that "sync.bat" or whatever you have named it, and it should give you a proper mini-menu for choosing synchronising direction. Enter the choice number, and the synchronisation shall commence... Happy synching :-)

Edit (2006-09-20): Sorry, the "choice" command isn't included in Win2k/XP by default; It is part of Microsoft's NT Resource kit... Choice.exe can be downloaded from here. Put it to C:\(Windows|WinNT)\system32 or to directory where is that rsync script located (folder where CwRsync is installed)

Thursday, September 07, 2006

Mysteriously unreachable websites

Today i solved a great annoyance i had for a loooong time... I couldn't access quite many websites: (No, i am NOT an ubuntu user. It is just that that i couldn't reach their website)

and a whole lot of other domains. I have regarded it as mystery and blamed ISP for that... Until today.

Today, i decided to look at them more closely and my quest was to find similarities between these hosts.

The whole log of how did i diagnose and fix it (maybe oververbose as always):

#This is my router box running Slack10.2
#First, i tried to nslookup and then follow the packets
root@EN6350:/var/log# nslookup

Non-authoritative answer:
root@EN6350:/var/log# traceroute
traceroute to (, 30 hops max, 38 byte packets
1 ( 2990.280 ms !H 2993.109 ms !H 2999.948 ms !H
root@EN6350:/var/log# traceroute
traceroute to (, 30 hops max, 38 byte packets
1 ( 2995.091 ms !H 2990.231 ms !H 2999.924 ms !H
#This is fake /|\, my gateway's ip is different
#nslookuping once again, to see possible similarities
root@EN6350:/var/log# nslookup

Non-authoritative answer:
root@EN6350:/var/log# nslookup

Non-authoritative answer:
root@EN6350:/var/log# nslookup

Non-authoritative answer:
#So, strangely, all of nonreachable hosts are in netmask.
#Let's look at route and iptables
root@EN6350:/var/log# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface * U 0 0 0 eth0 * U 0 0 0 eth1
loopback * U 0 0 0 lo
default UG 1 0 0 eth1
# route causes all packets sent to some ip address which starts with 82, be sent to null
#So i will delete that route.
root@EN6350:/var/log# route del -net netmask dev eth1
#Now, let's try tracerouting packets
karolis@EN6350:~$ traceroute
traceroute to (, 30 hops max, 38 byte packets
1 ( 8.700 ms 10.213 ms 9.128 ms
2 ( 62.339 ms 40.145 ms 9.255 ms
3 ( 10.151 ms 10.296 ms 9.614 ms
4 ( 13.482 ms 12.103 ms 14.310 ms
5 ( 232.569 ms 237.165 ms 159.932 ms
6 ( 196.053 ms 362.947 ms *
7 ( 285.953 ms 361.452 ms 242.792 ms
8 * ( 484.540 ms 282.054 ms
9 ( 249.593 ms 141.258 ms 261.868 ms
10 ( 356.662 ms 210.328 ms 298.223 ms
11 ( 91.372 ms 290.529 ms 276.604 ms

So i solved this problem only after about a year since it appeared... Because I couldn't imagine why those sites wouldn't work. But it's better later than never, I guess