Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 10355  / 2 Years ago, thu, september 8, 2022, 5:01:54

Is there a way two sync multiple computers (i.e. particular directories in the home folder) automatically using Unison? If not, is there an alternative that can do this? I'm not completely against opening Unison all the time and doing the sync manually, but when it opens you must select a profile, which corresponds to just one directory, so you have to sync each individually. Add to that, the IP address is dynamic, and therefore has to be edited. This is quite tedious, and it seems there should be a simpler way. Am I missing something? Is there a way to simplify this process (possibly a bash script)?


More From » sync

 Answers
3

My suggestion would be to solve the problem of the dynamic IP (most routers have the concept of address reservation, that you can use to "fix" the IP of your computer). After that, you can use the command line version of unison:



unison -auto -batch profilename 


and you can add it to your login/logout scripts or as a cron job.



If you still need to change the ip, you can use sed in a script:




  1. create a template file in ~/.unison, newprof.tmpl, like this:



    root = /home/romano/
    root = ssh://romano@MYIPHERE//home/romano/

    path = education
    path = research

  2. create the following script, call it sync_newprof:



    #!/bin/bash
    #
    cd $HOME/.unison
    cat newprof.tmpl | sed s/MYIPHERE/$1 >! newprof.prf
    unison -auto -batch profilename


    basically, we create a profile file changing the MYIPHERE word with the script first argument


  3. now you can call it as



    sync_newprof 1.1.1.1 


    and it will create the profile with the given IP and sync.



[#24227] Friday, September 9, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ipentainer

Total Points: 112
Total Questions: 113
Total Answers: 113

Location: Guernsey
Member since Tue, Jul 6, 2021
3 Years ago
;