none
File Sync One Way RRS feed

  • Question

  • guys,

     

    i have created a one way sync service that runs every 10 minutes and check the source directory for any new changes and apply the new changes to the remote directory. both directories are local and updates are happening just fine, also any changes in the remote directory should not be passed to the source directory and for that reason it's one way.

    i have also made sure for any conflict that may happen, source directory wins. I also call detect changes on both source and destination prior to start the sync session. my question is when i delete a file from a folder which was already created by the previous sync session, next call to sync would not re-copy over the deleted file from the source directory to destination.

     

    my understanding was, when you call detectChanges on provider, it should know the file was deleted from the destination and that has to be copied over from the source directory. i also tested this with syncToy and again nothing happened there as well.

    if i change the direction from upload to uploadandDownload, any files deleted from destination will be deleted from source directory as well and i don't want this. i need a way to make sure any previously deleted files from destination which was synced before, will be replaced back through calling agent.Synchronize() again.

     MY QUESTIONS:

    1- How do i achieve this?

    2- when the content of a file changes on destination folder, Sync doesn't fix it by bringing in the original file. does anyone know why this is happening?

    3- there is a weird case happening as i describe below:

               on source directory  i have a file say MyTest.txt with 4 bytes

             on destination i have a file called test.txt with 0 bytes

    when i rename Mytest.text to test.txt and run sync, following file is generated on destination : test.1.txt

    i have made sure for any conflicts and constraints, source wins however this is not the case. Does anyone know how to get around this issue? Desire output should be removing the old test.txt from destination and creating a new  4 byte test.txt

    SP

    here is the code snippet for this part:

    ////////////////////////

                FileSyncProvider sourceProvider = null;
                FileSyncProvider destinationProvider = null;

                    sourceProvider = new FileSyncProvider(sourceReplicaRootPath, filter, options);
                    destinationProvider = new FileSyncProvider(destinationReplicaRootPath, filter, options);

                    sourceProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins;
                    destinationProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins;

                    sourceProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.SourceWins;
                    destinationProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.SourceWins;

                    destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);
                    destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange);


                    SyncOrchestrator agent = new SyncOrchestrator();

                    agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination

                    agent.LocalProvider = sourceProvider;
                    agent.RemoteProvider = destinationProvider;

                     agent.Synchronize();

    ///////////////////

    • Edited by SP_TIO Thursday, March 25, 2010 8:07 AM
    Thursday, March 25, 2010 1:23 AM

Answers

  • Hi SP -

    Yours is the correct behavior that we would expect on a one-way sync. In a one-way sync deleting a file on the destination would not cause the source to resend the file. We will only send changes that are made on the source - not send changes in reaction to changes made on the destination. The only way to try to do this would be to do a PreviewSync in the opposite direction ( destination to source) - look at the events and then make dummy updates on the source side to flow the change once again from the source to the destination.

    To answer the questions from your original post:

    1. The way to do this is explained above.
    2. Same reasoning - changes have to be explicitly made to the source for it to be sent to the destination.
    3. It is not exactly wierd :) The two files started out as being different on both sides. So we give it different unique ids. Now when you rename the file on the source side and we send the change to the destination - we realize that there is a file with the same name on the destination. Since they started out as different files, we have no intelligent way to figure out exactly which file the user meant to keep so we just rename the file ( to avoid data loss).

    Thanks
    Deepa


    Deepa ( Microsoft Sync Framework)
    • Marked as answer by SP_TIO Friday, March 26, 2010 2:55 AM
    • Unmarked as answer by SP_TIO Friday, March 26, 2010 2:55 AM
    • Marked as answer by SP_TIO Friday, March 26, 2010 3:01 AM
    Friday, March 26, 2010 12:51 AM
    Answerer

All replies

  • afaik, for one-way syncs, SyncFx doesnt care about the changes in the destination. The DetectChanges on the source provider, detects changes on the source to be sent to the destination. The DetectChanges call on the destination provider is used for determining changes to be sent to the source, but since you;re in a one-way, upload sync, that changes is never considered for application in the source folder. Also, the change detection in one-way will not detect that a file has been deleted and needs to be restored. All it knows is that the file is not there, so it tries to copy it again. If a file is deleted from one of replica and you have two-way sync, the delete operation is applied on the other replica.
    Thursday, March 25, 2010 3:45 AM
    Moderator
  • hi June,

    i dont think this is the case,  i have seen with windows live mesh ,you can achieve all above features, although mesh is not based on sync framework, i think with Microsoft sync framework you can achieve one way sync  with support of deletion, rename, or content change.  i can achieve part of it by deleting the meta data from the destination folder after each call to sync. this way it re-genrate the files where deleted before.

     

    i think there is a better way of handling the scenario i described before. Anyone else wants to take a shot at solving my sync issues?

    thanks

    SP

    Thursday, March 25, 2010 7:59 AM
  • i edited my post to be clearer.

    How are you detecting the changes?

    i have simulated your scenario, sync one file, one way to destination, renamed or delete the file on the destination, sync again, and the file is always recreated. The other issue though is a rename on the source does  not do a rename on the destination, it results to a new copy of the file from the source to the destination instead of renaming the copy on the destination.

    Thursday, March 25, 2010 10:01 AM
    Moderator
  • Hi ,

    here is what i set for File sync Options

     

    // Set options for the sync operation

    Options = FileSyncOptions.ExplicitDetectChanges | FileSyncOptions.CompareFileStreams |
              FileSyncOptions.RecycleDeletedFiles |
       FileSyncOptions.RecyclePreviousFileOnUpdates |
              FileSyncOptions.RecycleConflictLoserFiles;


    and here is what i set for filter

    filter.FileNameExcludes.Add("*.exe"); // Exclude all *.exe files
    filter.FileNameExcludes.Add("*.metadata"); // Exclude all *.metadata files

    and here is how i detect changes:


    provider =new FileSyncProvider(replicaRootPath, filter, options);
    provider.DetectChanges();


    and here is how i apply changes:

    ////////////////////////

                FileSyncProvider sourceProvider = null;
                FileSyncProvider destinationProvider = null;

                    sourceProvider = new FileSyncProvider(sourceReplicaRootPath, filter, options);
                    destinationProvider = new FileSyncProvider(destinationReplicaRootPath, filter, options);

                    sourceProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins;
                    destinationProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins;

                    sourceProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.SourceWins;
                    destinationProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.SourceWins;

                    destinationProvider.AppliedChange += new EventHandler<AppliedChangeEventArgs>(OnAppliedChange);
                    destinationProvider.SkippedChange += new EventHandler<SkippedChangeEventArgs>(OnSkippedChange);


                    SyncOrchestrator agent = new SyncOrchestrator();

                    agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination

                    agent.LocalProvider = sourceProvider;
                    agent.RemoteProvider = destinationProvider;

                     agent.Synchronize();

    ///////////////////

    at this point, on a clean start, metadata files are being created and sync happens successfully. after i deleted a file from destination and run Syn nothing happens. in general these are the scenarios that i ran into:

    1- deletion - deleting a file from destination doesn't restore the file back from source dirstory after running the sync session again

    2- renaming - renaming a file on destination doesn't restore the renamed file back from source directory after running the sync session again

    3- content modification - changing the content of a file on destination, doesnt restore the original file back from source directory after running the sync session again

    i think this is a bit clear now where i am struggling at with MSF. any help is appreciated.

    thanks

    SP

    Thursday, March 25, 2010 5:43 PM
  • If you dummily update the file on the source folder which was deleted on the destination folder, doing sync from source to destination replica, you should see this file re-created if you make source provider win.

    Thanks.


    Leo Zhou ------ This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, March 25, 2010 8:44 PM
    Answerer
  • hi,

    i tested your solution and it works, however it would be hard to create a solution around this issue given the fact that i don't know what file(s) were deleted, modified or renamed on destination folder. i still think there should be a way in MFS to get around this issue

    thanks

    SP

    Thursday, March 25, 2010 9:02 PM
  • Since you only update/delete on the destination, and not on the source, this is not really a conflicting change.

    If your only requirement is to mirror everything from the source to the destination each time, why not use xcopy or robocopy?

    Thursday, March 25, 2010 9:42 PM
    Moderator
  • looks like the code's from the FileSyncProvider sample. If it is, i think the only difference between our codes is that i don't make a call to DetectChangesOnFileSystemReplica to detect the changes.

    instead, i call the DetectChanges before the call to Synchronize:

    sourceProvider.DetectChanges();
    destinationProvider.DetectChanges();
    
    SyncOrchestrator agent = new SyncOrchestrator();
    agent.LocalProvider = sourceProvider;
    agent.RemoteProvider = destinationProvider;
    agent.Direction = SyncDirectionOrder.Upload; // Sync source to destination
    
    agent.Synchronize();

     

    The behaviour am getting is:

    delete file from destination = sync restores the file on next sync

    rename the file from source = new copy of renamed file on destination instead of renaming the previously sync file in the destination

    update the file on source = overwrite file on destination

    Thursday, March 25, 2010 10:38 PM
    Moderator
  • hi June,

    well ,

    the following is not happening for me:

    1- Delete file from destination = next sync cycle doesn't replace/restore the file

    2- rename file from destination = next sync cycle doesn't restore it to original name

    3- modify content of a file on destination = next sync cycle doesn't update it to original content

    4- rename the file from source = new copy of renamed file on destination is created and previously sync file in the destination is deleted

    5- update the file on source = overwrite file on destination

    thanks

    SP

     

    Thursday, March 25, 2010 11:17 PM
  • Hi SP -

    Yours is the correct behavior that we would expect on a one-way sync. In a one-way sync deleting a file on the destination would not cause the source to resend the file. We will only send changes that are made on the source - not send changes in reaction to changes made on the destination. The only way to try to do this would be to do a PreviewSync in the opposite direction ( destination to source) - look at the events and then make dummy updates on the source side to flow the change once again from the source to the destination.

    To answer the questions from your original post:

    1. The way to do this is explained above.
    2. Same reasoning - changes have to be explicitly made to the source for it to be sent to the destination.
    3. It is not exactly wierd :) The two files started out as being different on both sides. So we give it different unique ids. Now when you rename the file on the source side and we send the change to the destination - we realize that there is a file with the same name on the destination. Since they started out as different files, we have no intelligent way to figure out exactly which file the user meant to keep so we just rename the file ( to avoid data loss).

    Thanks
    Deepa


    Deepa ( Microsoft Sync Framework)
    • Marked as answer by SP_TIO Friday, March 26, 2010 2:55 AM
    • Unmarked as answer by SP_TIO Friday, March 26, 2010 2:55 AM
    • Marked as answer by SP_TIO Friday, March 26, 2010 3:01 AM
    Friday, March 26, 2010 12:51 AM
    Answerer
  • thanks so much Deepa. now i know how to create a work around .

    since we ar eon this topic, i ran into an issue with sync when source direcotry is set to a network path and destination is a local directory.

    we i run sync, everything works and metadata is created on both directories however no file is generated on destination folder. i realized all the files creations are being skipped with following error:

    A first chance exception of type 'System.NotImplementedException' occurred in SyncService.exe

    -- Skipped applying CREATE for Learning\Arrays Tutorial (C#).url due to error: [The method or operation is not implemented.]

    when i switch both source and destination path to be local, all works just fine and no skipping happens. any help is appreciated.

    here is my settings for local and destination

    <configuration>
      <appSettings>
        <add key="SourcePath" value="\\server\\engineering\\SP\\Test />
        <add key="DestPath" value="C:\\TempSync\\" />
      </appSettings>
    </configuration>

     

     

    thanks

    SP

     

    Friday, March 26, 2010 3:08 AM
  • Hi,

    Could  you please provide an example of such "dummy" update?

    How to make dummy update for example for dll?

    Thanks.

    Ivan

    Thursday, January 20, 2011 7:05 PM