This HOWTO shows you how to setup the Unison file synchronizer to backup files from one server to another.
Topics include:
Get unison from here.
For more info on unison go to : http://www.cis.upenn.edu/~bcpierce/unison/
Here's HOWTO of how to setup UNISON on a Windows box: \\http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/unison-manual.html#ssh-win
Create a Unison profile
####################
# Now create a Unison profile
cd /home/unison/.unison edt sync_server.prf
# Here's my profile. Read comments and change to suit your needs
#---- Start of File ----# ########################################### # # # /home/unison/.unison/sync_server.prf # # unison configuration file # # Author: Brynn Neilson # # Email: admin@spinning-planet.com # # Date: 12 September 2004 # # # ########################################### # Roots of the synchronization root = / root = socket://[ip of your master server]:PORT # Where PORT is the port on which the server is listening on. # Don't ask questions. Just do the sync batch = true # Automatically choose default solution auto = true # syncronize owner info owner = true # syncronize super duper deluxo hybird nano technology group maximus highness deluxe edition group = true # syncronize modification times # times = true # force to write over old files # force = ssh://[ip of your master server]// # force = newer # suppress status messages # terse = true ## Paths to synchronize # path = current path = etc/passwd path = etc/group path = etc/exim.conf path = etc/aliases path = home path = pkg path = usr # Some regexps specifying names and paths to ignore ignore = Name temp.* ignore = Name *~ ignore = Name .*~ ignore = Name *.o ignore = Name *.tmp ignore = Name server.crt ignore = Name server.key ignore = Name pass.key ignore = Name local-host-names # ignore = Name e107_stat* # ignore = Name e107_online* # ignore = Path home/sites/spinningplanet # ignore = Path = var/lib/mysql/spinningplanet # following pattern will make Unison ignore any path containing the name # ignore = Name {statistics,spamassassin,stats,cache,.razor,.imap.index,razor-agent.log,dovecot-uidlist,access_log,e rror_log} ignore = Name {imdb} # Window height # height = 37 ## Keep a backup copy of the entire replica # backup = Name * # Use this command for displaying diffs # diff = diff -y -W 79 --suppress-common-lines # Log actions to the terminal log = true #---- End of File ----#
Create a shell script to run unison. You can actually test Unison first by typing:
unison sync_servers.prf
# add something like this:
#---- Start of File ----# ################################# # Author: Brynn Neilson # Date: Sunday, October 3rd. 2004 # # This is the Syncronization script to sync ns2.spinning-planet.com and # # ns3.spinniing-planet.com # ################################# # Stop Apache, cop etc files, and restart pointing at an offline html # page to allow MySQL to be stopped so it can be copied # Copyimg etc to backup folder /etc_backup so I have a local backup unison /etc /etc_backup -force /etc -batch -group -owner # I need to stop apache and restart with a temprary page httpd -k stop httpd -f /etc/httpd/conf/offline-httpd.conf # Need to stop mysql because it will corrupt if it is running when copied service mysqld stop # make local backup of mysql DBs unison /var/lib/mysql /var/lib/mysql_backup -force /var/lib/mysql -batch -group -owner # Do the same on master server ssh [ip of master server] unison /etc /etc_backup -force /etc -batch -group -owner ssh ns3.spinning-planet.com service mysqld stop ssh ns3.spinning-planet.com httpd -k stop ssh ns3.spinning-planet.com httpd -f /etc/httpd/conf/offline-httpd.conf ssh ns3.spinning-planet.com unison /var/lib/mysql /var/lib/mysql_backup -force /var/lib/mysql -batch -group -owner # now sync both servers unison sync_all.prf # restart everything back to normal on both servers ssh ns3.spinning-planet.com service named restart ssh ns3.spinning-planet.com service mysqld start ssh ns3.spinning-planet.com httpd -k stop ssh ns3.spinning-planet.com httpd -f /etc/httpd/conf/httpd.conf service named restart service mysqld start httpd -k stop httpd -f /etc/httpd/conf/httpd.conf #-- End of file --#
Of course your script doesn't have to have as much stuff in it but you will need to stop any databases that are running or they will get corrupt
# Make script executable
chmod 755 sync_servers.sh
# test it
./sync_servers.sh
If it all works all you need to do is create a cron job to run it. You can create different unison profiles to backup daily, weekly, or just specific user data if you want. There is also a binary for windows. Don't use the windows gui though. Create a unison profile instead. When you install it on windows just look for a file called default.prf. Also note that the windows user can only backup data for the same name user on the linux box.
If you have any questions feel free to contact me
brynn
See also for win config http://www.minezone.org/wiki/MVance/FileSyncingHowTo