Last week I had an interesting problem - how to sync two directories on two different servers in an automated and secured fashion. I remembered Hal using the rsync command to do this once before. A 5 minute Google search turned up exactly what I needed.
If server1 has a folder called foo that you need to sync with a folder called foo-copy on server2, use this command on server2:rsync -ave ssh --delete server1:/foo /foo-copy
This command will invoke the rsync program on server2 to make a connection to server1 via ssh (so it is encrypted), and synchronize the folder "foo" with the local folder "foo-copy". The "--delete" tells it that if a file was deleted on server1/foo to also delete it on server2/foo-copy.
Stick this in a small script called by cron and you have a quick and simple automated method to sync up directories on multiple servers.WORD OF CAUTION - The command above includes the --delete option, which will delete
files on the target so that it perfectly matches the source directory. Be careful
that you run the command from the correct directory (in this case the target directory)
or you could delete all your files!
Saturday, January 19, 2008
rsync over ssh
Posted by
Robert
at
12:18 PM
Labels: linux, systems administration, unix
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment