bi-directional sync with rsync











up vote
6
down vote

favorite
2












I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :



rsync -rtuv ./A/ ./B/
rsync -rtuv --delete ./B/ ./A/


This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.



Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.



Updated:



I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.










share|improve this question




























    up vote
    6
    down vote

    favorite
    2












    I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :



    rsync -rtuv ./A/ ./B/
    rsync -rtuv --delete ./B/ ./A/


    This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.



    Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.



    Updated:



    I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.










    share|improve this question


























      up vote
      6
      down vote

      favorite
      2









      up vote
      6
      down vote

      favorite
      2






      2





      I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :



      rsync -rtuv ./A/ ./B/
      rsync -rtuv --delete ./B/ ./A/


      This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.



      Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.



      Updated:



      I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.










      share|improve this question















      I am trying to setup bi-direction or two way sync with rsync. In my case I only need to delete the files when syncing from B to A. So, I was thinking of running rsync twice as follow :



      rsync -rtuv ./A/ ./B/
      rsync -rtuv --delete ./B/ ./A/


      This problem with this solution is that when I run rsync (B->A) which would be right after running the rsync (A-B), Any new file that get created in between the sync will also get removed.



      Is there a way I can specify a time stamp as condition that it only delete the file if it created before this date/time.



      Updated:



      I understand there is a unison solution but the problem with unison is required to install on both ends. I am syncing with a remote server and I can not install unison on the remote end.







      rsync synchronization






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 19 '16 at 16:34

























      asked Jan 18 '16 at 17:16









      Raza

      2,58241923




      2,58241923






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.



          https://github.com/deajan/osync



          It uses rsync internally, so it should be suitable for any situation where you could use rsync.






          share|improve this answer

















          • 1




            Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
            – Raza
            Jan 19 '16 at 17:25




















          up vote
          4
          down vote













          rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:



          unison A/ B/


          The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.



          The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.



          mkdir A B
          date > A/date
          who > B/who
          unison A/ B/
          # Lots of output from unison, showing synchronisation

          ls A
          date who
          ls B
          date who

          date > A/date
          unison A/ B/
          # Lots of output from unison, showing synchronisation


          There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.






          share|improve this answer



















          • 2




            I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
            – Raza
            Jan 19 '16 at 16:14






          • 1




            It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
            – Ted
            Jan 2 '17 at 18:22











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f256128%2fbi-directional-sync-with-rsync%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.



          https://github.com/deajan/osync



          It uses rsync internally, so it should be suitable for any situation where you could use rsync.






          share|improve this answer

















          • 1




            Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
            – Raza
            Jan 19 '16 at 17:25

















          up vote
          3
          down vote



          accepted










          You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.



          https://github.com/deajan/osync



          It uses rsync internally, so it should be suitable for any situation where you could use rsync.






          share|improve this answer

















          • 1




            Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
            – Raza
            Jan 19 '16 at 17:25















          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.



          https://github.com/deajan/osync



          It uses rsync internally, so it should be suitable for any situation where you could use rsync.






          share|improve this answer












          You could try osync which is designed for exactly this task. I once set up a complex sequence of rsync commands to do the job, but I now use osync.



          https://github.com/deajan/osync



          It uses rsync internally, so it should be suitable for any situation where you could use rsync.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 19 '16 at 16:53









          Mark Perryman

          513310




          513310








          • 1




            Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
            – Raza
            Jan 19 '16 at 17:25
















          • 1




            Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
            – Raza
            Jan 19 '16 at 17:25










          1




          1




          Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
          – Raza
          Jan 19 '16 at 17:25






          Thanks, Mark. I was just about to answer my own question. I found very similar script called bsync (github.com/dooblem/bsync) basically it uses diff to figure out whats need to be sync. Since I am not expecting any conflicts in sync, I also modify this script a little so it run silently when runs with a cron job.
          – Raza
          Jan 19 '16 at 17:25














          up vote
          4
          down vote













          rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:



          unison A/ B/


          The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.



          The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.



          mkdir A B
          date > A/date
          who > B/who
          unison A/ B/
          # Lots of output from unison, showing synchronisation

          ls A
          date who
          ls B
          date who

          date > A/date
          unison A/ B/
          # Lots of output from unison, showing synchronisation


          There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.






          share|improve this answer



















          • 2




            I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
            – Raza
            Jan 19 '16 at 16:14






          • 1




            It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
            – Ted
            Jan 2 '17 at 18:22















          up vote
          4
          down vote













          rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:



          unison A/ B/


          The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.



          The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.



          mkdir A B
          date > A/date
          who > B/who
          unison A/ B/
          # Lots of output from unison, showing synchronisation

          ls A
          date who
          ls B
          date who

          date > A/date
          unison A/ B/
          # Lots of output from unison, showing synchronisation


          There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.






          share|improve this answer



















          • 2




            I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
            – Raza
            Jan 19 '16 at 16:14






          • 1




            It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
            – Ted
            Jan 2 '17 at 18:22













          up vote
          4
          down vote










          up vote
          4
          down vote









          rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:



          unison A/ B/


          The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.



          The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.



          mkdir A B
          date > A/date
          who > B/who
          unison A/ B/
          # Lots of output from unison, showing synchronisation

          ls A
          date who
          ls B
          date who

          date > A/date
          unison A/ B/
          # Lots of output from unison, showing synchronisation


          There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.






          share|improve this answer














          rsync is the wrong tool for this task, for exactly the reasons that you have encountered. Instead, consider using unison:



          unison A/ B/


          The first time you run this it will identify files that are uniquely in A, and those that are uniquely in B. It will also flag those that are in both places and ask you to identify which is to be overwritten.



          The next time you run this it will copy changes from A to B and also B to A, flagging any files that have been changed in both places for manual resolution.



          mkdir A B
          date > A/date
          who > B/who
          unison A/ B/
          # Lots of output from unison, showing synchronisation

          ls A
          date who
          ls B
          date who

          date > A/date
          unison A/ B/
          # Lots of output from unison, showing synchronisation


          There are a number of useful flags available for unison which help automate the process by defining assumptions and thereby reducing the number of questions you're asked during the synchronisation.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 5 at 23:34









          Sparhawk

          9,09063889




          9,09063889










          answered Jan 18 '16 at 22:56









          roaima

          42.3k551116




          42.3k551116








          • 2




            I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
            – Raza
            Jan 19 '16 at 16:14






          • 1




            It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
            – Ted
            Jan 2 '17 at 18:22














          • 2




            I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
            – Raza
            Jan 19 '16 at 16:14






          • 1




            It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
            – Ted
            Jan 2 '17 at 18:22








          2




          2




          I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
          – Raza
          Jan 19 '16 at 16:14




          I saw unison solution but the problem with that is I am required to install on both end. I am syncing with a remote and I can not install unison on the remote end.
          – Raza
          Jan 19 '16 at 16:14




          1




          1




          It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
          – Ted
          Jan 2 '17 at 18:22




          It doesn't help the OP, but I was looking for unison. I see there are Debian packages and it supports ssh transport.
          – Ted
          Jan 2 '17 at 18:22


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f256128%2fbi-directional-sync-with-rsync%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt