Using Unison File Synchronizer
I have had to setup a new web server recently to separate the database from the app server and to place the web server in the DMZ. The developer that maintains the code will not have direct access to the server in the DMZ, so I had to come up with a way for him to make changes to the code and send it to the web server. My first thought was to use rsync
but that can be a nightmare to setup. That is where Unison comes in to take care of the sync.
Unison can sync folders over ssh which is what I needed since the only ports open to the DMZ are ssh and database ports from the database server.
I am going to walkthrough a simple setup to sync to folders. More detailed information can be found in the user manual from the link provided.
First,Install Unisonsudo apt-get install unison
Next,Let's sync folder */a*
* and folder /b*
*.*Command: **unison root1 root2unison /a /b
Now if you look at the contents of both directories they we be exact copies. You can set a file watcher to monitor the directories and run that command or set a cron job to run the command on a schedule. I chose to use a cron job.
To get more complex, you can set many different options from the command line or set everything in a profile file located in the .unison
directory in the user's home directory. In this file you can set the roots to sync and set other options such as creating backups of files that change. Here is a sample file:#Set_
the roots or folders to sync_root=/aroot=ssh://user@hostname//path/to/folder#Notice_
the "//" after the hostname. This is need to specify an_ absolute path or else the path would be relative to the user's home directory.#Set_
other options._owner=true _#copies__
the command every 60 secs_
You can call the profile by the following:unison profilename
A note to keep in mind is that you will need to setup key logins to uses the ssh sync unattended. A guide for setting this up is here:https://help.ubuntu.com/community/SSH/OpenSSH/Keys