Page 1 of 1 1
Topic Options
#176827 - 2007-06-08 01:04 PM Synchronising folders on different servers
Verne Offline
Fresh Scripter

Registered: 2006-02-13
Posts: 19
Loc: United Kingdom
Hi. A project I am working on has a web site running on two servers which are network load balanced. Admin users upload files through the web site which will be held locally on the web server. They could be uploading to either server. I need some way to synchronise these files so they are the same on both servers. I was looking at robocopy but I don't think it can do it. It seems to be geared up to having a source and a destination rather than copying in both directions.

Anyone come across this problem before and know a solution?

Thanks.

Top
#176828 - 2007-06-08 02:01 PM Re: Synchronising folders on different servers [Re: Verne]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
The simplest solution is to get the users to upload to an "upload" area, then use ROBOCOPY (or whatever) to copy/move the files to the target areas on both servers.

The users can still upload to *either* server.

Doing it this way means that you will never be trying to synchronise the two target areas - always a major headache.

Another solution is to have the common area on a highly available solution, like a SAN or NAS.

There are synchronisation tools around - for example you can get ports of the Unix RSYNC tools from various places, but depending on your requirements you may find that these introduce complications, dependancies and management problems that make them impractical.

Personally I'd advise you to stick with the simple options.

Top
#176829 - 2007-06-08 02:13 PM Re: Synchronising folders on different servers [Re: Richard H.]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This should work. It requires the DirPlus() - a recursive dir tool UDF.
I'm sure there is a shorter way. This is a quick and dirty solution.


 Code:
Break on

$upload = "\\server\share\"
$server1 = "\\server1\share\"
$server2 = "\\server2\share\"

;returns a list of files in the upload folder.
$upload = dirplus($upload,"/a-d")

For Each $file in $upload
	;check if the file allready exists on server1.
	If Exist ($server1 + $file.name)
		;make a backup if the file exists then copy the new file.
		Copy $server1 + $file.name $server1 + "backup\" + $file.name
		Copy $file $server1 + $file.name
	Else
		;copy the file.
		Copy $file $server1 + $file.name
	EndIf
	;check if the file allready exists on server2.
	If Exist ($server2 + $file.name)
		;make a backup if the file exists then copy the new file.
		Copy $server2 + $file.name $server2 + "backup\" + $file.name
		Copy $file $server2 + $file.name
	Else
		;copy the file.
		Copy $file $server2 + $file.name
	EndIf
Next


Edited by Mart (2007-06-08 02:14 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#176831 - 2007-06-08 03:14 PM Re: Synchronising folders on different servers [Re: Verne]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
I'd create a net share to hold the files, and simply point a virtual folder on each web instance to that place. Simple, and no sync issues at all, but this isn't always feasable.

If you have to maintain duplicate data sets, look into Unison, which is a bi-directional synchronization tool. I've had great results integrating it into Kix scripts, and it would be perfect for a situation like yours, where files exist in one place but need to be in two (or more) places. This can be fully automated. If files are MODIFIED, it gets a bit more tricky, but still possible with this tool.

Cool thing about Unison (besides being open-source) is that it works across platforms, and can ride over SSH tunnels to sync servers between different security zones.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 641 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.052 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org